You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
817 B

  1. package znet
  2. type Message struct {
  3. DataLen uint32 //消息的长度
  4. Id uint32 //消息的ID
  5. Data []byte //消息的内容
  6. }
  7. //创建一个Message消息包
  8. func NewMsgPackage(id uint32, data []byte) *Message {
  9. return &Message{
  10. DataLen: uint32(len(data)),
  11. Id: id,
  12. Data: data,
  13. }
  14. }
  15. //获取消息数据段长度
  16. func (msg *Message) GetDataLen() uint32 {
  17. return msg.DataLen
  18. }
  19. //获取消息ID
  20. func (msg *Message) GetMsgId() uint32 {
  21. return msg.Id
  22. }
  23. //获取消息内容
  24. func (msg *Message) GetData() []byte {
  25. return msg.Data
  26. }
  27. //设置消息数据段长度
  28. func (msg *Message) SetDataLen(len uint32) {
  29. msg.DataLen = len
  30. }
  31. //设计消息ID
  32. func (msg *Message) SetMsgId(msgId uint32) {
  33. msg.Id = msgId
  34. }
  35. //设计消息内容
  36. func (msg *Message) SetData(data []byte) {
  37. msg.Data = data
  38. }