tagClientInfo.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package public
  2. import (
  3. "math/rand"
  4. )
  5. type ClientInfo struct {
  6. ComputerID [3]uint32
  7. SystemVer [2]uint32
  8. ComputerName string //12
  9. }
  10. func NewClientInfo(ba *ByteArray) *ClientInfo {
  11. var this *ClientInfo = new(ClientInfo)
  12. for i := 0; i < 3; i++ {
  13. if ba != nil {
  14. this.ComputerID[i], _ = ba.ReadUInt32()
  15. } else {
  16. this.ComputerID[i] = uint32(rand.Intn(65535))
  17. }
  18. }
  19. for i := 0; i < 2; i++ {
  20. if ba != nil {
  21. this.SystemVer[i], _ = ba.ReadUInt32()
  22. } else {
  23. this.SystemVer[i] = 2018
  24. }
  25. }
  26. if ba != nil {
  27. this.ComputerName, _ = ba.ReadString(12)
  28. } else {
  29. this.ComputerName = "golang test"
  30. }
  31. return this
  32. }
  33. func (this *ClientInfo) Serialize(ba *ByteArray) {
  34. for i := 0; i < 3; i++ {
  35. ba.WriteUInt32(this.ComputerID[i])
  36. }
  37. for i := 0; i < 2; i++ {
  38. ba.WriteUInt32(this.SystemVer[i])
  39. }
  40. ba.WriteStringWithLen(this.ComputerName, 12)
  41. }
  42. func (this *ClientInfo) GetMachineNum() []byte {
  43. var tmpBuf []byte
  44. ba := CreateByteArray(tmpBuf)
  45. for i := 0; i < 3; i++ {
  46. ba.WriteUInt32(this.ComputerID[i])
  47. }
  48. return ba.Bytes()
  49. }