mqtt

package
v0.0.0-...-996fa4a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeOfConnect = uint8(iota + 1)
	TypeOfConnack
	TypeOfPublish
	TypeOfPuback
	TypeOfPubrec
	TypeOfPubrel
	TypeOfPubcomp
	TypeOfSubscribe
	TypeOfSuback
	TypeOfUnsubscribe
	TypeOfUnsuback
	TypeOfPingreq
	TypeOfPingresp
	TypeOfDisconnect
)

MQTT message types

View Source
const (
	MaxMessageSize = 65536 // max MQTT message size is impossible to increase as per protocol (uint16 len)
)

Variables

View Source
var ErrMessageBadPacket = errors.New("mqtt: bad packet")
View Source
var ErrMessageTooLarge = errors.New("mqtt: message size exceeds 64K")

ErrMessageTooLarge occurs when a message encoded/decoded is larger than max MQTT frame.

Functions

This section is empty.

Types

type Connack

type Connack struct {
	ReturnCode uint8
}

Connack represents an MQTT connack packet. 0x00 connection accepted 0x01 refused: unacceptable proto version 0x02 refused: identifier rejected 0x03 refused server unavailiable 0x04 bad user or password 0x05 not authorized

func (*Connack) EncodeTo

func (c *Connack) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Connack) String

func (c *Connack) String() string

String returns the name of mqtt operation.

func (*Connack) Type

func (c *Connack) Type() uint8

Type returns the MQTT message type.

type Connect

type Connect struct {
	ProtoName      []byte
	Version        uint8
	UsernameFlag   bool
	PasswordFlag   bool
	WillRetainFlag bool
	WillQOS        uint8
	WillFlag       bool
	CleanSeshFlag  bool
	KeepAlive      uint16
	ClientID       []byte
	WillTopic      []byte
	WillMessage    []byte
	Username       []byte
	Password       []byte
}

Connect represents an MQTT connect packet.

func (*Connect) EncodeTo

func (c *Connect) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Connect) String

func (c *Connect) String() string

String returns the name of mqtt operation.

func (*Connect) Type

func (c *Connect) Type() uint8

Type returns the MQTT message type.

type Disconnect

type Disconnect struct {
}

Disconnect is to signal you want to cease communications with the server

func (*Disconnect) EncodeTo

func (d *Disconnect) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Disconnect) String

func (d *Disconnect) String() string

String returns the name of mqtt operation.

func (*Disconnect) Type

func (d *Disconnect) Type() uint8

Type returns the MQTT message type.

type Header struct {
	DUP    bool
	Retain bool
	QOS    uint8
}

Header as defined in http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#fixed-header

type Message

type Message interface {
	fmt.Stringer

	Type() uint8
	EncodeTo(w io.Writer) (int, error)
}

Message is the interface all our packets will be implementing

func DecodePacket

func DecodePacket(rdr Reader, maxMessageSize int64) (Message, error)

DecodePacket decodes the packet from the provided reader.

type Pingreq

type Pingreq struct {
}

Pingreq is a keepalive

func (*Pingreq) EncodeTo

func (p *Pingreq) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Pingreq) String

func (p *Pingreq) String() string

String returns the name of mqtt operation.

func (*Pingreq) Type

func (p *Pingreq) Type() uint8

Type returns the MQTT message type.

type Pingresp

type Pingresp struct {
}

Pingresp is for saying "hey, the server is alive"

func (*Pingresp) EncodeTo

func (p *Pingresp) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Pingresp) String

func (p *Pingresp) String() string

String returns the name of mqtt operation.

func (*Pingresp) Type

func (p *Pingresp) Type() uint8

Type returns the MQTT message type.

type Puback

type Puback struct {
	MessageID uint16
}

Puback is sent for QOS level one to verify the receipt of a publish Qoth the spec: "A PUBACK message is sent by a server in response to a PUBLISH message from a publishing client, and by a subscriber in response to a PUBLISH message from the server."

func (*Puback) EncodeTo

func (p *Puback) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Puback) String

func (p *Puback) String() string

String returns the name of mqtt operation.

func (*Puback) Type

func (p *Puback) Type() uint8

Type returns the MQTT message type.

