packets

package
v0.0.0-...-91c8fa4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: EPL-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	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
)

Below are the constants assigned to each of the MQTT packet types

View Source
const (
	Accepted                        = 0x00
	ErrRefusedBadProtocolVersion    = 0x01
	ErrRefusedIDRejected            = 0x02
	ErrRefusedServerUnavailable     = 0x03
	ErrRefusedBadUsernameOrPassword = 0x04
	ErrRefusedNotAuthorised         = 0x05
	ErrNetworkError                 = 0xFE
	ErrProtocolViolation            = 0xFF
)

Below are the const definitions for error codes returned by Connect()

View Source
const Failure = 0x80

Failure defined error codes returned by Connect()

View Source
const (

	// MaxRemainingLength the max length of remain
	MaxRemainingLength = 268435455 // 0xFF, 0xFF, 0xFF, 0x7F
)

Variables

View Source
var (
	// ErrInternal will occored on internal error, which should not happen.
	ErrInternal = errors.New("internal error occurred")
	// ErrReadPacketLimitation return on packet remain length too large
	ErrReadPacketLimitation = errors.New("packet size exceeded limitation")
	// ErrMQTTPacketLimitation return on the mqtt packet remain length too large
	ErrMQTTPacketLimitation = errors.New("the mqtt packet size exceeded limitation")
)
View Source
var ConnErrors = map[byte]error{
	Accepted:                        nil,
	ErrRefusedBadProtocolVersion:    errors.New("Unnacceptable protocol version"),
	ErrRefusedIDRejected:            errors.New("Identifier rejected"),
	ErrRefusedServerUnavailable:     errors.New("Server Unavailable"),
	ErrRefusedBadUsernameOrPassword: errors.New("Bad user name or password"),
	ErrRefusedNotAuthorised:         errors.New("Not Authorized"),
	ErrNetworkError:                 errors.New("Network Error"),
	ErrProtocolViolation:            errors.New("Protocol Violation"),
}

ConnErrors is a map of the errors codes constants for Connect() to a Go error

View Source
var ConnackReturnCodes = map[uint8]string{
	0:   "Connection Accepted",
	1:   "Connection Refused: Bad Protocol Version",
	2:   "Connection Refused: Client Identifier Rejected",
	3:   "Connection Refused: Server Unavailable",
	4:   "Connection Refused: Username or Password in unknown format",
	5:   "Connection Refused: Not Authorised",
	254: "Connection Error",
	255: "Connection Refused: Protocol Violation",
}

ConnackReturnCodes is a map of the error codes constants for Connect() to a string representation of the error

View Source
var PacketNames = []string{
	0:  "Reserved",
	1:  "CONNECT",
	2:  "CONNACK",
	3:  "PUBLISH",
	4:  "PUBACK",
	5:  "PUBREC",
	6:  "PUBREL",
	7:  "PUBCOMP",
	8:  "SUBSCRIBE",
	9:  "SUBACK",
	10: "UNSUBSCRIBE",
	11: "UNSUBACK",
	12: "PINGREQ",
	13: "PINGRESP",
	14: "DISCONNECT",
	15: "Reserved",
}

PacketNames maps the constants for each of the MQTT packet types to a string representation of their name.

View Source
var SubackReturnCodes = map[uint8]string{
	0:   "Subscribe succeed, Maximum QoS 0",
	1:   "Subscribe succeed, Maximum QoS 1",
	2:   "Subscribe succeed, Maximum QoS 2",
	128: "Subscribe failed",
}

SubackReturnCodes is a map of the error codes constants for Subscribe() to a string representation of the error

Functions

func Getbuf

func Getbuf() (b *leakBuffer)

Getbuf returns a buffer from the leaky buffer or create a new buffer.

func NewBufferPool

func NewBufferPool(bufSize int)

NewBufferPool creates a leaky buffer which can hold at most n buffer, each with bufSize bytes.

func Putbuf

func Putbuf(b *leakBuffer)

Putbuf add the buffer into the free buffer pool for reuse. Panic if the buffer size is not the same with the leaky buffer's. This is intended to expose error usage of leaky buffer.

func WritePacket

func WritePacket(w io.Writer, p ControlPacket) (int, error)

WritePacket write a packet to w

Types

type ConnackPacket

type ConnackPacket struct {
	*FixedHeader
	SessionPresent bool
	ReturnCode     byte
	TraceID        string
}

