-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
50 lines (39 loc) · 892 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
44
45
46
47
48
49
50
package mqtt
import (
`github.com/eclipse/paho.mqtt.golang`
`github.com/goexl/gox`
)
// Message 消息封装
type Message struct {
original mqtt.Message
options *messageOptions
_ gox.CannotCopy
}
func newMessage(original mqtt.Message, options *messageOptions) *Message {
return &Message{
original: original,
options: options,
}
}
func (m *Message) Fill(value interface{}, opts ...messageOption) (err error) {
for _, opt := range opts {
opt.applyMessage(m.options)
}
err = m.options.unmarshal(m.original.Payload(), value)
return
}
func (m *Message) Duplicate() bool {
return m.original.Duplicate()
}
func (m *Message) Qos() byte {
return m.original.Qos()
}
func (m *Message) Retained() bool {
return m.original.Retained()
}
func (m *Message) Topic() string {
return m.original.Topic()
}
func (m *Message) MessageId() uint16 {
return m.original.MessageID()
}