protocol

package
v0.0.0-...-c8a5804 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnackSuccess                    = 0x00
	ConnackUnspecifiedError           = 0x80
	ConnackMalformedPacket            = 0x81
	ConnackProtocolError              = 0x82
	ConnackImplementationError        = 0x83
	ConnackUnsupportedProtocolVersion = 0x84
	ConnackClientIdentifierNotValid   = 0x85
	ConnackBadUsernameOrPassword      = 0x86
	ConnackNotAuthorized              = 0x87
	ConnackServerUnavailable          = 0x88
	ConnackServerBusy                 = 0x89
	ConnackBanned                     = 0x8A
	ConnackBadAuthenticationMethod    = 0x8C
	ConnackTopicNameInvalid           = 0x90
	ConnackPacketToLarge              = 0x95
	ConnackQuotaExceeded              = 0x97
	ConnackPayloadFormatInvalid       = 0x99
	ConnackRetainNotSupported         = 0x9A
	ConnackQosNotSupported            = 0x9B
	ConnackUseAnotherServer           = 0x9C
	ConnackServerMoved                = 0x9D
	ConnackConnectionRateExceeded     = 0x9F
)
View Source
const (
	FlagCleanStart   = 0x02
	FlagWillFlag     = 0x04
	FlagWillRetain   = 0x20
	FlagPassword     = 0x40
	FlagUsername     = 0x80
	FlagWillQoSShift = 3
)
View Source
const (
	DisconnectNormalDisconnection                 = 0x00
	DisconnectDisconnectWithWillMessage           = 0x04
	DisconnectUnspecifiedError                    = 0x80
	DisconnectMalformedPacket                     = 0x81
	DisconnectProtocolError                       = 0x82
	DisconnectImplementationSpecificError         = 0x83
	DisconnectNotAuthorized                       = 0x87
	DisconnectServerBusy                          = 0x89
	DisconnectServerShuttingDown                  = 0x8B
	DisconnectKeepAliveTimeout                    = 0x8D
	DisconnectSessionTakenOver                    = 0x8E
	DisconnectTopicFilterInvalid                  = 0x8F
	DisconnectTopicNameInvalid                    = 0x90
	DisconnectReceiveMaximumExceeded              = 0x93
	DisconnectTopicAliasInvalid                   = 0x94
	DisconnectPacketTooLarge                      = 0x95
	DisconnectMessageRateTooHigh                  = 0x96
	DisconnectQuotaExceeded                       = 0x97
	DisconnectAdministrativeAction                = 0x98
	DisconnectPayloadFormatInvalid                = 0x99
	DisconnectRetainNotSupported                  = 0x9A
	DisconnectQoSNotSupported                     = 0x9B
	DisconnectUseAnotherServer                    = 0x9C
	DisconnectServerMoved                         = 0x9D
	DisconnectSharedSubscriptionsNotSupported     = 0x9E
	DisconnectConnectionRateExceeded              = 0x9F
	DisconnectMaximumConnectTime                  = 0xA0
	DisconnectSubscriptionIdentifiersNotSupported = 0xA1
	DisconnectWildcardSubscriptionsNotSupported   = 0xA2
)
View Source
const (
	TypeConnect byte
	TypeConnack
	TypePublish
	TypePubAck
	TypePubRec
	TypePubRel
	TypePubComp
	TypeSubscribe
	TypeSubAck
	TypeUnsubscribe
	TypeUnSubAck
	TypePingReq
	TypePingResp
	TypeDisconnect
	TypeAuth
)
View Source
const (
	PropertyPayloadFormatIndicator          = 0x01
	PropertyMessageExpiryInterval           = 0x02
	PropertyContentType                     = 0x03
	PropertyResponseTopic                   = 0x08
	PropertyCorrelationData                 = 0x09
	PropertySubscriptionIdentifier          = 0x0B
	PropertySessionExpiryInterval           = 0x11
	PropertyAssignedClientIdentifier        = 0x12
	PropertyServerKeepAlive                 = 0x13
	PropertyAuthenticationMethod            = 0x15
	PropertyAuthenticationData              = 0x16
	PropertyRequestProblemInfo              = 0x17
	PropertyWillDelayInterval               = 0x18
	PropertyRequestResponseInfo             = 0x19
	PropertyResponseInformation             = 0x1A
	PropertyServerReference                 = 0x1C
	PropertyReasonString                    = 0x1F
	PropertyReceiveMaximum                  = 0x21
	PropertyTopicAliasMaximum               = 0x22
	PropertyTopicAlias                      = 0x23
	PropertyMaximumQoS                      = 0x24
	PropertyRetainAvailable                 = 0x25
	PropertyUserProperty                    = 0x26
	PropertyMaximumPacketSize               = 0x27
	PropertyWildcardSubscriptionAvailable   = 0x28
	PropertySubscriptionIdentifierAvailable = 0x29
	PropertySharedSubscriptionAvailable     = 0x2A
)
View Source
const (
	PubQosStepSuccess          = 0x00
	PubQosStepPackedIDNotFound = 0x92
)
View Source
const (
	FlagRetain = 0x01
	FlagDup    = 0x08
)
View Source
const (
	PubAckSuccess                     = 0x00
	PubAckNoMatchingSubscriber        = 0x10
	PubAckUnspecifiedError            = 0x80
	PubAckImplementationSpecificError = 0x83
	PubAckNotAuthorized               = 0x87
	PubAckTopicNameInvalid            = 0x90
	PubAckPacketIdentifierInUse       = 0x91
	PubAckPacketIdentifierNotFound    = 0x92
	PubAckQuotaExceed                 = 0x97
	PubAckPayloadFormatInvalid        = 0x99
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnAck

type ConnAck struct {
	SessionPresent bool
	ReasonCode     byte
	Properties     *ConnAckProperties
}

func (*ConnAck) Decode

func (p *ConnAck) Decode(reader io.Reader) error

func (*ConnAck) LogValue

func (p *ConnAck) LogValue() slog.Value

type ConnAckProperties

type ConnAckProperties struct {
	SessionExpiryInterval           *uint32
	ReceiveMaximum                  *uint16
	MaximumQoS                      *byte
	RetainAvailable                 *byte
	MaximumPacketSize               *uint32
	AssignedClientIdentifier        string
	TopicAliasMaximum               *uint16
	ReasonString                    string
	UserProperty                    []UserProperty
	WildcardSubscriptionAvailable   *byte
	SubscriptionIdentifierAvailable *byte
	SharedSubscriptionAvailable     *byte
	ServerKeepAlive                 *uint16
	ResponseInformation             string
	ServerReference                 string
	AuthenticationMethod            string
	AuthenticationData              []byte
}

func (*ConnAckProperties) LogValue

func (pp *ConnAckProperties) LogValue() slog.Value

type Connect

type Connect struct {
	// contains filtered or unexported fields
}

func NewConnect

func NewConnect(opt ConnectOptions) *Connect

func (*Connect) Encode

func (c *Connect) Encode() (net.Buffers, error)

func (*Connect) LogValue

func (c *Connect) LogValue() slog.Value

func (*Connect) Validate

func (c *Connect) Validate() error

type ConnectOptions

type ConnectOptions struct {
	CleanStart        bool
	KeepAlive         uint16
	ConnectProperties *ConnectProperties
	ClientID          string
	WillTopic         string
	WillMessage       string
	WillQoS           byte
	WillRetain        bool
	WillProperties    *WillProperties
	Username          string
	Password          string
}

type ConnectProperties

type ConnectProperties struct {
	SessionExpiryInterval      *uint32
	ReceiveMaximum             *uint16
	MaximumPacketSize          *uint32
	TopicAliasMaximum          *uint16
	RequestResponseInformation *byte
	RequestProblemInformation  *byte
	UserProperty               []UserProperty
	AuthenticationMethod       string
	AuthenticationData         []byte
}

func (*ConnectProperties) Encode

func (cp *ConnectProperties) Encode() ([]byte, error)

func (*ConnectProperties) LogValue

func (cp *ConnectProperties) LogValue() slog.Value

type Disconnect

type Disconnect struct {
	ReasonCode byte
	Properties *DisconnectProperties
}

func NewDisconnect

func NewDisconnect(reasonCode byte, properties *DisconnectProperties) *Disconnect

func (*Disconnect) Decode

func (c *Disconnect) Decode(reader io.Reader) error

func (*Disconnect) Encode

func (c *Disconnect) Encode() (net.Buffers, error)

type DisconnectProperties

type DisconnectProperties struct {
	SessionExpiryInterval *uint32
	ReasonString          string
	UserProperty          []UserProperty
	ServerReference       string
}

func (*DisconnectProperties) Encode

func (dp *DisconnectProperties) Encode() ([]byte, error)

type Packet

type Packet interface {
	Encode() (net.Buffers, error)
}

type PingReq

type PingReq struct{}

func (*PingReq) Encode

func (p *PingReq) Encode() (net.Buffers, error)

type PingRes

type PingRes struct{}

func (*PingRes) Decode

func (p *PingRes) Decode(reader io.Reader) error

type PubAck

type PubAck struct {
	PubAckPacket
}

func (*PubAck) Encode

func (pa *PubAck) Encode() (net.Buffers, error)

type PubAckPacket

type PubAckPacket struct {
	PacketID   uint16
	ReasonCode byte
	Properties *PubAckProperties
}

func (*PubAckPacket) Decode

func (ap *PubAckPacket) Decode(reader io.Reader) error

func (*PubAckPacket) GetPacketID

func (ap *PubAckPacket) GetPacketID() uint16

func (*PubAckPacket) SetPacketID

func (ap *PubAckPacket) SetPacketID(packetID uint16)

type PubAckProperties

type PubAckProperties struct {
	ReasonString string
	UserProperty []UserProperty
}

func (*PubAckProperties) Encode

func (ap *PubAckProperties) Encode() ([]byte, error)

type PubComp

type PubComp struct {
	PubAckPacket
}

type PubPacket

type PubPacket interface {
	GetPacketID() uint16
	SetPacketID(packetID uint16)
}

type PubRec

type PubRec struct {
	PubAckPacket
}

type PubRel

type PubRel struct {
	PubAckPacket
}

func NewPubRel

func NewPubRel(packetID uint16, reasonCode byte, properties *PubAckProperties) (*PubRel, error)

func (*PubRel) Encode

func (ap *PubRel) Encode() (net.Buffers, error)

type Publish

type Publish struct {
	// contains filtered or unexported fields
}

func NewPublish

func NewPublish(opt PublishOptions) (*Publish, error)

func (*Publish) Encode

func (p *Publish) Encode() (net.Buffers, error)

func (*Publish) GetPacketID

func (p *Publish) GetPacketID() uint16

func (*Publish) MarkAsDuplicated

func (p *Publish) MarkAsDuplicated()

func (*Publish) Properties

func (p *Publish) Properties() *PublishProperties

func (*Publish) SetPacketID

func (p *Publish) SetPacketID(packetID uint16)

func (*Publish) Topic

func (p *Publish) Topic() string

type PublishOptions

type PublishOptions struct {
	Qos               byte
	Retain            bool
	Topic             string
	PublishProperties *PublishProperties
	Payload           []byte
}

type PublishProperties

type PublishProperties struct {
	PayloadFormatIndicator *bool
	MessageExpiryInterval  *uint32
	TopicAlias             *uint16
	ResponseTopic          string
	CorrelationData        []byte
	UserProperty           []UserProperty
	SubscriptionIdentifier *uint32
	ContentType            string
}

func (*PublishProperties) Encode

func (pp *PublishProperties) Encode() ([]byte, error)

type SubAck

type SubAck struct {
	PacketID    uint16
	Properties  *SubAckProperties
	ReasonCodes []byte
}

func (*SubAck) Decode

func (sa *SubAck) Decode(reader io.Reader) error

type SubAckProperties

type SubAckProperties struct {
	ReasonString string
	UserProperty []UserProperty
}

type Subscribe

type Subscribe struct {
	PacketID            uint16
	Subscriptions       []Subscription
	SubscribeProperties *SubscribeProperties
}

func (*Subscribe) Encode

func (s *Subscribe) Encode() (net.Buffers, error)

type SubscribeProperties

type SubscribeProperties struct {
	SubscriptionIdentifier *uint32
	UserProperty           []UserProperty
}

func (*SubscribeProperties) Encode

func (sp *SubscribeProperties) Encode() ([]byte, error)

type Subscription

type Subscription struct {
	TopicFilter       string
	QoS               byte
	NoLocal           bool
	RetainAsPublished bool
	RetainHandling    byte
}

type UnSubAck

type UnSubAck struct {
	PacketID    uint16
	Properties  *UnSubAckProperties
	ReasonCodes []byte
}

func (*UnSubAck) Decode

func (ua *UnSubAck) Decode(reader io.Reader) error

type UnSubAckProperties

type UnSubAckProperties struct {
	ReasonString string
	UserProperty []UserProperty
}

type UnSubscribe

type UnSubscribe struct {
	PacketID              uint16
	TopicFilters          []string
	UnSubscribeProperties *UnSubscribeProperties
}

func (*UnSubscribe) Encode

func (s *UnSubscribe) Encode() (net.Buffers, error)

type UnSubscribeProperties

type UnSubscribeProperties struct {
	UserProperty []UserProperty
}

Note: `UserProperty` could be a direct property in `UnSubscribe`, since `UnSubscribeProperties` has only one property. However, I prefer code consistency and easier extensibility if the spec changes.

func (*UnSubscribeProperties) Encode

func (sp *UnSubscribeProperties) Encode() ([]byte, error)

type UserProperty

type UserProperty struct {
	Key, Value string
}

type WillProperties

type WillProperties struct {
	WillDelayInterval      *uint32
	PayloadFormatIndicator *bool
	MessageExpiryInterval  *uint32
	ContentType            string
	ResponseTopic          string
	CorrelationData        []byte
	UserProperty           []UserProperty
}

func (*WillProperties) Encode

func (wp *WillProperties) Encode() ([]byte, error)

func (*WillProperties) LogValue

func (wp *WillProperties) LogValue() slog.Value

Jump to

Keyboard shortcuts

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