ConnackPacket is an internal representation of the fields of the Connack MQTT packet

func NewConnackPacket

func NewConnackPacket() *ConnackPacket

NewConnackPacket return the connect ack packet

func (*ConnackPacket) Close

func (ca *ConnackPacket) Close()

Close reset the packet field put the control packet back to pool

func (*ConnackPacket) Details

func (ca *ConnackPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*ConnackPacket) Reset

func (ca *ConnackPacket) Reset()

Reset will initialize the fields in control packet

func (*ConnackPacket) SetFixedHeader

func (ca *ConnackPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*ConnackPacket) SetTraceID

func (ca *ConnackPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*ConnackPacket) String

func (ca *ConnackPacket) String() string

String export the packet of connack information

func (*ConnackPacket) Type

func (ca *ConnackPacket) Type() byte

Type return the packet type

func (*ConnackPacket) Unpack

func (ca *ConnackPacket) Unpack(b []byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*ConnackPacket) Verify

func (ca *ConnackPacket) Verify() bool

Verify packet availability

func (*ConnackPacket) Write

func (ca *ConnackPacket) Write(w io.Writer) (length int, err error)

Write will write the packets mostly into a net.Conn | --- Fixed Header --- | | --- SessionPresent --- | | --- ReturnCode --- | Connack is a specify length packet. So we only use one bytes

type ConnectPacket

type ConnectPacket struct {
	*FixedHeader
	ProtocolName    string
	ProtocolVersion byte
	CleanSession    bool
	WillFlag        bool
	WillQoS         byte
	WillRetain      bool
	UsernameFlag    bool
	PasswordFlag    bool
	// TODO as protocol saying:
	// > The Server MUST validate that the reserved flag in the CONNECT Control Packet is set to zero and
	// > disconnect the Client if it is not zero
	// so if we need to handle the reservedbit?
	ReservedBit byte
	Keepalive   uint16

	ClientIdentifier string
	WillTopic        string
	WillMessage      []byte
	Username         string
	Password         []byte
	TraceID          string
}

ConnectPacket is an internal representation of the fields of the Connect MQTT packet

func NewConnectPacket

func NewConnectPacket() *ConnectPacket

NewConnectPacket return the connect packet

func (*ConnectPacket) Close

func (c *ConnectPacket) Close()

Close reset the packet field put the control packet back to pool

func (*ConnectPacket) Details

func (c *ConnectPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*ConnectPacket) Reset

func (c *ConnectPacket) Reset()

Reset will initialize the fields in control packet

func (*ConnectPacket) SetFixedHeader

func (c *ConnectPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*ConnectPacket) SetTraceID

func (c *ConnectPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*ConnectPacket) String

func (c *ConnectPacket) String() string

String export the packet of connect info

func (*ConnectPacket) Type

func (c *ConnectPacket) Type() byte

Type return the packet type

func (*ConnectPacket) Unpack

func (c *ConnectPacket) Unpack(b []byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*ConnectPacket) Validate

func (c *ConnectPacket) Validate() byte

Validate performs validation of the fields of a Connect packet

func (*ConnectPacket) Verify

func (c *ConnectPacket) Verify() bool

Verify packet availability

func (*ConnectPacket) Write

