packet

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2014 License: MIT Imports: 4 Imported by: 3

Documentation

Overview

Package packet provides MQTT Control Packets.

Index

Constants

View Source
const (
	TypeCONNECT     byte = 0x01
	TypeCONNACK     byte = 0x02
	TypePUBLISH     byte = 0x03
	TypePUBACK      byte = 0x04
	TypePUBREC      byte = 0x05
	TypePUBREL      byte = 0x06
	TypePUBCOMP     byte = 0x07
	TypeSUBSCRIBE   byte = 0x08
	TypeSUBACK      byte = 0x09
	TypeUNSUBSCRIBE byte = 0x0A
	TypeUNSUBACK    byte = 0x0B
	TypePINGREQ     byte = 0x0C
	TypePINGRESP    byte = 0x0D
	TypeDISCONNECT  byte = 0x0E
)

MQTT Control Packet types

View Source
const SUBACKRetFailure byte = 0x80

Return Code Failure

Variables

View Source
var (
	ErrInvalidFixedHeader       = errors.New("invalid fixed header")
	ErrInvalidVariableHeaderLen = errors.New("invalid length of the variable header")
	ErrInvalidRemainingLen      = errors.New("invalid length of the remaining")
	ErrInvalidVariableHeader    = errors.New("invalid variable header")
	ErrInvalidRemainingLength   = errors.New("invalid Remaining Length")
	ErrInvalidConnectReturnCode = errors.New("invalid Connect Return code")
)

Error values

View Source
var (
	ErrClientIDExceedsMaxStringsLen    = errors.New("the length of the Client Identifier exceeds the maximum strings legnth")
	ErrUserNameExceedsMaxStringsLen    = errors.New("the length of the User Name exceeds the maximum strings legnth")
	ErrPasswordExceedsMaxStringsLen    = errors.New("the length of the Password exceeds the maximum strings legnth")
	ErrWillTopicExceedsMaxStringsLen   = errors.New("the length of the Will Topic exceeds the maximum strings legnth")
	ErrWillMessageExceedsMaxStringsLen = errors.New("the length of the Will Message exceeds the maximum strings legnth")
	ErrInvalidClientIDCleanSession     = errors.New("the Clean Session must be true if the Client Identifier is zero-byte")
	ErrInvalidClientIDPassword         = errors.New("the Password must be zero-byte if the Client Identifier is zero-byte")
	ErrInvalidWillTopicMessage         = errors.New("the Will Topic (Message) must not be zero-byte if the Will Message (Topic) is not zero-byte")
	ErrInvalidWillQoS                  = errors.New("the Will QoS is invalid")
	ErrInvalidWillTopicMessageQoS      = errors.New("the Will QoS must be zero if both the Will Topic and the Will Message are zero-byte")
	ErrInvalidWillTopicMessageRetain   = errors.New("the Will Retain must be false if both the Will Topic and the Will Message are zero-byte")
)

Error values

View Source
var (
	ErrInvalidQoS                    = errors.New("the QoS is invalid")
	ErrTopicNameExceedsMaxStringsLen = errors.New("the length of the Topic Name exceeds the maximum strings legnth")
	ErrTopicNameContainsWildcards    = errors.New("the Topic Name contains wildcard characters")
	ErrMessageExceedsMaxStringsLen   = errors.New("the length of the Message exceeds the maximum strings legnth")
)

Error values

View Source
var (
	ErrNoTopicFilter                   = errors.New("the Topic Filter must be specified")
	ErrTopicFilterExceedsMaxStringsLen = errors.New("the length of the Topic Filter exceeds the maximum strings legnth")
)

Error values

View Source
var ErrInvalidByteLen = errors.New("invalid byte length")

Error value

View Source
var ErrInvalidFixedHeaderLen = errors.New("the length of the fixed header is invalid")

Error value

View Source
var ErrInvalidNoSubReq = errors.New("subscription request must be specified")

Error value

View Source
var ErrInvalidPacketID = errors.New("invalid Packet Identifier")

Error value

View Source
var ErrInvalidPacketType = errors.New("invalid MQTT Control Packet type")

Error value

View Source
var ErrInvalidSUBACKReturnCode = errors.New("invalid SUBACK Return Code")

Error value

Functions

This section is empty.

Types

type CONNACK

type CONNACK struct {
	// contains filtered or unexported fields
}

CONNACK represents a CONNACK Packet.

func (*CONNACK) Type

func (b *CONNACK) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*CONNACK) WriteTo

func (b *CONNACK) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type CONNECT

type CONNECT struct {
	// contains filtered or unexported fields
}

CONNECT represents a CONNECT Packet.

func (*CONNECT) Type

func (b *CONNECT) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*CONNECT) WriteTo

func (b *CONNECT) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type CONNECTOptions

