paho.mqtt.golang: github.com/eclipse/paho.mqtt.golang/packets Index | Files

package packets

import "github.com/eclipse/paho.mqtt.golang/packets"

Index

Package Files

connack.go connect.go disconnect.go packets.go pingreq.go pingresp.go puback.go pubcomp.go publish.go pubrec.go pubrel.go suback.go subscribe.go unsuback.go unsubscribe.go

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
    ErrRefusedServerUnavailable     = 0x03
    ErrRefusedBadUsernameOrPassword = 0x04
    ErrRefusedNotAuthorised         = 0x05
    ErrNetworkError                 = 0xFE
    ErrProtocolViolation            = 0xFF
)

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

Variables

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 = map[uint8]string{
    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",
}

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

type ConnackPacket Uses

type ConnackPacket struct {
    FixedHeader
    SessionPresent bool
    ReturnCode     byte
}

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

func (*ConnackPacket) Details Uses

func (ca *ConnackPacket) Details() Details

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

func (*ConnackPacket) String Uses

func (ca *ConnackPacket) String() string

func (*ConnackPacket) Unpack Uses

func (ca *ConnackPacket) Unpack(b io.Reader) error

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

func (*ConnackPacket) Write Uses

func (ca *ConnackPacket) Write(w io.Writer) error

type ConnectPacket Uses

type ConnectPacket struct {
    FixedHeader
    ProtocolName    string
    ProtocolVersion byte
    CleanSession    bool
    WillFlag        bool
    WillQos         byte
    WillRetain      bool
    UsernameFlag    bool
    PasswordFlag    bool
    ReservedBit     byte
    Keepalive       uint16

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

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

func (*ConnectPacket) Details Uses

func (c *ConnectPacket) Details() Details

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

func (*ConnectPacket) String Uses

func (c *ConnectPacket) String() string

func (*ConnectPacket) Unpack Uses

func (c *ConnectPacket) Unpack(b io.Reader) error

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

func (*ConnectPacket) Validate Uses

func (c *ConnectPacket) Validate() byte

Validate performs validation of the fields of a Connect packet

func (*ConnectPacket) Write Uses

func (c *ConnectPacket) Write(w io.Writer) error

type ControlPacket Uses

type ControlPacket interface {
    Write(io.Writer) error
    Unpack(io.Reader) error
    String() string
    Details() Details
}

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

func NewControlPacket Uses

func NewControlPacket(packetType byte) 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 Uses

func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error)

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 Uses

