-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.go
43 lines (37 loc) · 838 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tcpack
// Imessage is an interface that definds a message,
// which carries DataLen, MsgId and MsgData.
type Imessage interface {
GetDataLen() uint32
GetMsgId() uint32
GetMsgData() []byte
}
// Message implements Imessage.
type Message struct {
Id uint32
DataLen uint32
Data []byte
}
// NewMessage returns a message typed *Message.
func NewMessage(id, datalen uint32, data []byte) *Message {
if data == nil {
data = []uint8{}
}
return &Message{
Id: id,
DataLen: datalen,
Data: data,
}
}
// GetDataLen returns DataLen typed uint32.
func (msg *Message) GetDataLen() uint32 {
return msg.DataLen
}
// GetMsgId returns Id typed uint32.
func (msg *Message) GetMsgId() uint32 {
return msg.Id
}
// GetMsgData returns Data typed []byte.
func (msg *Message) GetMsgData() []byte {
return msg.Data
}