func (c *ConnectPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type ControlPacket

type ControlPacket interface {
	// SetFixedHeader will set fh for our header
	SetFixedHeader(*FixedHeader)
	// SetTraceID set the traceable label into packets. whild the packet was delievering.
	SetTraceID(id string)
	// Verify will check the package if validate
	Verify() bool
	// Type return the packet type
	Type() byte
	// Write the packet into Writer
	Write(io.Writer) (int, error)
	// Unpack the given byte and fill in the control packet object fields
	Unpack([]byte) error
	// Reset will initialize the fields in control packet
	Reset()
	// Close reset the packet field put the control packet back to pool
	Close()
	// Details return packet QoS and MessageID
	Details() Details

	// String export the packet of connack info
	String() string
}

ControlPacket defines the interface for structs intended to hold decoded MQTT packets, either from being read or before being written

func NewControlPacket

func NewControlPacket(packetType byte) (cp ControlPacket)

NewControlPacket is used to create a new ControlPacket of the type specified by packetType, this is usually done by reference to the packet type constants defined in packets.go. The newly created ControlPacket is empty and a pointer is returned.

func NewControlPacketWithHeader

func NewControlPacketWithHeader(fh *FixedHeader) (cp ControlPacket)

NewControlPacketWithHeader is used to create a new ControlPacket of the type specified within the FixedHeader that is passed to the function. The newly created ControlPacket is empty and a pointer is returned.

func ReadPacket

func ReadPacket(r io.Reader) (cp ControlPacket, length int, err error)

ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts to read an MQTT packet from the stream. It returns a ControlPacket representing the decoded MQTT packet and an error. One of these returns will always be nil, a nil ControlPacket indicating an error occurred. [0][1] [2 3 4] ... [m+1] ... [n]

--- fh --- | vh |  datagram  |

func ReadPacketLimitSize

func ReadPacketLimitSize(r io.Reader, s int) (cp ControlPacket, length int, err error)

ReadPacketLimitSize read a packet with a maximum size of s from net.Conn

type Details

type Details struct {
	QoS       byte
	MessageID uint16
}

Details struct returned by the Details() function called on ControlPackets to present details of the QoS and MessageID of the ControlPacket

type DisconnectPacket

type DisconnectPacket struct {
	*FixedHeader
	TraceID string
}

DisconnectPacket is an internal representation of the fields of the Disconnect MQTT packet

func NewDisconnectPacket

func NewDisconnectPacket() *DisconnectPacket

NewDisconnectPacket return the disconnect packet

func (*DisconnectPacket) Close

func (d *DisconnectPacket) Close()

Close reset the packet field put the control packet back to pool

func (*DisconnectPacket) Details

func (d *DisconnectPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*DisconnectPacket) Reset

func (d *DisconnectPacket) Reset()

Reset will initialize the fields in control packet

func (*DisconnectPacket) SetFixedHeader

func (d *DisconnectPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*DisconnectPacket) SetTraceID

func (d *DisconnectPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*DisconnectPacket) String

func (d *DisconnectPacket) String() string

String export the packet of disconnect info

func (*DisconnectPacket) Type

func (d *DisconnectPacket) Type() byte

Type return the packet type

func (*DisconnectPacket) Unpack

func (d *DisconnectPacket) Unpack([]byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*DisconnectPacket) Verify

func (d *DisconnectPacket) Verify() bool

Verify packet availability

func (*DisconnectPacket) Write

func (d *DisconnectPacket) Write(w io.Writer) (int, error)

Write will write the packets mostly into a net.Conn

type FixedHeader

type FixedHeader struct {
	MessageType     byte
	Dup             bool
	QoS             byte
	Retain          bool
	RemainingLength int
}

FixedHeader is a struct to hold the decoded information from the fixed header of an MQTT ControlPacket

|  7  6  5  4 |  3  |  2   1  |  0   |
| MessageType | Dup |   QoS   |Retain|
| byte        | bool|  byte   | bool |

FixedHeader only contains 5 bytes at most. And it can align to memory boundary based on 64bit system and hardware

| MsgType | dup | qos | retain |
|        remain length         |
|           ... ...            |
|           ... ...            |
|           ... ...            |
|    ---    4 bytes     ---    |

FixedHeader memory layout
|    MsgType    |-----
|      dup      |    |
|      qos      |    |
|    retain     | 8 bytes
| remain length0|    |
| remain length1|    |
| remain length2|    |
| remain length3|-----

func (*FixedHeader) String

func (fh *FixedHeader) String() string

type PingreqPacket

type PingreqPacket struct {
	*FixedHeader
}

PingreqPacket is an internal representation of the fields of the Pingreq MQTT packet

func NewPingreqPacket

func NewPingreqPacket() *PingreqPacket

NewPingreqPacket return the ping request packet

func (*PingreqPacket) Close

func (pr *PingreqPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PingreqPacket) Details

func (pr *PingreqPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PingreqPacket) Reset

func (pr *PingreqPacket) Reset()

Reset will initialize the fields in control packet

func (*PingreqPacket) SetFixedHeader

func (pr *PingreqPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PingreqPacket) SetTraceID

func (pr *PingreqPacket) SetTraceID(string)

SetTraceID will set traceid for tracing

func (*PingreqPacket) String

func (pr *PingreqPacket) String() string

String export the packet of ping information

func (*PingreqPacket) Type

func (pr *PingreqPacket) Type() byte

Type return the packet type

func (*PingreqPacket) Unpack

func (pr *PingreqPacket) Unpack([]byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PingreqPacket) Verify

func (pr *PingreqPacket) Verify() bool

Verify packet availability

func (*PingreqPacket) Write

func (pr *PingreqPacket) Write(w io.Writer) (int, error)

Write will write the packets mostly into a net.Conn

type PingrespPacket

type PingrespPacket struct {
	*FixedHeader
}

PingrespPacket is an internal representation of the fields of the Pingresp MQTT packet

func NewPingrespPacket

func NewPingrespPacket() *PingrespPacket

NewPingrespPacket return the ping response packet

func (*PingrespPacket) Close

func (pr *PingrespPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PingrespPacket) Details

func (pr *PingrespPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PingrespPacket) Reset

func (pr *PingrespPacket) Reset()

Reset will initialize the fields in control packet

func (*PingrespPacket) SetFixedHeader

func (pr *PingrespPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PingrespPacket) SetTraceID

func (pr *PingrespPacket) SetTraceID(string)

SetTraceID will set traceid for tracing

func (*PingrespPacket) String

func (pr *PingrespPacket) String() string

String export the packet of connack info

func (*PingrespPacket) Type

func (pr *PingrespPacket) Type() byte

Type return the packet type

func (*PingrespPacket) Unpack

func (pr *PingrespPacket) Unpack([]byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PingrespPacket) Verify

func (pr *PingrespPacket) Verify() bool

Verify packet availability

func (*PingrespPacket) Write

func (pr *PingrespPacket) Write(w io.Writer) (int, error)

Write will write the packets mostly into a net.Conn

type PubackPacket

type PubackPacket struct {
	*FixedHeader
	MessageID uint16
	TraceID   string
}

PubackPacket is an internal representation of the fields of the Puback MQTT packet

func NewPubackPacket

func NewPubackPacket() *PubackPacket

NewPubackPacket return the puback packet

func (*PubackPacket) Close

func (pa *PubackPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PubackPacket) Details

func (pa *PubackPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PubackPacket) Reset

func (pa *PubackPacket) Reset()

Reset will initialize the fields in control packet

func (*PubackPacket) SetFixedHeader

func (pa *PubackPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PubackPacket) SetTraceID

func (pa *PubackPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*PubackPacket) String

func (pa *PubackPacket) String() string

String export the packet of connack info

func (*PubackPacket) Type

func (pa *PubackPacket) Type() byte

Type return the packet type

func (*PubackPacket) Unpack

func (pa *PubackPacket) Unpack(b []byte) (err error)

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PubackPacket) Verify