func ReadPacket(r io.Reader) (ControlPacket, 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.

type Details Uses

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 Uses

type DisconnectPacket struct {
    FixedHeader
}

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

func (*DisconnectPacket) Details Uses

func (d *DisconnectPacket) Details() Details

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

func (*DisconnectPacket) String Uses

func (d *DisconnectPacket) String() string

func (*DisconnectPacket) Unpack Uses

func (d *DisconnectPacket) Unpack(b io.Reader) error

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

func (*DisconnectPacket) Write Uses

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

type FixedHeader Uses

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

func (FixedHeader) String Uses

func (fh FixedHeader) String() string

type PingreqPacket Uses

type PingreqPacket struct {
    FixedHeader
}

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

func (*PingreqPacket) Details Uses

func (pr *PingreqPacket) Details() Details

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

func (*PingreqPacket) String Uses

func (pr *PingreqPacket) String() string

func (*PingreqPacket) Unpack Uses

func (pr *PingreqPacket) Unpack(b io.Reader) error

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

func (*PingreqPacket) Write Uses

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

type PingrespPacket Uses

type PingrespPacket struct {
    FixedHeader
}

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

func (*PingrespPacket) Details Uses

func (pr *PingrespPacket) Details() Details

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

func (*PingrespPacket) String Uses

func (pr *PingrespPacket) String() string

func (*PingrespPacket) Unpack Uses

func (pr *PingrespPacket) Unpack(b io.Reader) error

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

func (*PingrespPacket) Write Uses

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

type PubackPacket Uses

type PubackPacket struct {
    FixedHeader
    MessageID uint16
}

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

func (*PubackPacket) Details Uses

func (pa *PubackPacket) Details() Details

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

func (*PubackPacket) String Uses

func (pa *PubackPacket) String() string

func (*PubackPacket) Unpack Uses

func (pa *PubackPacket) Unpack(b io.Reader) error

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

func (*PubackPacket) Write Uses

func (pa *PubackPacket) Write(w io.Writer) error

type PubcompPacket Uses

type PubcompPacket struct {
    FixedHeader
    MessageID uint16
}

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

func (*PubcompPacket) Details Uses

func (pc *PubcompPacket) Details() Details

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

func (*PubcompPacket) String Uses

func (pc *PubcompPacket) String() string

func (*PubcompPacket) Unpack Uses

func (pc *PubcompPacket) Unpack(b io.Reader) error

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

func (*PubcompPacket) Write Uses

func (pc *PubcompPacket) Write(w io.Writer) error

type PublishPacket Uses

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

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

func (*PublishPacket) Copy Uses

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

func (*PublishPacket) Details Uses

func (p *PublishPacket) Details() Details

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

func (*PublishPacket) String Uses

func (p *PublishPacket) String() string

func (*PublishPacket) Unpack Uses

func (p *PublishPacket) Unpack(b io.Reader) error

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

func (*PublishPacket) Write Uses

func (p *PublishPacket) Write(w io.Writer) error

type PubrecPacket Uses

type PubrecPacket struct {
    FixedHeader
    MessageID uint16
}

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

func (*PubrecPacket) Details Uses

func (pr *PubrecPacket) Details() Details

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

func (*PubrecPacket) String Uses

func (pr *PubrecPacket) String() string

func (*PubrecPacket) Unpack Uses

func (pr *PubrecPacket) Unpack(b io.Reader) error

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

func (*PubrecPacket) Write Uses

func (pr *PubrecPacket) Write(w io.Writer) error

type PubrelPacket Uses

type PubrelPacket struct {
    FixedHeader
    MessageID uint16
}

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

func (*PubrelPacket) Details Uses

func (pr *PubrelPacket) Details() Details

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

func (*PubrelPacket) String Uses

func (pr *PubrelPacket) String() string

func (*PubrelPacket) Unpack Uses

func (pr *PubrelPacket) Unpack(b io.Reader) error

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

func (*PubrelPacket) Write Uses

func (pr *PubrelPacket) Write(w io.Writer) error

type SubackPacket Uses

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

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

func (*SubackPacket) Details Uses

func (sa *SubackPacket) Details() Details

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

func (*SubackPacket) String Uses

func (sa *SubackPacket) String() string

func (*SubackPacket) Unpack Uses

func (sa *SubackPacket) Unpack(b io.Reader) error

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

func (*SubackPacket) Write Uses

func (sa *SubackPacket) Write(w io.Writer) error

type SubscribePacket Uses

type SubscribePacket struct {
    FixedHeader
    MessageID uint16
    Topics    []string
    Qoss      []byte
}

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

func (*SubscribePacket) Details Uses

func (s *SubscribePacket) Details() Details

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

func (*SubscribePacket) String Uses

func (s *SubscribePacket) String() string

func (*SubscribePacket) Unpack Uses

func (s *SubscribePacket) Unpack(b io.Reader) error

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

func (*SubscribePacket) Write Uses

func (s *SubscribePacket) Write(w io.Writer) error

type UnsubackPacket Uses

type UnsubackPacket struct {
    FixedHeader
    MessageID uint16
}

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

func (*UnsubackPacket) Details Uses

func (ua *UnsubackPacket) Details() Details

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

func (*UnsubackPacket) String Uses

func (ua *UnsubackPacket) String() string

func (*UnsubackPacket) Unpack Uses

func (ua *UnsubackPacket) Unpack(b io.Reader) error

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

func (*UnsubackPacket) Write Uses

func (ua *UnsubackPacket) Write(w io.Writer) error

type UnsubscribePacket Uses

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

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

func (*UnsubscribePacket) Details Uses

func (u *UnsubscribePacket) Details() Details

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

func (*UnsubscribePacket) String Uses

func (u *UnsubscribePacket) String() string

func (*UnsubscribePacket) Unpack Uses

func (u *UnsubscribePacket) Unpack(b io.Reader) error

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

func (*UnsubscribePacket) Write Uses

func (u *UnsubscribePacket) Write(w io.Writer) error

Package packets imports 5 packages (graph) and is imported by 22 packages. Updated 2019-03-21. Refresh now. Tools for package owners.