type Pubcomp

type Pubcomp struct {
	MessageID uint16
}

Pubcomp is for saying is in response to a pubrel sent by the publisher the final member of the QOS2 flow. both sides have said "hey, we did it!"

func (*Pubcomp) EncodeTo

func (p *Pubcomp) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Pubcomp) String

func (p *Pubcomp) String() string

String returns the name of mqtt operation.

func (*Pubcomp) Type

func (p *Pubcomp) Type() uint8

Type returns the MQTT message type.

type Publish

type Publish struct {
	Header
	Topic     []byte
	MessageID uint16
	Payload   []byte
}

Publish represents an MQTT publish packet.

func (*Publish) EncodeTo

func (p *Publish) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Publish) String

func (p *Publish) String() string

String returns the name of mqtt operation.

func (*Publish) Type

func (p *Publish) Type() uint8

Type returns the MQTT message type.

type Pubrec

type Pubrec struct {
	MessageID uint16
}

Pubrec is for verifying the receipt of a publish Qoth the spec:"It is the second message of the QoS level 2 protocol flow. A PUBREC message is sent by the server in response to a PUBLISH message from a publishing client, or by a subscriber in response to a PUBLISH message from the server."

func (*Pubrec) EncodeTo

func (p *Pubrec) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Pubrec) String

func (p *Pubrec) String() string

String returns the name of mqtt operation.

func (*Pubrec) Type

func (p *Pubrec) Type() uint8

Type returns the MQTT message type.

type Pubrel

type Pubrel struct {
	MessageID uint16
	//QOS1
	Header Header
}

Pubrel is a response to pubrec from either the client or server.

func (*Pubrel) EncodeTo

func (p *Pubrel) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Pubrel) String

func (p *Pubrel) String() string

String returns the name of mqtt operation.

func (*Pubrel) Type

func (p *Pubrel) Type() uint8

Type returns the MQTT message type.

type Reader

type Reader interface {
	io.Reader
	ReadByte() (byte, error)
}

Reader is the requied reader for an efficient decoding.

type Suback

type Suback struct {
	MessageID uint16
	Qos       []uint8
}

Suback is to say "hey, you got it buddy. I will send you messages that fit this pattern"

func (*Suback) EncodeTo

func (s *Suback) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Suback) String

func (s *Suback) String() string

String returns the name of mqtt operation.

func (*Suback) Type

func (s *Suback) Type() uint8

Type returns the MQTT message type.

type Subscribe

type Subscribe struct {
	Header
	MessageID     uint16
	Subscriptions []TopicQOSTuple
}

Subscribe tells the server which topics the client would like to subscribe to

func (*Subscribe) EncodeTo

func (s *Subscribe) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Subscribe) String

func (s *Subscribe) String() string

String returns the name of mqtt operation.

func (*Subscribe) Type

func (s *Subscribe) Type() uint8

Type returns the MQTT message type.

type TopicQOSTuple

type TopicQOSTuple struct {
	Qos   uint8
	Topic []byte
}

TopicQOSTuple is a struct for pairing the Qos and topic together for the QOS' pairs in unsubscribe and subscribe

type Unsuback

type Unsuback struct {
	MessageID uint16
}

Unsuback is to unsubscribe as suback is to subscribe

func (*Unsuback) EncodeTo

func (u *Unsuback) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Unsuback) String

func (u *Unsuback) String() string

String returns the name of mqtt operation.

func (*Unsuback) Type

func (u *Unsuback) Type() uint8

Type returns the MQTT message type.

type Unsubscribe

type Unsubscribe struct {
	Header
	MessageID uint16
	Topics    []TopicQOSTuple
}

Unsubscribe is the message to send if you don't want to subscribe to a topic anymore

func (*Unsubscribe) EncodeTo

func (u *Unsubscribe) EncodeTo(w io.Writer) (int, error)

EncodeTo writes the encoded message to the underlying writer.

func (*Unsubscribe) String

func (u *Unsubscribe) String() string

String returns the name of mqtt operation.

func (*Unsubscribe) Type

func (u *Unsubscribe) Type() uint8

Type returns the MQTT message type.

Jump to

Keyboard shortcuts

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