type CONNECTOptions struct {
	// ClientID is the Client Identifier of the payload.
	ClientID []byte
	// UserName is the User Name of the payload.
	UserName []byte
	// Password is the Password of the payload.
	Password []byte
	// CleanSession is the Clean Session of the variable header.
	CleanSession bool
	// KeepAlive is the Keep Alive of the variable header.
	KeepAlive uint16
	// WillTopic is the Will Topic of the payload.
	WillTopic []byte
	// WillMessage is the Will Message of the payload.
	WillMessage []byte
	// WillQoS is the Will QoS of the variable header.
	WillQoS byte
	// WillRetain is the Will Retain of the variable header.
	WillRetain bool
}

CONNECTOptions represents options for a CONNECT Packet.

type DISCONNECT

type DISCONNECT struct {
	// contains filtered or unexported fields
}

DISCONNECT represents a DISCONNECT Packet.

func (*DISCONNECT) Type

func (b *DISCONNECT) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*DISCONNECT) WriteTo

func (b *DISCONNECT) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type FixedHeader

type FixedHeader []byte

FixedHeader represents the fixed header of the Packet.

type PINGREQ

type PINGREQ struct {
	// contains filtered or unexported fields
}

PINGREQ represents a PINGREQ Packet.

func (*PINGREQ) Type

func (b *PINGREQ) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PINGREQ) WriteTo

func (b *PINGREQ) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PINGRESP

type PINGRESP struct {
	// contains filtered or unexported fields
}

PINGRESP represents a PINGRESP Packet.

func (*PINGRESP) Type

func (b *PINGRESP) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PINGRESP) WriteTo

func (b *PINGRESP) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PUBACK

type PUBACK struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// contains filtered or unexported fields
}

PUBACK represents a PUBACK Packet.

func (*PUBACK) Type

func (b *PUBACK) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PUBACK) WriteTo

func (b *PUBACK) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PUBACKOptions

type PUBACKOptions struct {
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
}

PUBACKOptions represents options for a PUBACK Packet.

type PUBCOMP

type PUBCOMP struct {

	// packetID is the Packet Identifier of the variable header.
	PacketID uint16
	// contains filtered or unexported fields
}

PUBCOMP represents a PUBCOMP Packet.

func (*PUBCOMP) Type

func (b *PUBCOMP) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PUBCOMP) WriteTo

func (b *PUBCOMP) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PUBCOMPOptions

type PUBCOMPOptions struct {
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
}

PUBCOMPOptions represents options for a PUBCOMP Packet.

type PUBLISH

type PUBLISH struct {

	// dup is the DUP flag of the fixed header.
	DUP bool
	// qos is the QoS of the fixed header.
	QoS byte

	// topicName is the Topic Name of the varible header.
	TopicName []byte
	// packetID is the Packet Identifier of the variable header.
	PacketID uint16
	// message is the Application Message of the payload.
	Message []byte
	// contains filtered or unexported fields
}

PUBLISH represents a PUBLISH Packet.

func (*PUBLISH) Type

func (b *PUBLISH) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PUBLISH) WriteTo

func (b *PUBLISH) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PUBLISHOptions

type PUBLISHOptions struct {
	// DUP is the DUP flag of the fixed header.
	DUP bool
	// QoS is the QoS of the fixed header.
	QoS byte
	// Retain is the Retain of the fixed header.
	Retain bool
	// TopicName is the Topic Name of the varible header.
	TopicName []byte
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// Message is the Application Message of the payload.
	Message []byte
}

PUBLISHOptions represents options for a PUBLISH Packet.

type PUBREC

type PUBREC struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// contains filtered or unexported fields
}

PUBREC represents a PUBREC Packet.

func (*PUBREC) Type

func (b *PUBREC) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PUBREC) WriteTo

func (b *PUBREC) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PUBRECOptions

type PUBRECOptions struct {
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
}

PUBRECOptions represents options for a PUBREC Packet.

type PUBREL

type PUBREL struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// contains filtered or unexported fields
}

PUBREL represents a PUBREL Packet.

func (*PUBREL) Type

func (b *PUBREL) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*PUBREL) WriteTo

func (b *PUBREL) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type PUBRELOptions

type PUBRELOptions struct {
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
}

PUBRELOptions represents options for a PUBREL Packet.

type Packet

type Packet interface {
	io.WriterTo
	// Type returns the MQTT Control Packet type of the Packet.
	Type() (byte, error)
}

Packet represents an MQTT Control Packet.

func NewCONNACKFromBytes

func NewCONNACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error)

NewCONNACKFromBytes creates the CONNACK Packet from the byte data and returns it.

func NewCONNECT

func NewCONNECT(opts *CONNECTOptions) (Packet, error)

NewCONNECT creates and returns a CONNECT Packet.

func NewDISCONNECT

func NewDISCONNECT() Packet

NewDISCONNECT creates and returns a DISCONNECT Packet.

func NewFromBytes

func NewFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error)

NewFromBytes creates a Packet from the byte data and returns it.

func NewPINGREQ

func NewPINGREQ() Packet

