Add PubMessge

This commit is contained in:
Nicolas Duhamel 2022-12-28 09:29:58 +01:00
parent f135802a46
commit 0c64ac1523

38
mqtt.go
View File

@ -19,22 +19,22 @@ type Message interface {
Ack()
}
type message struct {
duplicate bool
qos byte
retained bool
topic string
messageID uint16
payload []byte
ack func()
type PubMessage interface {
Topic() string
Payload() []byte
Qos() byte
Retained() bool
}
func (m *message) Duplicate() bool {
return m.duplicate
type message struct {
qos int
retained bool
topic string
payload []byte
}
func (m *message) Qos() byte {
return m.qos
return byte(m.qos)
}
func (m *message) Retained() bool {
@ -45,19 +45,17 @@ func (m *message) Topic() string {
return m.topic
}
func (m *message) MessageID() uint16 {
return m.messageID
}
func (m *message) Payload() []byte {
return m.payload
}
func (m *message) Ack() {
}
func NewSimpleMessage(topic string, payload []byte, retained bool) *message {
return &message{topic: topic, payload: payload, retained: retained}
func NewPubMessage(topic string, payload []byte, qos int, retained bool) *message {
return &message{
topic: topic,
payload: payload,
qos: qos,
retained: retained,
}
}
type Config struct {