packets

package
v0.0.0-...-5f0d520 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONNECT = iota + 1
	CONNACK
	PUBLISH
	PUBACK
	PUBREC
	PUBREL
	PUBCOMP
	SUBSCRIBE
	SUBACK
	UNSUBSCRIBE
	UNSUBACK
	PINGREQ
	PINGRESP
	DISCONNECT
	AUTH
)

Packet type

View Source
const (
	V31 = iota + 3
	V311
	V5
)

MQTT Version

View Source
const (
	Qos0 byte = iota
	Qos1
	Qos2
)

MQTT Qos

View Source
const (
	Accepted                     = 0x00
	RefusedBadProtocolVersion    = 0x01
	RefusedIDRejected            = 0x02
	RefusedServerUnavailable     = 0x03
	RefusedBadUsernameOrPassword = 0x04
	RefusedNotAuthorised         = 0x05
	Failure                      = 0x80
)

V3 reason code

View Source
const (
	Success                     = 0x00
	NormalDisconnection         = 0x00
	GrantedQoS0                 = 0x00
	GrantedQoS1                 = 0x01
	GrantedQoS2                 = 0x02
	DisconnectWithWillMessage   = 0x04
	NotMatchingSubscribers      = 0x10
	NoSubscriptionExisted       = 0x11
	ContinueAuthentication      = 0x18
	ReAuthenticate              = 0x19
	UnspecifiedError            = 0x80
	MalformedPacket             = 0x81
	ProtocolError               = 0x82
	ImplementationSpecificError = 0x83
	UnsupportedProtocolVersion  = 0x84
	ClientIdentifierNotValid    = 0x85
	BadUserNameOrPassword       = 0x86
	NotAuthorized               = 0x87
	ServerUnavailable           = 0x88
	ServerBusy                  = 0x89
	Banned                      = 0x8A
	BadAuthMethod               = 0x8C
	KeepAliveTimeout            = 0x8D
	SessionTakenOver            = 0x8E
	TopicFilterInvalid          = 0x8F
	TopicNameInvalid            = 0x90
	PacketIDInUse               = 0x91
	PacketIDNotFound            = 0x92
	RecvMaxExceeded             = 0x93
	TopicAliasInvalid           = 0x94
	PacketTooLarge              = 0x95
	MessageRateTooHigh          = 0x96
	QuotaExceeded               = 0x97
	AdminAction                 = 0x98
	PayloadFormatInvalid        = 0x99
	RetainNotSupported          = 0x9A
	QoSNotSupported             = 0x9B
	UseAnotherServer            = 0x9C
	ServerMoved                 = 0x9D
	SharedSubNotSupported       = 0x9E
	ConnectionRateExceeded      = 0x9F
	MaxConnectTime              = 0xA0
	SubIDNotSupported           = 0xA1
	WildcardSubNotSupported     = 0xA2
)

V5 reason code

View Source
const (
	PayloadFormat          = 0x01
	MessageExpiry          = 0x02
	ContentType            = 0x03
	ResponseTopic          = 0x08
	CorrelationData        = 0x09
	SubscriptionIdentifier = 0x0B
	SessionExpiryInterval  = 0x11
	AssignedClientID       = 0x12
	ServerKeepAlive        = 0x13
	AuthMethod             = 0x15
	AuthData               = 0x16
	RequestProblemInfo     = 0x17
	WillDelayInterval      = 0x18
	RequestResponseInfo    = 0x19
	ResponseInfo           = 0x1A
	ServerReference        = 0x1C
	ReasonString           = 0x1F
	ReceiveMaximum         = 0x21
	TopicAliasMaximum      = 0x22
	TopicAlias             = 0x23
	MaximumQoS             = 0x24
	RetainAvailable        = 0x25
	User                   = 0x26
	MaximumPacketSize      = 0x27
	WildcardSubAvailable   = 0x28
	SubIDAvailable         = 0x29
	SharedSubAvailable     = 0x2A
)

Properties

Variables

View Source
var (
	ErrMalformed = &Error{Code: MalformedPacket}
	ErrProtocol  = &Error{Code: ProtocolError}
)

Functions