func (pa *PubackPacket) Verify() bool

Verify packet availability

func (*PubackPacket) Write

func (pa *PubackPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type PubcompPacket

type PubcompPacket struct {
	*FixedHeader
	MessageID uint16
	TraceID   string
}

PubcompPacket is an internal representation of the fields of the Pubcomp MQTT packet

func NewPubcompPacket

func NewPubcompPacket() *PubcompPacket

NewPubcompPacket return the ping request packet

func (*PubcompPacket) Close

func (pc *PubcompPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PubcompPacket) Details

func (pc *PubcompPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PubcompPacket) Reset

func (pc *PubcompPacket) Reset()

Reset will initialize the fields in control packet

func (*PubcompPacket) SetFixedHeader

func (pc *PubcompPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PubcompPacket) SetTraceID

func (pc *PubcompPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*PubcompPacket) String

func (pc *PubcompPacket) String() string

String export the packet of connack info

func (*PubcompPacket) Type

func (pc *PubcompPacket) Type() byte

Type return the packet type

func (*PubcompPacket) Unpack

func (pc *PubcompPacket) Unpack(b []byte) (err error)

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PubcompPacket) Verify

func (pc *PubcompPacket) Verify() bool

Verify packet availability

func (*PubcompPacket) Write

func (pc *PubcompPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type PublishPacket

type PublishPacket struct {
	*FixedHeader
	TopicName string
	MessageID uint16
	Payload   []byte
	TraceID   string
}

PublishPacket is an internal representation of the fields of the Publish MQTT packet

func NewPublishPacket

func NewPublishPacket() *PublishPacket

NewPublishPacket return the ping request packet

func (*PublishPacket) Close

func (p *PublishPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PublishPacket) Copy

func (p *PublishPacket) Copy() *PublishPacket

Copy creates a new PublishPacket with the same topic and payload but an empty fixed header, useful for when you want to deliver a message with different properties such as QoS but the same content XXX need to check if put back a packet will cause noting wrong

func (*PublishPacket) Details

func (p *PublishPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PublishPacket) Reset

func (p *PublishPacket) Reset()

Reset will initialize the fields in control packet

func (*PublishPacket) SetFixedHeader

func (p *PublishPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PublishPacket) SetTraceID

func (p *PublishPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*PublishPacket) String

func (p *PublishPacket) String() string

String export the packet of publish information

func (*PublishPacket) Type

func (p *PublishPacket) Type() byte

Type return the packet type

func (*PublishPacket) Unpack

func (p *PublishPacket) Unpack(b []byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PublishPacket) Verify

func (p *PublishPacket) Verify() bool

Verify packet availability

func (*PublishPacket) Write

func (p *PublishPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type PubrecPacket

type PubrecPacket struct {
	*FixedHeader
	MessageID uint16
	TraceID   string
}

PubrecPacket is an internal representation of the fields of the Pubrec MQTT packet

func NewPubrecPacket

func NewPubrecPacket() *PubrecPacket

NewPubrecPacket return the ping request packet

func (*PubrecPacket) Close

func (pr *PubrecPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PubrecPacket) Details

func (pr *PubrecPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PubrecPacket) Reset

func (pr *PubrecPacket) Reset()

Reset will initialize the fields in control packet

func (*PubrecPacket) SetFixedHeader

func (pr *PubrecPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PubrecPacket) SetTraceID

func (pr *PubrecPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*PubrecPacket) String

func (pr *PubrecPacket) String() string

String export the packet of pubrec information

func (*PubrecPacket) Type

func (pr *PubrecPacket) Type() byte

Type return the packet type

func (*PubrecPacket) Unpack

func (pr *PubrecPacket) Unpack(b []byte) (err error)

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PubrecPacket) Verify

func (pr *PubrecPacket) Verify() bool

Verify packet availability

func (*PubrecPacket) Write

func (pr *PubrecPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type PubrelPacket

type PubrelPacket struct {
	*FixedHeader
	MessageID uint16
	TraceID   string
}

PubrelPacket is an internal representation of the fields of the Pubrel MQTT packet

func NewPubrelPacket

func NewPubrelPacket() *PubrelPacket

NewPubrelPacket return the ping request packet

func (*PubrelPacket) Close

func (pr *PubrelPacket) Close()

Close reset the packet field put the control packet back to pool

func (*PubrelPacket) Details

func (pr *PubrelPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*PubrelPacket) Reset

func (pr *PubrelPacket) Reset()

Reset will initialize the fields in control packet

func (*PubrelPacket) SetFixedHeader

func (pr *PubrelPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*PubrelPacket) SetTraceID

func (pr *PubrelPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*PubrelPacket) String

func (pr *PubrelPacket) String() string

String export the packet of pubrel information

func (*PubrelPacket) Type

func (pr *PubrelPacket) Type() byte

Type return the packet type

func (*PubrelPacket) Unpack

func (pr *PubrelPacket) Unpack(b []byte) (err error)

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*PubrelPacket) Verify

func (pr *PubrelPacket) Verify() bool

Verify packet availability

func (*PubrelPacket) Write

func (pr *PubrelPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type SubackPacket

type SubackPacket struct {
	*FixedHeader
	MessageID   uint16
	ReturnCodes []byte
	TraceID     string
}

SubackPacket is an internal representation of the fields of the Suback MQTT packet

func NewSubackPacket

func NewSubackPacket() *SubackPacket

NewSubackPacket return the ping request packet

func (*SubackPacket) Close

func (sa *SubackPacket) Close()

Close reset the packet field put the control packet back to pool

func (*SubackPacket) Details

func (sa *SubackPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*SubackPacket) Reset

func (sa *SubackPacket) Reset()

Reset will initialize the fields in control packet

func (*SubackPacket) SetFixedHeader

func (sa *SubackPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*SubackPacket) SetTraceID

func (sa *SubackPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*SubackPacket) String

func (sa *SubackPacket) String() string

func (*SubackPacket) Type

func (sa *SubackPacket) Type() byte

Type return the packet type

func (*SubackPacket) Unpack

func (sa *SubackPacket) Unpack(b []byte) (err error)

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*SubackPacket) Verify

func (sa *SubackPacket) Verify() bool

Verify packet availability

func (*SubackPacket) Write

func (sa *SubackPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type SubscribePacket

type SubscribePacket struct {
	*FixedHeader
	MessageID uint16
	Topics    []string
	QoSs      []byte
	TraceID   string
}

SubscribePacket is an internal representation of the fields of the Subscribe MQTT packet

func NewSubscribePacket

func NewSubscribePacket() *SubscribePacket

NewSubscribePacket return the ping request packet

func (*SubscribePacket) Close

func (s *SubscribePacket) Close()

Close reset the packet field put the control packet back to pool

func (*SubscribePacket) Details

func (s *SubscribePacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*SubscribePacket) Reset

func (s *SubscribePacket) Reset()

Reset will initialize the fields in control packet

func (*SubscribePacket) SetFixedHeader

func (s *SubscribePacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*SubscribePacket) SetTraceID

func (s *SubscribePacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*SubscribePacket) String

func (s *SubscribePacket) String() string

String export the packet of connack information

func (*SubscribePacket) Type

func (s *SubscribePacket) Type() byte

Type return the packet type

func (*SubscribePacket) Unpack

func (s *SubscribePacket) Unpack(b []byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*SubscribePacket) Verify

func (s *SubscribePacket) Verify() bool

Verify packet availability

func (*SubscribePacket) Write

func (s *SubscribePacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type UnsubackPacket

type UnsubackPacket struct {
	*FixedHeader
	MessageID uint16
	TraceID   string
}

UnsubackPacket is an internal representation of the fields of the Unsuback MQTT packet

func NewUnsubackPacket

func NewUnsubackPacket() *UnsubackPacket

NewUnsubackPacket return the ping request packet

func (*UnsubackPacket) Close

func (ua *UnsubackPacket) Close()

Close reset the packet field put the control packet back to pool

func (*UnsubackPacket) Details

func (ua *UnsubackPacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*UnsubackPacket) Reset

func (ua *UnsubackPacket) Reset()

Reset will initialize the fields in control packet

func (*UnsubackPacket) SetFixedHeader

func (ua *UnsubackPacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*UnsubackPacket) SetTraceID

func (ua *UnsubackPacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*UnsubackPacket) String

func (ua *UnsubackPacket) String() string

String export the packet of unsuback information

func (*UnsubackPacket) Type

func (ua *UnsubackPacket) Type() byte

Type return the packet type

func (*UnsubackPacket) Unpack

func (ua *UnsubackPacket) Unpack(b []byte) (err error)

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*UnsubackPacket) Verify

func (ua *UnsubackPacket) Verify() bool

Verify packet availability

func (*UnsubackPacket) Write

func (ua *UnsubackPacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

type UnsubscribePacket

type UnsubscribePacket struct {
	*FixedHeader
	MessageID uint16
	Topics    []string
	TraceID   string
}

UnsubscribePacket is an internal representation of the fields of the Unsubscribe MQTT packet

func NewUnsubscribePacket

func NewUnsubscribePacket() *UnsubscribePacket

NewUnsubscribePacket return the ping request packet

func (*UnsubscribePacket) Close

func (u *UnsubscribePacket) Close()

Close reset the packet field put the control packet back to pool

func (*UnsubscribePacket) Details

func (u *UnsubscribePacket) Details() Details

Details returns a Details struct containing the QoS and MessageID of this ControlPacket

func (*UnsubscribePacket) Reset

func (u *UnsubscribePacket) Reset()

Reset will initialize the fields in control packet

func (*UnsubscribePacket) SetFixedHeader

func (u *UnsubscribePacket) SetFixedHeader(fh *FixedHeader)

SetFixedHeader will set fh for our header

func (*UnsubscribePacket) SetTraceID

func (u *UnsubscribePacket) SetTraceID(id string)

SetTraceID will set traceid for tracing

func (*UnsubscribePacket) String

func (u *UnsubscribePacket) String() string

String export the packet of unsubscribe information

func (*UnsubscribePacket) Type

func (u *UnsubscribePacket) Type() byte

Type return the packet type

func (*UnsubscribePacket) Unpack

func (u *UnsubscribePacket) Unpack(b []byte) error

Unpack decodes the details of a ControlPacket after the fixed header has been read

func (*UnsubscribePacket) Verify

func (u *UnsubscribePacket) Verify() bool

Verify packet availability

func (*UnsubscribePacket) Write

func (u *UnsubscribePacket) Write(w io.Writer) (n int, err error)

Write will write the packets mostly into a net.Conn

Jump to

Keyboard shortcuts

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