packets

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Connect    = 1
	Connack    = 2
	Publish    = 3
	Puback     = 4
	Pingreq    = 5
	Pingresp   = 6
	Disconnect = 7
)
View Source
const (
	Accepted                        = 0x00
	ErrRefusedBadProtocolVersion    = 0x01
	ErrRefusedIDRejected            = 0x02
	ErrRefusedServerUnavailable     = 0x03
	ErrRefusedBadUsernameOrPassword = 0x04
	ErrRefusedNotAuthorised         = 0x05
	ErrNetworkError                 = 0xFE
	ErrProtocolViolation            = 0xFF
)

Variables

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"),
}
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 = map[uint8]string{
	1: "CONNECT",
	2: "CONNACK",
	3: "PUBLISH",
	4: "PUBACK",
	5: "PINGREQ",
	6: "PINGRESP",
	7: "DISCONNECT",
}

Functions

This section is empty.

Types

type ConnackPacket

type ConnackPacket struct {
	FixedHeader
	SessionPresent bool
	ReturnCode     byte
}

func (*ConnackPacket) Details

func (ca *ConnackPacket) Details() Details

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

func (*ConnackPacket) String

func (ca *ConnackPacket) String() string

func (*ConnackPacket) Unpack

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

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

type ConnectPacket

type ConnectPacket struct {
	FixedHeader
	ProtocolVersion byte

	CleanSession bool

	Keepalive uint16

	ClientIdentifier string
}

func (*ConnectPacket) Details

func (c *ConnectPacket) Details() Details

func (*ConnectPacket) String

func (c *ConnectPacket) String() string

func (*ConnectPacket) Unpack

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

func (*ConnectPacket) Validate

func (c *ConnectPacket) Validate() byte

func (*ConnectPacket) Write

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

type ControlPacket

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

func NewControlPacket

func NewControlPacket(packetType byte) ControlPacket

func NewControlPacketWithHeader

func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error)

func ReadPacket

func ReadPacket(r io.Reader) (ControlPacket, error)

type Details

type Details struct {
	Qos       byte
	MessageID uint16
}

type DisconnectPacket

type DisconnectPacket struct {
	FixedHeader
}

func (*DisconnectPacket) Details

func (d *DisconnectPacket) Details() Details

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

func (*DisconnectPacket) String

func (d *DisconnectPacket) String() string

func (*DisconnectPacket) Unpack

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

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

type FixedHeader

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

func (*FixedHeader) SetDup

func (f *FixedHeader) SetDup()

func (FixedHeader) String

func (fh FixedHeader) String() string

type PingreqPacket

type PingreqPacket struct {
	FixedHeader
}

func (*PingreqPacket) Details

func (pr *PingreqPacket) Details() Details

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

func (*PingreqPacket) String

func (pr *PingreqPacket) String() string

func (*PingreqPacket) Unpack

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

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

type PingrespPacket

type PingrespPacket struct {
	FixedHeader
}

func (*PingrespPacket) Details

func (pr *PingrespPacket) Details() Details

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

func (*PingrespPacket) String

func (pr *PingrespPacket) String() string

func (*PingrespPacket) Unpack

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

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

type PubackPacket

type PubackPacket struct {
	FixedHeader
	MessageID uint16
}

func (*PubackPacket) Details

func (pa *PubackPacket) Details() Details

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

func (*PubackPacket) String

func (pa *PubackPacket) String() string

func (*PubackPacket) Unpack

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

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

type PublishPacket

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

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

func (*PublishPacket) Details

func (p *PublishPacket) Details() Details

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

func (*PublishPacket) String

func (p *PublishPacket) String() string

func (*PublishPacket) Unpack

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

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

Jump to

Keyboard shortcuts

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