func Code

func Code(v, c byte) byte

Types

type Auth

type Auth struct {
	FixHeader  *FixHeader
	ReasonCode byte
	Properties *Properties
}

func (*Auth) Pack

func (a *Auth) Pack(w io.Writer) error

Pack Auth Packet

func (*Auth) Unpack

func (a *Auth) Unpack(r io.Reader) error

Unpack Auth Packet

type Connack

type Connack struct {
	FixHeader      *FixHeader
	Version        byte
	SessionPresent bool
	ReasonCode     byte
	Properties     *Properties
}

Connack Packet

func (*Connack) Pack

func (c *Connack) Pack(w io.Writer) error

Pack Connack Packet

func (*Connack) Unpack

func (c *Connack) Unpack(r io.Reader) error

Unpack Connack Packet

type Connect

type Connect struct {
	FixHeader *FixHeader
	// Variable Header
	Protocol string
	Version  byte
	// Connect Flags
	UsernameFlag bool
	PasswordFlag bool
	WillRetain   bool
	WillQos      byte
	WillFlag     bool
	CleanStart   bool
	Reserved     bool
	KeepAlive    uint16
	Properties   *Properties
	// Payload
	ClientID       string
	WillProperties *Properties
	WillTopic      string
	WillMsg        string
	Username       string
	Password       string
}

Connect Packet

func (*Connect) Pack

func (c *Connect) Pack(w io.Writer) error

Pack Connect Packet

func (*Connect) Unpack

func (c *Connect) Unpack(r io.Reader) error

Unpack Connect Packet

type Disconnect

type Disconnect struct {
	FixHeader  *FixHeader
	Version    byte
	ReasonCode byte
	Properties *Properties
}

Disconnect Packet

func (*Disconnect) Pack

func (c *Disconnect) Pack(w io.Writer) error

Pack Disconnect Packet

func (*Disconnect) Unpack

func (c *Disconnect) Unpack(r io.Reader) error

Unpack Disconnect Packet

type Error

type Error struct {
	Code   byte
	Reason string
}

func (*Error) Error

func (e *Error) Error() string

type FixHeader

type FixHeader struct {
	PacketType byte
	Flags      byte
	Dup        bool
	Qos        byte
	Retain     bool
	RemainLen  int
}

FixHeader Struct

func (*FixHeader) Pack

func (fh *FixHeader) Pack(w io.Writer) error

Pack Fix Header

func (*FixHeader) Unpack

func (fh *FixHeader) Unpack(r io.Reader) error

Unpack Fix Header

type Packet

type Packet interface {
	Pack(w io.Writer) error
	Unpack(r io.Reader) error
}

Packet interface

func NewPacket

func NewPacket(fh *FixHeader, v byte) Packet

type Pingreq

type Pingreq struct {
	FixHeader *FixHeader
}

Pingreq packet

func (*Pingreq) Pack

func (c *Pingreq) Pack(w io.Writer) error

Pack Pingreq Packet

func (*Pingreq) Unpack

func (c *Pingreq) Unpack(r io.Reader) error

Unpack Pingreq Packet

type Pingresp

type Pingresp struct {
	FixHeader *FixHeader
}

Pingresp packet

func (*Pingresp) Pack

func (c *Pingresp) Pack(w io.Writer) error

Pack Pingresp Packet

func (*Pingresp) Unpack

func (c *Pingresp) Unpack(r io.Reader) error

Unpack Pingresp Packet

type Properties

type Properties struct {
	PayloadFormat          *byte
	MessageExpiry          *uint32
	ContentType            string
	ResponseTopic          string
	CorrelationData        string
	SubscriptionIdentifier []uint32
	SessionExpiryInterval  *uint32
	AssignedClientID       string
	ServerKeepAlive        *uint16
	AuthMethod             string
	AuthData               string
	RequestProblemInfo     *byte
	WillDelayInterval      *uint32
	RequestResponseInfo    *byte
	ResponseInfo           string
	ServerReference        string
	ReasonString           string
	ReceiveMaximum         *uint16
	TopicAliasMaximum      *uint16
	TopicAlias             *uint16
	MaximumQoS             *byte
	RetainAvailable        *byte
	User                   map[string]string
	MaximumPacketSize      *uint32
	WildcardSubAvailable   *byte
	SubIDAvailable         *byte
	SharedSubAvailable     *byte
}

