Documentation ¶
Index ¶
- Constants
- Variables
- type FixedHeader
- type Packet
- func (pk *Packet) ConnackDecode(buf []byte) error
- func (pk *Packet) ConnackEncode(buf *bytes.Buffer) error
- func (pk *Packet) ConnectDecode(buf []byte) error
- func (pk *Packet) ConnectEncode(buf *bytes.Buffer) error
- func (pk *Packet) ConnectValidate() (b byte, err error)
- func (pk *Packet) DisconnectEncode(buf *bytes.Buffer) error
- func (pk *Packet) FormatID() string
- func (pk *Packet) PingreqEncode(buf *bytes.Buffer) error
- func (pk *Packet) PingrespEncode(buf *bytes.Buffer) error
- func (pk *Packet) PubackDecode(buf []byte) error
- func (pk *Packet) PubackEncode(buf *bytes.Buffer) error
- func (pk *Packet) PubcompDecode(buf []byte) error
- func (pk *Packet) PubcompEncode(buf *bytes.Buffer) error
- func (pk *Packet) PublishCopy() Packet
- func (pk *Packet) PublishDecode(buf []byte) error
- func (pk *Packet) PublishEncode(buf *bytes.Buffer) error
- func (pk *Packet) PublishValidate() (byte, error)
- func (pk *Packet) PubrecDecode(buf []byte) error
- func (pk *Packet) PubrecEncode(buf *bytes.Buffer) error
- func (pk *Packet) PubrelDecode(buf []byte) error
- func (pk *Packet) PubrelEncode(buf *bytes.Buffer) error
- func (pk *Packet) SubackDecode(buf []byte) error
- func (pk *Packet) SubackEncode(buf *bytes.Buffer) error
- func (pk *Packet) SubscribeDecode(buf []byte) error
- func (pk *Packet) SubscribeEncode(buf *bytes.Buffer) error
- func (pk *Packet) SubscribeValidate() (byte, error)
- func (pk *Packet) UnsubackDecode(buf []byte) error
- func (pk *Packet) UnsubackEncode(buf *bytes.Buffer) error
- func (pk *Packet) UnsubscribeDecode(buf []byte) error
- func (pk *Packet) UnsubscribeEncode(buf *bytes.Buffer) error
- func (pk *Packet) UnsubscribeValidate() (byte, error)
Constants ¶
const ( Reserved byte = iota Connect // 1 Connack // 2 Publish // 3 Puback // 4 Pubrec // 5 Pubrel // 6 Pubcomp // 7 Subscribe // 8 Suback // 9 Unsubscribe // 10 Unsuback // 11 Pingreq // 12 Pingresp // 13 Disconnect // 14 Accepted byte = 0x00 Failed byte = 0xFF CodeConnectBadProtocolVersion byte = 0x01 CodeConnectBadClientID byte = 0x02 CodeConnectBadAuthValues byte = 0x04 CodeConnectNotAuthorised byte = 0x05 CodeConnectNetworkError byte = 0xFE CodeConnectProtocolViolation byte = 0xFF ErrSubAckNetworkError byte = 0x80 )
All of the valid packet types and their packet identifier.
Variables ¶
var ( // CONNECT ErrMalformedProtocolName = errors.New("malformed packet: protocol name") ErrMalformedProtocolVersion = errors.New("malformed packet: protocol version") ErrMalformedFlags = errors.New("malformed packet: flags") ErrMalformedKeepalive = errors.New("malformed packet: keepalive") ErrMalformedClientID = errors.New("malformed packet: client id") ErrMalformedWillTopic = errors.New("malformed packet: will topic") ErrMalformedWillMessage = errors.New("malformed packet: will message") ErrMalformedUsername = errors.New("malformed packet: username") ErrMalformedPassword = errors.New("malformed packet: password") // CONNACK ErrMalformedSessionPresent = errors.New("malformed packet: session present") ErrMalformedReturnCode = errors.New("malformed packet: return code") // PUBLISH ErrMalformedTopic = errors.New("malformed packet: topic name") ErrMalformedPacketID = errors.New("malformed packet: packet id") // SUBSCRIBE ErrMalformedQoS = errors.New("malformed packet: qos") // PACKETS ErrProtocolViolation = errors.New("protocol violation") ErrOffsetBytesOutOfRange = errors.New("offset bytes out of range") ErrOffsetByteOutOfRange = errors.New("offset byte out of range") ErrOffsetBoolOutOfRange = errors.New("offset bool out of range") ErrOffsetUintOutOfRange = errors.New("offset uint out of range") ErrOffsetStrInvalidUTF8 = errors.New("offset string invalid utf8") ErrInvalidFlags = errors.New("invalid flags set for packet") ErrOversizedLengthIndicator = errors.New("protocol violation: oversized length indicator") ErrMissingPacketID = errors.New("missing packet id") ErrSurplusPacketID = errors.New("surplus packet id") )
Functions ¶
This section is empty.
Types ¶
type FixedHeader ¶
type FixedHeader struct { Remaining int // the number of remaining bytes in the payload. Type byte // the type of the packet (PUBLISH, SUBSCRIBE, etc) from bits 7 - 4 (byte 1). Qos byte // indicates the quality of service expected. Dup bool // indicates if the packet was already sent at an earlier time. Retain bool // whether the message should be retained. }
FixedHeader contains the values of the fixed header portion of the MQTT packet.
func (*FixedHeader) Decode ¶
func (fh *FixedHeader) Decode(headerByte byte) error
Decode extracts the specification bits from the header byte.
func (*FixedHeader) Encode ¶
func (fh *FixedHeader) Encode(buf *bytes.Buffer)
Encode encodes the FixedHeader and returns a bytes buffer.
type Packet ¶
type Packet struct { FixedHeader FixedHeader AllowClients []string // For use with OnMessage event hook. Topics []string ReturnCodes []byte ProtocolName []byte Qoss []byte Payload []byte Username []byte Password []byte WillMessage []byte ClientIdentifier string TopicName string WillTopic string PacketID uint16 Keepalive uint16 ReturnCode byte ProtocolVersion byte WillQos byte ReservedBit byte CleanSession bool WillFlag bool WillRetain bool UsernameFlag bool PasswordFlag bool SessionPresent bool }
Packet is an MQTT packet. Instead of providing a packet interface and variant packet structs, this is a single concrete packet type to cover all packet types, which allows us to take advantage of various compiler optimizations.
func (*Packet) ConnackDecode ¶
ConnackDecode decodes a Connack packet.
func (*Packet) ConnackEncode ¶
ConnackEncode encodes a Connack packet.
func (*Packet) ConnectDecode ¶
ConnectDecode decodes a connect packet.
func (*Packet) ConnectEncode ¶
ConnectEncode encodes a connect packet.
func (*Packet) ConnectValidate ¶
ConnectValidate ensures the connect packet is compliant.
func (*Packet) DisconnectEncode ¶
DisconnectEncode encodes a Disconnect packet.
func (*Packet) PingreqEncode ¶
PingreqEncode encodes a Pingreq packet.
func (*Packet) PingrespEncode ¶
PingrespEncode encodes a Pingresp packet.
func (*Packet) PubackDecode ¶
PubackDecode decodes a Puback packet.
func (*Packet) PubackEncode ¶
PubackEncode encodes a Puback packet.
func (*Packet) PubcompDecode ¶
PubcompDecode decodes a Pubcomp packet.
func (*Packet) PubcompEncode ¶
PubcompEncode encodes a Pubcomp packet.
func (*Packet) PublishCopy ¶
PublishCopy creates a new instance of Publish packet bearing the same payload and destination topic, but with an empty header for inheriting new QoS flags, etc.
func (*Packet) PublishDecode ¶
PublishDecode extracts the data values from the packet.
func (*Packet) PublishEncode ¶
PublishEncode encodes a Publish packet.
func (*Packet) PublishValidate ¶
PublishValidate validates a publish packet.
func (*Packet) PubrecDecode ¶
PubrecDecode decodes a Pubrec packet.
func (*Packet) PubrecEncode ¶
PubrecEncode encodes a Pubrec packet.
func (*Packet) PubrelDecode ¶
PubrelDecode decodes a Pubrel packet.
func (*Packet) PubrelEncode ¶
PubrelEncode encodes a Pubrel packet.
func (*Packet) SubackDecode ¶
SubackDecode decodes a Suback packet.
func (*Packet) SubackEncode ¶
SubackEncode encodes a Suback packet.
func (*Packet) SubscribeDecode ¶
SubscribeDecode decodes a Subscribe packet.
func (*Packet) SubscribeEncode ¶
SubscribeEncode encodes a Subscribe packet.
func (*Packet) SubscribeValidate ¶
SubscribeValidate ensures the packet is compliant.
func (*Packet) UnsubackDecode ¶
UnsubackDecode decodes an Unsuback packet.
func (*Packet) UnsubackEncode ¶
UnsubackEncode encodes an Unsuback packet.
func (*Packet) UnsubscribeDecode ¶
UnsubscribeDecode decodes an Unsubscribe packet.
func (*Packet) UnsubscribeEncode ¶
UnsubscribeEncode encodes an Unsubscribe packet.
func (*Packet) UnsubscribeValidate ¶
UnsubscribeValidate validates an Unsubscribe packet.