Documentation
¶
Overview ¶
Package packets1 implements MQTT-SN version 1.2 packets structs.
Index ¶
- Constants
- func NewPacketWithHeader(h pkts.Header) (pkt pkts.Packet, err error)
- func ReadPacket(r io.Reader) (pkt pkts.Packet, err error)
- type Advertise
- type Auth
- type Connack
- type Connect
- type Disconnect
- type GwInfo
- type MessageIDProperty
- type PacketWithID
- type Pingreq
- type Pingresp
- type Puback
- type Pubcomp
- type Publish
- type Pubrec
- type Pubrel
- type Regack
- type Register
- type ReturnCode
- type SearchGw
- type Suback
- type Subscribe
- type Unsuback
- type Unsubscribe
- type WillMsg
- type WillMsgReq
- type WillMsgResp
- type WillMsgUpd
- type WillTopic
- type WillTopicReq
- type WillTopicResp
- type WillTopicUpd
Constants ¶
const ( AUTH_SUCCESS uint8 = 0 AUTH_CONTINUE uint8 = 0x18 AUTH_REAUTHENTICATE uint8 = 0x19 )
Authentication reason constants.
const ( TIT_REGISTERED uint8 = iota TIT_PREDEFINED TIT_SHORT )
TopicID type constants.
const (
AUTH_PLAIN = "PLAIN"
)
Auth method constants.
const MaxPacketLen = 8192
MQTT-SN specification version 1.2, section 5.2.1 defines maximal packet size to be 65535B but pion/udp and pion/dtls use maximal packet size of 8192B. See e.g.: - https://github.com/pion/udp/blob/b66c29020370bbb21647c27cf0b5ac50a18677f7/conn.go#L17 - https://github.com/pion/dtls/blob/3dc563b9aede91561ece5ae14b6ec6edf6fc5eb9/conn.go#L30 An effective MQTT-SN maximal packet size is even a few bytes smaller: for UDP transport: PUBLISH with 8183B-long payload = 8192B total packet length for DTLS transport: PUBLISH with 8146B-long payload = 8155B total packet length (I'm not sure if the DTLS maximal length is affected by the cipher used or not)
The MQTT-SN specification presuppose such packet length limit imposed by the network layer:
Note that because MQTT-SN does not support message fragmentation and reassembly, the maximum message length that could be used in a network is governed by the maximum packet size that is supported by that network, and not by the maximum length that could be encoded by MQTT-SN. [MQTT-SN specification v. 1.2, chapter 5.2.1 Length]
const MaxPayloadLength = 7168
Because I'm not sure about maximal DTLS header length, we have decided to use this arbitrary "small enough to be safe" maximal payload length.
const TIT_STRING = uint8(0)
Whole topic string included in the packet (SUBSCRIBE packet only).
Variables ¶
This section is empty.
Functions ¶
func NewPacketWithHeader ¶
NewPacketWithHeader returns a particular packet struct with a given header. The struct type is determined by h.msgType.
Types ¶
type Advertise ¶
func NewAdvertise ¶
type Auth ¶
Non-standard extension to allow user/password authentication in MQTT-SN.
Implemented according to the OASIS Open MQTT-SN v. 2.0 draft https://www.oasis-open.org/committees/download.php/68568/mqtt-sn-v2.0-wd09.docx
SASL PLAIN method specification: https://datatracker.ietf.org/doc/html/rfc4616
func NewAuthPlain ¶
NewAuthPlain creates a new Auth with "PLAIN" method encoded authentication data.
func (*Auth) DecodePlain ¶
DecodePlain decodes username and password from AUTH package data encoded using "PLAIN" method.
type Connack ¶
type Connack struct { pkts.Header // Fields ReturnCode ReturnCode }
func NewConnack ¶
func NewConnack(returnCode ReturnCode) *Connack
type Connect ¶
type Connect struct { pkts.Header // Flags Will bool CleanSession bool // Fields ProtocolID uint8 Duration uint16 ClientID []byte }
func NewConnect ¶
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
type Disconnect ¶
func NewDisconnect ¶
func NewDisconnect(duration uint16) *Disconnect
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
func (*Disconnect) Pack ¶
func (p *Disconnect) Pack() ([]byte, error)
func (Disconnect) String ¶
func (p Disconnect) String() string
func (*Disconnect) Unpack ¶
func (p *Disconnect) Unpack(buf []byte) error
type GwInfo ¶
type MessageIDProperty ¶
type MessageIDProperty struct {
// contains filtered or unexported fields
}
func (*MessageIDProperty) CopyMessageID ¶
func (p *MessageIDProperty) CopyMessageID(m2 PacketWithID)
func (*MessageIDProperty) MessageID ¶
func (p *MessageIDProperty) MessageID() uint16
func (*MessageIDProperty) SetMessageID ¶
func (p *MessageIDProperty) SetMessageID(msgID uint16)
type PacketWithID ¶
PacketWithID is an interface for all packets which include MessageID property.
type Pingreq ¶
func NewPingreq ¶
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
type Pingresp ¶
func NewPingresp ¶
func NewPingresp() *Pingresp
type Puback ¶
type Puback struct { pkts.Header // Fields TopicID uint16 MessageIDProperty ReturnCode ReturnCode }
func NewPuback ¶
func NewPuback(topicID uint16, returnCode ReturnCode) *Puback
type Pubcomp ¶
type Pubcomp struct { pkts.Header // Fields MessageIDProperty }
func NewPubcomp ¶
func NewPubcomp() *Pubcomp
type Publish ¶
type Publish struct { pkts.Header // Flags pkts.DUPProperty QOS uint8 Retain bool TopicIDType uint8 // Fields TopicID uint16 MessageIDProperty Data []byte }
type Pubrec ¶
type Pubrec struct { pkts.Header // Fields MessageIDProperty }
type Pubrel ¶
type Pubrel struct { pkts.Header // Fields MessageIDProperty }
type Regack ¶
type Regack struct { pkts.Header // Fields TopicID uint16 MessageIDProperty ReturnCode ReturnCode }
func NewRegack ¶
func NewRegack(topicID uint16, returnCode ReturnCode) *Regack
type Register ¶
type Register struct { pkts.Header // Fields TopicID uint16 MessageIDProperty TopicName string }
func NewRegister ¶
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
type ReturnCode ¶
type ReturnCode uint8
Return code constants.
const ( RC_ACCEPTED ReturnCode = iota RC_CONGESTION RC_INVALID_TOPIC_ID RC_NOT_SUPPORTED )
func (ReturnCode) String ¶
func (c ReturnCode) String() string
type SearchGw ¶
func NewSearchGw ¶
type Suback ¶
type Suback struct { pkts.Header // Flags QOS uint8 // Fields TopicID uint16 MessageIDProperty ReturnCode ReturnCode }
type Subscribe ¶
type Subscribe struct { pkts.Header // Flags pkts.DUPProperty QOS uint8 TopicIDType uint8 // Fields MessageIDProperty TopicID uint16 TopicName string }
type Unsuback ¶
type Unsuback struct { pkts.Header // Fields MessageIDProperty }
func NewUnsuback ¶
func NewUnsuback() *Unsuback
type Unsubscribe ¶
type Unsubscribe struct { pkts.Header // Flags TopicIDType uint8 // Fields MessageIDProperty TopicID uint16 TopicName string }
func NewUnsubscribe ¶
func NewUnsubscribe(topicName string, topicID uint16, topicIDType uint8) *Unsubscribe
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
func (*Unsubscribe) Pack ¶
func (p *Unsubscribe) Pack() ([]byte, error)
func (Unsubscribe) String ¶
func (p Unsubscribe) String() string
func (*Unsubscribe) Unpack ¶
func (p *Unsubscribe) Unpack(buf []byte) error
type WillMsg ¶
func NewWillMsg ¶
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
type WillMsgReq ¶
func NewWillMsgReq ¶
func NewWillMsgReq() *WillMsgReq
func (*WillMsgReq) Pack ¶
func (p *WillMsgReq) Pack() ([]byte, error)
func (WillMsgReq) String ¶
func (p WillMsgReq) String() string
func (*WillMsgReq) Unpack ¶
func (p *WillMsgReq) Unpack(buf []byte) error
type WillMsgResp ¶
type WillMsgResp struct { pkts.Header // Fields ReturnCode ReturnCode }
func NewWillMsgResp ¶
func NewWillMsgResp(returnCode ReturnCode) *WillMsgResp
func (*WillMsgResp) Pack ¶
func (p *WillMsgResp) Pack() ([]byte, error)
func (WillMsgResp) String ¶
func (p WillMsgResp) String() string
func (*WillMsgResp) Unpack ¶
func (p *WillMsgResp) Unpack(buf []byte) error
type WillMsgUpd ¶
func NewWillMsgUpd ¶
func NewWillMsgUpd(willMsg []byte) *WillMsgUpd
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
func (*WillMsgUpd) Pack ¶
func (p *WillMsgUpd) Pack() ([]byte, error)
func (WillMsgUpd) String ¶
func (p WillMsgUpd) String() string
func (*WillMsgUpd) Unpack ¶
func (p *WillMsgUpd) Unpack(buf []byte) error
type WillTopic ¶
func NewWillTopic ¶
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
type WillTopicReq ¶
func NewWillTopicReq ¶
func NewWillTopicReq() *WillTopicReq
func (*WillTopicReq) Pack ¶
func (p *WillTopicReq) Pack() ([]byte, error)
func (WillTopicReq) String ¶
func (p WillTopicReq) String() string
func (*WillTopicReq) Unpack ¶
func (p *WillTopicReq) Unpack(buf []byte) error
type WillTopicResp ¶
type WillTopicResp struct { pkts.Header // Fields ReturnCode ReturnCode }
func NewWillTopicResp ¶
func NewWillTopicResp(returnCode ReturnCode) *WillTopicResp
func (*WillTopicResp) Pack ¶
func (p *WillTopicResp) Pack() ([]byte, error)
func (WillTopicResp) String ¶
func (p WillTopicResp) String() string
func (*WillTopicResp) Unpack ¶
func (p *WillTopicResp) Unpack(buf []byte) error
type WillTopicUpd ¶
func NewWillTopicUpd ¶
func NewWillTopicUpd(willTopic string, qos uint8, retain bool) *WillTopicUpd
NOTE: Packet length is initialized in this constructor and recomputed in m.Write().
func (*WillTopicUpd) Pack ¶
func (p *WillTopicUpd) Pack() ([]byte, error)
func (WillTopicUpd) String ¶
func (p WillTopicUpd) String() string
func (*WillTopicUpd) Unpack ¶
func (p *WillTopicUpd) Unpack(buf []byte) error
Source Files
¶
- advertise.go
- auth.go
- connack.go
- connect.go
- disconnect.go
- gwinfo.go
- packets1.go
- pingreq.go
- pingresp.go
- property_message_id.go
- puback.go
- pubcomp.go
- publish.go
- pubrec.go
- pubrel.go
- regack.go
- register.go
- searchgw.go
- suback.go
- subscribe.go
- unsuback.go
- unsubscribe.go
- willmsg.go
- willmsgreq.go
- willmsgresp.go
- willmsgupd.go
- willtopic.go
- willtopicreq.go
- willtopicresp.go
- willtopicupd.go