46 lines
801 B
Go
46 lines
801 B
Go
package znet
|
|
|
|
type Message struct {
|
|
// 消息 ID
|
|
id uint32
|
|
// 消息长度
|
|
dataLen uint32
|
|
// 消息内容
|
|
data []byte
|
|
}
|
|
|
|
// NewMsgPackage 创建一个 Message 消息包
|
|
func NewMsgPackage(id uint32, data []byte) *Message {
|
|
return &Message{
|
|
id: id,
|
|
dataLen: uint32(len(data)),
|
|
data: data,
|
|
}
|
|
}
|
|
|
|
// GetMsgID 获取消息 ID
|
|
func (m *Message) GetMsgID() uint32 {
|
|
return m.id
|
|
}
|
|
|
|
// GetDataLen 获取消息长度
|
|
func (m *Message) GetDataLen() uint32 {
|
|
return m.dataLen
|
|
}
|
|
|
|
// GetData 获取消息内容
|
|
func (m *Message) GetData() []byte {
|
|
return m.data
|
|
}
|
|
|
|
// SetMsgID 设置消息 ID
|
|
func (m *Message) SetMsgID(id uint32) {
|
|
m.id = id
|
|
}
|
|
|
|
// SetData 设置消息内容(自动同步长度)
|
|
func (m *Message) SetData(data []byte) {
|
|
m.data = data
|
|
m.dataLen = uint32(len(data))
|
|
}
|