Documentation ¶
Index ¶
- Constants
- Variables
- func Getbuf() (b *leakBuffer)
- func NewBufferPool(bufSize int)
- func Putbuf(b *leakBuffer)
- func WritePacket(w io.Writer, p ControlPacket) (int, error)
- type ConnackPacket
- func (ca *ConnackPacket) Close()
- func (ca *ConnackPacket) Details() Details
- func (ca *ConnackPacket) Reset()
- func (ca *ConnackPacket) SetFixedHeader(fh *FixedHeader)
- func (ca *ConnackPacket) SetTraceID(id string)
- func (ca *ConnackPacket) String() string
- func (ca *ConnackPacket) Type() byte
- func (ca *ConnackPacket) Unpack(b []byte) error
- func (ca *ConnackPacket) Verify() bool
- func (ca *ConnackPacket) Write(w io.Writer) (length int, err error)
- type ConnectPacket
- func (c *ConnectPacket) Close()
- func (c *ConnectPacket) Details() Details
- func (c *ConnectPacket) Reset()
- func (c *ConnectPacket) SetFixedHeader(fh *FixedHeader)
- func (c *ConnectPacket) SetTraceID(id string)
- func (c *ConnectPacket) String() string
- func (c *ConnectPacket) Type() byte
- func (c *ConnectPacket) Unpack(b []byte) error
- func (c *ConnectPacket) Validate() byte
- func (c *ConnectPacket) Verify() bool
- func (c *ConnectPacket) Write(w io.Writer) (n int, err error)
- type ControlPacket
- type Details
- type DisconnectPacket
- func (d *DisconnectPacket) Close()
- func (d *DisconnectPacket) Details() Details
- func (d *DisconnectPacket) Reset()
- func (d *DisconnectPacket) SetFixedHeader(fh *FixedHeader)
- func (d *DisconnectPacket) SetTraceID(id string)
- func (d *DisconnectPacket) String() string
- func (d *DisconnectPacket) Type() byte
- func (d *DisconnectPacket) Unpack([]byte) error
- func (d *DisconnectPacket) Verify() bool
- func (d *DisconnectPacket) Write(w io.Writer) (int, error)
- type FixedHeader
- type PingreqPacket
- func (pr *PingreqPacket) Close()
- func (pr *PingreqPacket) Details() Details
- func (pr *PingreqPacket) Reset()
- func (pr *PingreqPacket) SetFixedHeader(fh *FixedHeader)
- func (pr *PingreqPacket) SetTraceID(string)
- func (pr *PingreqPacket) String() string
- func (pr *PingreqPacket) Type() byte
- func (pr *PingreqPacket) Unpack([]byte) error
- func (pr *PingreqPacket) Verify() bool
- func (pr *PingreqPacket) Write(w io.Writer) (int, error)
- type PingrespPacket
- func (pr *PingrespPacket) Close()
- func (pr *PingrespPacket) Details() Details
- func (pr *PingrespPacket) Reset()
- func (pr *PingrespPacket) SetFixedHeader(fh *FixedHeader)
- func (pr *PingrespPacket) SetTraceID(string)
- func (pr *PingrespPacket) String() string
- func (pr *PingrespPacket) Type() byte
- func (pr *PingrespPacket) Unpack([]byte) error
- func (pr *PingrespPacket) Verify() bool
- func (pr *PingrespPacket) Write(w io.Writer) (int, error)
- type PubackPacket
- func (pa *PubackPacket) Close()
- func (pa *PubackPacket) Details() Details
- func (pa *PubackPacket) Reset()
- func (pa *PubackPacket) SetFixedHeader(fh *FixedHeader)
- func (pa *PubackPacket) SetTraceID(id string)
- func (pa *PubackPacket) String() string
- func (pa *PubackPacket) Type() byte
- func (pa *PubackPacket) Unpack(b []byte) (err error)
- func (pa *PubackPacket) Verify() bool
- func (pa *PubackPacket) Write(w io.Writer) (n int, err error)
- type PubcompPacket
- func (pc *PubcompPacket) Close()
- func (pc *PubcompPacket) Details() Details
- func (pc *PubcompPacket) Reset()
- func (pc *PubcompPacket) SetFixedHeader(fh *FixedHeader)
- func (pc *PubcompPacket) SetTraceID(id string)
- func (pc *PubcompPacket) String() string
- func (pc *PubcompPacket) Type() byte
- func (pc *PubcompPacket) Unpack(b []byte) (err error)
- func (pc *PubcompPacket) Verify() bool
- func (pc *PubcompPacket) Write(w io.Writer) (n int, err error)
- type PublishPacket
- func (p *PublishPacket) Close()
- func (p *PublishPacket) Copy() *PublishPacket
- func (p *PublishPacket) Details() Details
- func (p *PublishPacket) Reset()
- func (p *PublishPacket) SetFixedHeader(fh *FixedHeader)
- func (p *PublishPacket) SetTraceID(id string)
- func (p *PublishPacket) String() string
- func (p *PublishPacket) Type() byte
- func (p *PublishPacket) Unpack(b []byte) error
- func (p *PublishPacket) Verify() bool
- func (p *PublishPacket) Write(w io.Writer) (n int, err error)
- type PubrecPacket
- func (pr *PubrecPacket) Close()
- func (pr *PubrecPacket) Details() Details
- func (pr *PubrecPacket) Reset()
- func (pr *PubrecPacket) SetFixedHeader(fh *FixedHeader)
- func (pr *PubrecPacket) SetTraceID(id string)
- func (pr *PubrecPacket) String() string
- func (pr *PubrecPacket) Type() byte
- func (pr *PubrecPacket) Unpack(b []byte) (err error)
- func (pr *PubrecPacket) Verify() bool
- func (pr *PubrecPacket) Write(w io.Writer) (n int, err error)
- type PubrelPacket
- func (pr *PubrelPacket) Close()
- func (pr *PubrelPacket) Details() Details
- func (pr *PubrelPacket) Reset()
- func (pr *PubrelPacket) SetFixedHeader(fh *FixedHeader)
- func (pr *PubrelPacket) SetTraceID(id string)
- func (pr *PubrelPacket) String() string
- func (pr *PubrelPacket) Type() byte
- func (pr *PubrelPacket) Unpack(b []byte) (err error)
- func (pr *PubrelPacket) Verify() bool
- func (pr *PubrelPacket) Write(w io.Writer) (n int, err error)
- type SubackPacket
- func (sa *SubackPacket) Close()
- func (sa *SubackPacket) Details() Details
- func (sa *SubackPacket) Reset()
- func (sa *SubackPacket) SetFixedHeader(fh *FixedHeader)
- func (sa *SubackPacket) SetTraceID(id string)
- func (sa *SubackPacket) String() string
- func (sa *SubackPacket) Type() byte
- func (sa *SubackPacket) Unpack(b []byte) (err error)
- func (sa *SubackPacket) Verify() bool
- func (sa *SubackPacket) Write(w io.Writer) (n int, err error)
- type SubscribePacket
- func (s *SubscribePacket) Close()
- func (s *SubscribePacket) Details() Details
- func (s *SubscribePacket) Reset()
- func (s *SubscribePacket) SetFixedHeader(fh *FixedHeader)
- func (s *SubscribePacket) SetTraceID(id string)
- func (s *SubscribePacket) String() string
- func (s *SubscribePacket) Type() byte
- func (s *SubscribePacket) Unpack(b []byte) error
- func (s *SubscribePacket) Verify() bool
- func (s *SubscribePacket) Write(w io.Writer) (n int, err error)
- type UnsubackPacket
- func (ua *UnsubackPacket) Close()
- func (ua *UnsubackPacket) Details() Details
- func (ua *UnsubackPacket) Reset()
- func (ua *UnsubackPacket) SetFixedHeader(fh *FixedHeader)
- func (ua *UnsubackPacket) SetTraceID(id string)
- func (ua *UnsubackPacket) String() string
- func (ua *UnsubackPacket) Type() byte
- func (ua *UnsubackPacket) Unpack(b []byte) (err error)
- func (ua *UnsubackPacket) Verify() bool
- func (ua *UnsubackPacket) Write(w io.Writer) (n int, err error)
- type UnsubscribePacket
- func (u *UnsubscribePacket) Close()
- func (u *UnsubscribePacket) Details() Details
- func (u *UnsubscribePacket) Reset()
- func (u *UnsubscribePacket) SetFixedHeader(fh *FixedHeader)
- func (u *UnsubscribePacket) SetTraceID(id string)
- func (u *UnsubscribePacket) String() string
- func (u *UnsubscribePacket) Type() byte
- func (u *UnsubscribePacket) Unpack(b []byte) error
- func (u *UnsubscribePacket) Verify() bool
- func (u *UnsubscribePacket) Write(w io.Writer) (n int, err error)
Constants ¶
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
const ( Accepted = 0x00 ErrRefusedBadProtocolVersion = 0x01 ErrRefusedIDRejected = 0x02 ErrRefusedBadUsernameOrPassword = 0x04 ErrRefusedNotAuthorised = 0x05 ErrNetworkError = 0xFE ErrProtocolViolation = 0xFF )
Below are the const definitions for error codes returned by Connect()
const Failure = 0x80
Failure defined error codes returned by Connect()
const ( // MaxRemainingLength the max length of remain MaxRemainingLength = 268435455 // 0xFF, 0xFF, 0xFF, 0x7F )
Variables ¶
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") )
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
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
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.
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) Unpack ¶
func (ca *ConnackPacket) Unpack(b []byte) error
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) 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
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 ¶
ReadPacketLimitSize read a packet with a maximum size of s from net.Conn
type Details ¶
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) 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
type FixedHeader ¶
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) Unpack ¶
func (pr *PingreqPacket) Unpack([]byte) error
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (pr *PingrespPacket) Unpack([]byte) error
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (pa *PubackPacket) Unpack(b []byte) (err error)
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (pc *PubcompPacket) Unpack(b []byte) (err error)
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (p *PublishPacket) Unpack(b []byte) error
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (pr *PubrecPacket) Unpack(b []byte) (err error)
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (pr *PubrelPacket) Unpack(b []byte) (err error)
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (sa *SubackPacket) Unpack(b []byte) (err error)
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (s *SubscribePacket) Unpack(b []byte) error
Unpack decodes the details of a ControlPacket after the fixed header has been read
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) Unpack ¶
func (ua *UnsubackPacket) Unpack(b []byte) (err error)
Unpack decodes the details of a ControlPacket after the fixed header has been read
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