Documentation ¶
Overview ¶
Package packet defines the MQTT packet types
Index ¶
- Constants
- Variables
- func ReadByte(r io.Reader) (b byte, err error)
- func ReadBytes(r io.Reader) (b []byte, err error)
- func ReadRemainingLength(r io.Reader) (value int, err error)
- func ReadString(r io.Reader) (string, error)
- func ReadStringPair(r io.Reader) (string, string, error)
- func ReadUint16(r io.Reader) (i uint16, err error)
- func ReadUint32(r io.Reader) (i uint32, err error)
- func Write(w io.Writer, p ControlPacket) (err error)
- func WriteByte(w io.Writer, b byte) (err error)
- func WriteBytes(w io.Writer, b []byte) (err error)
- func WriteRemainingLength(w io.Writer, x int) (err error)
- func WriteString(w io.Writer, s string) error
- func WriteStringPair(w io.Writer, k, v string) error
- func WriteUint16(w io.Writer, i uint16) (err error)
- func WriteUint32(w io.Writer, i uint32) (err error)
- type ConnackPacket
- type ConnectPacket
- type ConnectReturnCode
- type ControlPacket
- type DisconnectPacket
- type PacketType
- type PingreqPacket
- type PingrespPacket
- type PubackPacket
- type PubcompPacket
- type PublishPacket
- type PubrecPacket
- type PubrelPacket
- type SubackPacket
- type SubscribePacket
- type UnsubackPacket
- type UnsubscribePacket
Constants ¶
const ( CONNECT = 1 // Client request to connect to Server CONNACK = 2 // Connect acknowledgment PUBLISH = 3 // Publish message PUBACK = 4 // Publish acknowledgment PUBREC = 5 // Publish received (assured delivery part 1) PUBREL = 6 // Publish release (assured delivery part 2) PUBCOMP = 7 // Publish complete (assured delivery part 3) SUBSCRIBE = 8 // Subscribe request SUBACK = 9 // Subscribe acknowledgment UNSUBSCRIBE = 10 // Unsubscribe request UNSUBACK = 11 // Unsubscribe acknowledgment PINGREQ = 12 // PING request PINGRESP = 13 // PING response DISCONNECT = 14 // Client is disconnecting AUTH = 15 // Authentication exchange )
Packet types
const ( AtMostOnce = 0 AtLeastOnce = 1 ExactlyOnce = 2 )
QoS Levels
Variables ¶
var ErrInvalidFlags = errors.New("Invalid flags")
ErrInvalidFlags is returned if the flags of a packet are invalid
var ErrInvalidLength = errors.New("Invalid Length")
ErrInvalidLength indicates an invalid length
var ErrInvalidPacketIdentifier = errors.New("Invalid packet identifier")
ErrInvalidPacketIdentifier is returned if an expected packet identifier was empty
var ErrInvalidPacketType = errors.New("Invalid packet type")
ErrInvalidPacketType is returned when the control packet type is invalid
var ErrInvalidQoS = errors.New("Invalid QoS")
ErrInvalidQoS is returned if the QoS of a publish packet is invalid
var ErrInvalidRemainingLength = errors.New("Invalid Remaining Length")
ErrInvalidRemainingLength when attempting to encode an invalid remaining length field
var ErrMalformedRemainingLength = errors.New("Malformed Remaining Length")
ErrMalformedRemainingLength is returned when attempting to read a malformed remaining length
var ErrProtocolViolation = errors.New("Protocol Violation")
ErrProtocolViolation is returned when a message violates the protocol specification
var Name = map[byte]string{ CONNECT: "connect", CONNACK: "connack", PUBLISH: "publish", PUBACK: "puback", PUBREC: "pubrec", PUBREL: "pubrel", PUBCOMP: "pubcomp", SUBSCRIBE: "subscribe", SUBACK: "suback", UNSUBSCRIBE: "unsubscribe", UNSUBACK: "unsuback", PINGREQ: "pingreq", PINGRESP: "pingresp", DISCONNECT: "disconnect", AUTH: "auth", }
var SubscribeRejected byte = 0x80
SubscribeRejected response code
Functions ¶
func ReadRemainingLength ¶
ReadRemainingLength returns the decoded remaining length field
func ReadString ¶
ReadString reads a string from the given Reader
func ReadStringPair ¶
ReadStringPair reads a string pair from the given Reader
func ReadUint16 ¶
ReadUint16 reads an uint16 from the given Reader
func ReadUint32 ¶
ReadUint32 reads an uint32 from the given Reader
func Write ¶
func Write(w io.Writer, p ControlPacket) (err error)
Write a control packet to the writer
func WriteBytes ¶
WriteBytes writes bytes to the given Writer
func WriteRemainingLength ¶
WriteRemainingLength writes a remaining length field to the given Writer
func WriteString ¶
WriteString writes a string to the given Writer
func WriteStringPair ¶
WriteStringPair writes a string pair to the given Writer
func WriteUint16 ¶
WriteUint16 writes an uint16 to the given Writer
Types ¶
type ConnackPacket ¶
type ConnackPacket struct { ReturnCode ConnectReturnCode SessionPresent bool }
ConnackPacket is the CONNACK packet
func (ConnackPacket) MarshalBinary ¶
func (p ConnackPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (ConnackPacket) PacketType ¶
func (ConnackPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*ConnackPacket) UnmarshalBinary ¶
func (p *ConnackPacket) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (ConnackPacket) Validate ¶
func (p ConnackPacket) Validate() error
Validate the packet contents
type ConnectPacket ¶
type ConnectPacket struct { ProtocolName string ProtocolLevel byte CleanStart bool Will bool WillQoS byte WillRetain bool KeepAlive uint16 ClientID string WillTopic string WillMessage []byte Username string Password []byte }
ConnectPacket is the CONNECT packet
func (ConnectPacket) MarshalBinary ¶
func (p ConnectPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (ConnectPacket) PacketType ¶
func (ConnectPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (ConnectPacket) Response ¶
func (p ConnectPacket) Response() *ConnackPacket
Response to the packet
func (*ConnectPacket) UnmarshalBinary ¶
func (p *ConnectPacket) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (ConnectPacket) Validate ¶
func (p ConnectPacket) Validate() error
Validate the packet contents
type ConnectReturnCode ¶
type ConnectReturnCode byte
ConnectReturnCode is returned in the Connack
var ( ConnectAccepted ConnectReturnCode = 0x00 ConnectUnacceptableProtocolVersion ConnectReturnCode = 0x01 ConnectIdentifierRejected ConnectReturnCode = 0x02 ConnectMalformedUsernameOrPassword ConnectReturnCode = 0x04 ConnectNotAuthorized ConnectReturnCode = 0x05 )
Connect return codes
func (ConnectReturnCode) Error ¶
func (c ConnectReturnCode) Error() string
type ControlPacket ¶
type ControlPacket interface { encoding.BinaryMarshaler // without fixed header encoding.BinaryUnmarshaler // without fixed header PacketType() byte Validate() error // contains filtered or unexported methods }
ControlPacket represents an MQTT Control Packet
type DisconnectPacket ¶
type DisconnectPacket struct { }
DisconnectPacket is the DISCONNECT packet
func (DisconnectPacket) MarshalBinary ¶
func (p DisconnectPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (DisconnectPacket) PacketType ¶
func (DisconnectPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*DisconnectPacket) UnmarshalBinary ¶
func (p *DisconnectPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (DisconnectPacket) Validate ¶
func (p DisconnectPacket) Validate() error
Validate the packet contents (noop)
type PingreqPacket ¶
type PingreqPacket struct { }
PingreqPacket is the PINGREQ packet
func (PingreqPacket) MarshalBinary ¶
func (p PingreqPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PingreqPacket) PacketType ¶
func (PingreqPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (PingreqPacket) Response ¶
func (p PingreqPacket) Response() *PingrespPacket
Response to the packet
func (*PingreqPacket) UnmarshalBinary ¶
func (p *PingreqPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (PingreqPacket) Validate ¶
func (p PingreqPacket) Validate() error
Validate the packet contents (noop)
type PingrespPacket ¶
type PingrespPacket struct { }
PingrespPacket is the PINGRESP packet
func (PingrespPacket) MarshalBinary ¶
func (p PingrespPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PingrespPacket) PacketType ¶
func (PingrespPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*PingrespPacket) UnmarshalBinary ¶
func (p *PingrespPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (PingrespPacket) Validate ¶
func (p PingrespPacket) Validate() error
Validate the packet contents (noop)
type PubackPacket ¶
type PubackPacket struct {
PacketIdentifier uint16
}
PubackPacket is the PUBACK packet
func (PubackPacket) MarshalBinary ¶
func (p PubackPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PubackPacket) PacketType ¶
func (PubackPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*PubackPacket) UnmarshalBinary ¶
func (p *PubackPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
type PubcompPacket ¶
type PubcompPacket struct {
PacketIdentifier uint16
}
PubcompPacket is the PUBCOMP packet
func (PubcompPacket) MarshalBinary ¶
func (p PubcompPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PubcompPacket) PacketType ¶
func (PubcompPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*PubcompPacket) UnmarshalBinary ¶
func (p *PubcompPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (PubcompPacket) Validate ¶
func (p PubcompPacket) Validate() error
Validate the packet contents
type PublishPacket ¶
type PublishPacket struct { Received time.Time `json:"received"` Retain bool `json:"retained"` QoS byte `json:"qos"` Duplicate bool `json:"-"` PacketIdentifier uint16 `json:"-"` TopicName string `json:"topic"` TopicParts []string `json:"-"` Message []byte `json:"message"` }
PublishPacket is the PUBLISH packet
func (PublishPacket) MarshalBinary ¶
func (p PublishPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PublishPacket) PacketType ¶
func (PublishPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (PublishPacket) Response ¶
func (p PublishPacket) Response() ControlPacket
Response to the packet
func (*PublishPacket) UnmarshalBinary ¶
func (p *PublishPacket) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (PublishPacket) Validate ¶
func (p PublishPacket) Validate() error
Validate the packet contents
type PubrecPacket ¶
type PubrecPacket struct {
PacketIdentifier uint16
}
PubrecPacket is the PUBREC packet
func (PubrecPacket) MarshalBinary ¶
func (p PubrecPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PubrecPacket) PacketType ¶
func (PubrecPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (PubrecPacket) Response ¶
func (p PubrecPacket) Response() *PubrelPacket
Response to the packet
func (*PubrecPacket) UnmarshalBinary ¶
func (p *PubrecPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
type PubrelPacket ¶
type PubrelPacket struct {
PacketIdentifier uint16
}
PubrelPacket is the PUBREL packet
func (PubrelPacket) MarshalBinary ¶
func (p PubrelPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (PubrelPacket) PacketType ¶
func (PubrelPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (PubrelPacket) Response ¶
func (p PubrelPacket) Response() *PubcompPacket
Response to the packet
func (*PubrelPacket) UnmarshalBinary ¶
func (p *PubrelPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
type SubackPacket ¶
SubackPacket is the SUBACK packet
func (SubackPacket) MarshalBinary ¶
func (p SubackPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (SubackPacket) PacketType ¶
func (SubackPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*SubackPacket) UnmarshalBinary ¶
func (p *SubackPacket) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary implements encoding.BinaryUnmarshaler
type SubscribePacket ¶
SubscribePacket is the SUBSCRIBE packet
func (SubscribePacket) MarshalBinary ¶
func (p SubscribePacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (SubscribePacket) PacketType ¶
func (SubscribePacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (SubscribePacket) Response ¶
func (p SubscribePacket) Response() *SubackPacket
Response to the packet
func (*SubscribePacket) UnmarshalBinary ¶
func (p *SubscribePacket) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (SubscribePacket) Validate ¶
func (p SubscribePacket) Validate() (err error)
Validate the packet contents
type UnsubackPacket ¶
type UnsubackPacket struct {
PacketIdentifier uint16
}
UnsubackPacket is the UNSUBACK packet
func (UnsubackPacket) MarshalBinary ¶
func (p UnsubackPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (UnsubackPacket) PacketType ¶
func (UnsubackPacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (*UnsubackPacket) UnmarshalBinary ¶
func (p *UnsubackPacket) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (UnsubackPacket) Validate ¶
func (p UnsubackPacket) Validate() error
Validate the packet contents
type UnsubscribePacket ¶
UnsubscribePacket is the UNSUBSCRIBE packet
func (UnsubscribePacket) MarshalBinary ¶
func (p UnsubscribePacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements encoding.BinaryMarshaler
func (UnsubscribePacket) PacketType ¶
func (UnsubscribePacket) PacketType() byte
PacketType returns the MQTT packet type of this packet
func (UnsubscribePacket) Response ¶
func (p UnsubscribePacket) Response() *UnsubackPacket
Response to the packet
func (*UnsubscribePacket) UnmarshalBinary ¶
func (p *UnsubscribePacket) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (UnsubscribePacket) Validate ¶
func (p UnsubscribePacket) Validate() (err error)
Validate the packet contents