NewPINGREQ creates and returns a PINGREQ Packet.

func NewPINGRESPFromBytes

func NewPINGRESPFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error)

NewPINGRESPFromBytes creates a PINGRESP Packet from the byte data and returns it.

func NewPUBACK

func NewPUBACK(opts *PUBACKOptions) (Packet, error)

NewPUBACK creates and returns a PUBACK Packet.

func NewPUBACKFromBytes

func NewPUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error)

NewPUBACKFromBytes creates a PUBACK Packet from the byte data and returns it.

func NewPUBCOMP

func NewPUBCOMP(opts *PUBCOMPOptions) (Packet, error)

NewPUBCOMP creates and returns a PUBCOMP Packet.

func NewPUBCOMPFromBytes

func NewPUBCOMPFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error)

NewPUBCOMPFromBytes creates a PUBCOMP Packet from the byte data and returns it.

func NewPUBLISH

func NewPUBLISH(opts *PUBLISHOptions) (Packet, error)

NewPUBLISH creates and returns a PUBLISH Packet.

func NewPUBLISHFromBytes

func NewPUBLISHFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error)

NewPUBLISHFromBytes creates the PUBLISH Packet from the byte data and returns it.

func NewPUBREC

func NewPUBREC(opts *PUBRECOptions) (Packet, error)

NewPUBREC creates and returns a PUBACK Packet.

func NewPUBRECFromBytes

func NewPUBRECFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error)

NewPUBRECFromBytes creates a PUBREC Packet from the byte data and returns it.

func NewPUBREL

func NewPUBREL(opts *PUBRELOptions) (Packet, error)

NewPUBREL creates and returns a PUBREL Packet.

func NewPUBRELFromBytes

func NewPUBRELFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error)

NewPUBRELFromBytes creates a PUBREL Packet from the byte data and returns it.

func NewSUBACKFromBytes

func NewSUBACKFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error)

NewSUBACKFromBytes creates a SUBACK Packet from the byte data and returns it.

func NewSUBSCRIBE

func NewSUBSCRIBE(opts *SUBSCRIBEOptions) (Packet, error)

NewSUBSCRIBE creates and returns a SUBSCRIBE Packet.

func NewUNSUBACKFromBytes

func NewUNSUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error)

NewUNSUBACKFromBytes creates an UNSUBACK Packet from the byte data and returns it.

func NewUNSUBSCRIBE

func NewUNSUBSCRIBE(opts *UNSUBSCRIBEOptions) (Packet, error)

NewUNSUBSCRIBE creates and returns an UNSUBSCRIBE Packet.

type SUBACK

type SUBACK struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// ReturnCodes is the Return Codes of the payload.
	ReturnCodes []byte
	// contains filtered or unexported fields
}

SUBACK represents a SUBACK Packet.

func (*SUBACK) Type

func (b *SUBACK) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*SUBACK) WriteTo

func (b *SUBACK) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type SUBSCRIBE

type SUBSCRIBE struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// SubReqs is a slice of the subscription requests.
	SubReqs []*SubReq
	// contains filtered or unexported fields
}

SUBSCRIBE represents a SUBSCRIBE Packet.

func (*SUBSCRIBE) Type

func (b *SUBSCRIBE) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*SUBSCRIBE) WriteTo

func (b *SUBSCRIBE) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type SUBSCRIBEOptions

type SUBSCRIBEOptions struct {
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// SubReqs is a slice of the subscription requests.
	SubReqs []*SubReq
}

SUBSCRIBEOptions represents options for a SUBSCRIBE Packet.

type SubReq

type SubReq struct {
	// TopicFilter is the Topic Filter of the Subscription.
	TopicFilter []byte
	// QoS is the requsting QoS.
	QoS byte
}

SubReq represents subscription request.

type UNSUBACK

type UNSUBACK struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// contains filtered or unexported fields
}

UNSUBACK represents an UNSUBACK Packet.

func (*UNSUBACK) Type

func (b *UNSUBACK) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*UNSUBACK) WriteTo

func (b *UNSUBACK) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type UNSUBSCRIBE

type UNSUBSCRIBE struct {

	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// TopicFilters represents a slice of the Topic Filters
	TopicFilters [][]byte
	// contains filtered or unexported fields
}

UNSUBSCRIBE represents an UNSUBSCRIBE Packet.

func (*UNSUBSCRIBE) Type

func (b *UNSUBSCRIBE) Type() (byte, error)

Type extracts the MQTT Control Packet type from the fixed header and returns it.

func (*UNSUBSCRIBE) WriteTo

func (b *UNSUBSCRIBE) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Packet data to the writer.

type UNSUBSCRIBEOptions

type UNSUBSCRIBEOptions struct {
	// PacketID is the Packet Identifier of the variable header.
	PacketID uint16
	// TopicFilters represents a slice of the Topic Filters
	TopicFilters [][]byte
}

UNSUBSCRIBEOptions represents options for an UNSUBSCRIBE Packet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL