/
message.go
102 lines (83 loc) · 1.77 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package mqtt
////////////////////Interface//////////////////////////////
type QOS byte
const (
QOS_ZERO QOS = iota
QOS_ONE
QOS_TWO
QOS_RESERVED
QOS_FAILURE QOS = 0x80
)
type Message interface {
GetDup() bool
SetDup(dup bool)
GetQos() QOS
SetQos(qos QOS)
GetRetain() bool
SetRetain(retain bool)
GetTopic() string
SetTopic(topic string)
GetContent() string
SetContent(content string)
//GetClientId() string
//SetClientId(clientId string)
Packetize(packetId uint16) PacketPublish
}
////////////////////Implementation////////////////////////
type message struct {
dup bool
qos QOS
retain bool
topic string
content string
clientId string
}
func NewMessage(dup bool, qos QOS, retain bool, topic string, content string) Message {
return &message{dup: dup,
qos: qos,
retain: retain,
topic: topic,
content: content}
}
func (this *message) GetDup() bool {
return this.dup
}
func (this *message) SetDup(dup bool) {
this.dup = dup
}
func (this *message) GetQos() QOS {
return this.qos
}
func (this *message) SetQos(qos QOS) {
this.qos = qos
}
func (this *message) GetRetain() bool {
return this.retain
}
func (this *message) SetRetain(retain bool) {
this.retain = retain
}
func (this *message) GetTopic() string {
return this.topic
}
func (this *message) SetTopic(topic string) {
this.topic = topic
}
func (this *message) GetContent() string {
return this.content
}
func (this *message) SetContent(content string) {
this.content = content
}
func (this *message) GetClientId() string {
return this.clientId
}
func (this *message) SetClientId(clientId string) {
this.clientId = clientId
}
func (this *message) Packetize(packetId uint16) PacketPublish {
pkt := NewPacketPublish()
pkt.SetPacketId(packetId)
pkt.SetMessage(this)
return pkt
}