func (*Properties) Pack

func (p *Properties) Pack(w *bytes.Buffer) error

Pack Connect Packet

func (*Properties) Unpack

func (p *Properties) Unpack(r *bytes.Buffer) error

Unpack Properties

type Puback

type Puback struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	ReasonCode byte
	Properties *Properties
}

Puback Packet

func (*Puback) Pack

func (p *Puback) Pack(w io.Writer) error

Pack Puback Packet

func (*Puback) Unpack

func (p *Puback) Unpack(r io.Reader) error

Unpack Puback Packet

type Pubcomp

type Pubcomp struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	ReasonCode byte
	Properties *Properties
}

Pubcomp Packet

func (*Pubcomp) Pack

func (p *Pubcomp) Pack(w io.Writer) error

Pack Pubcomp Packet

func (*Pubcomp) Unpack

func (p *Pubcomp) Unpack(r io.Reader) error

Unpack Pubcomp Packet

type Publish

type Publish struct {
	FixHeader  *FixHeader
	Version    byte
	TopicName  string
	PacketID   uint16
	Properties *Properties
	Payload    []byte
}

func (*Publish) Pack

func (p *Publish) Pack(w io.Writer) error

Pack Publish Packet

func (*Publish) Unpack

func (p *Publish) Unpack(r io.Reader) error

Unpack Publish Packet

type Pubrec

type Pubrec struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	ReasonCode byte
	Properties *Properties
}

Pubrec Packet

func (*Pubrec) Pack

func (p *Pubrec) Pack(w io.Writer) error

Pack Pubrec Packet

func (*Pubrec) Unpack

func (p *Pubrec) Unpack(r io.Reader) error

Unpack Pubrec Packet

type Pubrel

type Pubrel struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	ReasonCode byte
	Properties *Properties
}

Pubrel Packet

func (*Pubrel) Pack

func (p *Pubrel) Pack(w io.Writer) error

Pack Pubrel Packet

func (*Pubrel) Unpack

func (p *Pubrel) Unpack(r io.Reader) error

Unpack Pubrel Packet

type Suback

type Suback struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	Properties *Properties
	Payload    []byte
}

Suback Packet

func (*Suback) Pack

func (s *Suback) Pack(w io.Writer) error

Pack Suback Packet

func (*Suback) Unpack

func (s *Suback) Unpack(r io.Reader) error

Unpack Suback Packet

type Subscribe

type Subscribe struct {
	FixHeader     *FixHeader
	Version       byte
	PacketID      uint16
	Subscriptions []Subscription
	Properties    *Properties
}

func (*Subscribe) Pack

func (s *Subscribe) Pack(w io.Writer) error

Pack Subscribe Packet

func (*Subscribe) Unpack

func (s *Subscribe) Unpack(r io.Reader) error

Unpack Subscribe Packet

type Subscription

type Subscription struct {
	Topic             string
	ShareName         string
	RetainHandling    byte
	RetainAsPublished bool
	NoLocal           bool
	Qos               byte
	SubID             uint32
}

type Unsuback

type Unsuback struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	Properties *Properties
	Payload    []byte
}

Unsuback Packet

func (*Unsuback) Pack

func (u *Unsuback) Pack(w io.Writer) error

Pack Unsuback Packet

func (*Unsuback) Unpack

func (u *Unsuback) Unpack(r io.Reader) error

Unpack Unsuback Packet

type Unsubscribe

type Unsubscribe struct {
	FixHeader  *FixHeader
	Version    byte
	PacketID   uint16
	Topics     []string
	Properties *Properties
}

func (*Unsubscribe) Pack

func (u *Unsubscribe) Pack(w io.Writer) error

Pack Unsubscribe Packet

func (*Unsubscribe) Unpack

func (u *Unsubscribe) Unpack(r io.Reader) error

Unpack Unsubscribe Packet

Jump to

Keyboard shortcuts

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