mqttp

package
Version: v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: Apache-2.0 Imports: 6 Imported by: 57

Documentation

Index

Constants

View Source
const (
	PropertyPayloadFormat                   = PropertyID(0x01)
	PropertyPublicationExpiry               = PropertyID(0x02)
	PropertyContentType                     = PropertyID(0x03)
	PropertyResponseTopic                   = PropertyID(0x08)
	PropertyCorrelationData                 = PropertyID(0x09)
	PropertySubscriptionIdentifier          = PropertyID(0x0B)
	PropertySessionExpiryInterval           = PropertyID(0x11)
	PropertyAssignedClientIdentifier        = PropertyID(0x12)
	PropertyServerKeepAlive                 = PropertyID(0x13)
	PropertyAuthMethod                      = PropertyID(0x15)
	PropertyAuthData                        = PropertyID(0x16)
	PropertyRequestProblemInfo              = PropertyID(0x17)
	PropertyWillDelayInterval               = PropertyID(0x18)
	PropertyRequestResponseInfo             = PropertyID(0x19)
	PropertyResponseInfo                    = PropertyID(0x1A)
	PropertyServerReverence                 = PropertyID(0x1C)
	PropertyReasonString                    = PropertyID(0x1F)
	PropertyReceiveMaximum                  = PropertyID(0x21)
	PropertyTopicAliasMaximum               = PropertyID(0x22)
	PropertyTopicAlias                      = PropertyID(0x23)
	PropertyMaximumQoS                      = PropertyID(0x24)
	PropertyRetainAvailable                 = PropertyID(0x25)
	PropertyUserProperty                    = PropertyID(0x26)
	PropertyMaximumPacketSize               = PropertyID(0x27)
	PropertyWildcardSubscriptionAvailable   = PropertyID(0x28)
	PropertySubscriptionIdentifierAvailable = PropertyID(0x29)
	PropertySharedSubscriptionAvailable     = PropertyID(0x2A)
)
View Source
const (
	PropertyTypeByte = iota
	PropertyTypeShort
	PropertyTypeInt
	PropertyTypeVarInt
	PropertyTypeString
	PropertyTypeStringPair
	PropertyTypeBinary
)
View Source
const (
	// ProtocolV31 describes spec MQIsdp
	ProtocolV31 = ProtocolVersion(0x3)
	// ProtocolV311 describes spec v3.1.1
	ProtocolV311 = ProtocolVersion(0x4)
	// ProtocolV50 describes spec v5.0
	ProtocolV50 = ProtocolVersion(0x5)
)
View Source
const (
	// MaxLPString maximum size of length-prefixed string
	MaxLPString = 65535
)

Variables

View Source
var (
	// TopicFilterRegexp regular expression that all subscriptions must be validated
	TopicFilterRegexp = regexp.MustCompile(`^(([^+#]*|\+)(/([^+#]*|\+))*(/#)?|#)$`)

	// TopicPublishRegexp regular expression that all publish to topic must be validated
	TopicPublishRegexp = regexp.MustCompile(`^[^#+]*$`)

	// SharedTopicRegexp regular expression that all share subscription must be validated
	SharedTopicRegexp = regexp.MustCompile(`^\$share/([^#+/]+)(/)(.+)$`)

	// BasicUTFRegexp regular expression all MQTT strings must meet [MQTT-1.5.3]
	BasicUTFRegexp = regexp.MustCompile("^[^\u0000-\u001F\u007F-\u009F]*$")
)
View Source
var SupportedVersions = map[ProtocolVersion]string{
	ProtocolV31:  "MQIsdp",
	ProtocolV311: "MQTT",
	ProtocolV50:  "MQTT",
}

SupportedVersions is a map of the version number (0x3 or 0x4) to the version string, "MQIsdp" for 0x3, and "MQTT" for 0x4.

Functions

func Encode

func Encode(p IFace) ([]byte, error)

Encode try encode packet with into newly allocated buffer

func IsValidUTF added in v0.5.1

func IsValidUTF(b []byte) bool

func ReadLPBytes

func ReadLPBytes(buf []byte) ([]byte, int, error)

ReadLPBytes read length prefixed bytes

func ValidTopic

func ValidTopic(topic []byte) bool

ValidTopic checks the topic, which is a slice of bytes, to see if it's valid. Topic is considered valid if it's longer than 0 bytes, and doesn't contain any wildcard characters such as + and #.

func WriteLPBytes

func WriteLPBytes(buf []byte, b []byte) (int, error)

WriteLPBytes write length prefixed bytes

Types

type Ack

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

Ack acknowledge packets for PUBLISH messages A PUBACK Packet is the response to a PUBLISH Packet with QoS level 1 A PUBREC/PUBREL/PUBCOMP Packet is the response to a PUBLISH Packet with QoS level 2

func NewPubAck

func NewPubAck(v ProtocolVersion) *Ack

NewPubAck creates a new PUBACK packet

func NewPubComp

func NewPubComp(v ProtocolVersion) *Ack

NewPubComp creates a new PUBCOMP packet

func NewPubRec

func NewPubRec(v ProtocolVersion) *Ack

NewPubRec creates a new PUBREC packet

func NewPubRel

func NewPubRel(v ProtocolVersion) *Ack

NewPubRel creates a new PUBREL packet

func (*Ack) Desc

func (h *Ack) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*Ack) Encode

func (h *Ack) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*Ack) Flags

func (h *Ack) Flags() byte

Flags returns the fixed header flags for this message.

func (*Ack) ID

func (h *Ack) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*Ack) Name

func (h *Ack) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*Ack) PropertiesDiscard

func (h *Ack) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*Ack) PropertyForEach

func (h *Ack) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*Ack) PropertyGet

func (h *Ack) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*Ack) PropertySet

func (h *Ack) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*Ack) Reason

func (msg *Ack) Reason() ReasonCode

Reason return acknowledgment reason

func (*Ack) RemainingLength

func (h *Ack) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*Ack) SetPacketID

func (msg *Ack) SetPacketID(v IDType)

SetPacketID sets the ID of the packet.

func (*Ack) SetReason

func (msg *Ack) SetReason(c ReasonCode)

SetReason of acknowledgment

func (*Ack) SetVersion

func (h *Ack) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*Ack) Size

func (h *Ack) Size() (int, error)

Size of message

func (*Ack) Type

func (h *Ack) Type() Type

Type returns the MessageType of the Message

func (*Ack) Version

func (h *Ack) Version() ProtocolVersion

Version protocol version used by packet

type Auth

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

Auth The CONNACK Packet is the packet sent by the Server in response to a CONNECT Packet received from a Client. The first packet sent from the Server to the Client MUST be a CONNACK Packet [MQTT-3.2.0-1]. If the Client does not receive a CONNACK Packet from the Server within a reasonable amount of time, the Client SHOULD close the Network Connection. A "reasonable" amount of time depends on the type of application and the communications infrastructure.

func NewAuth

func NewAuth(v ProtocolVersion) *Auth

NewAuth creates a new AUTH packet

func (*Auth) Desc

func (h *Auth) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*Auth) Encode

func (h *Auth) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*Auth) Flags

func (h *Auth) Flags() byte

Flags returns the fixed header flags for this message.

func (*Auth) ID

func (h *Auth) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*Auth) Name

func (h *Auth) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*Auth) PropertiesDiscard

func (h *Auth) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*Auth) PropertyForEach

func (h *Auth) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*Auth) PropertyGet

func (h *Auth) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*Auth) PropertySet

func (h *Auth) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*Auth) ReasonCode

func (msg *Auth) ReasonCode() ReasonCode

ReasonCode get authentication reason

func (*Auth) RemainingLength

func (h *Auth) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*Auth) SetReasonCode

func (msg *Auth) SetReasonCode(c ReasonCode) error

SetReasonCode set authentication reason code

func (*Auth) SetVersion

func (h *Auth) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*Auth) Size

func (h *Auth) Size() (int, error)

Size of message

func (*Auth) Type

func (h *Auth) Type() Type

Type returns the MessageType of the Message

func (*Auth) Version

func (h *Auth) Version() ProtocolVersion

Version protocol version used by packet

type CodeIssuer

type CodeIssuer byte

CodeIssuer who is message issuer

const (
	CodeIssuerServer CodeIssuer = 0x00
	CodeIssuerClient
	CodeIssuerBoth
	CodeIssuerInvalid
)

nolint: golint

type ConnAck

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

ConnAck The CONNACK Packet is the packet sent by the Server in response to a CONNECT Packet received from a Client. The first packet sent from the Server to the Client MUST be a CONNACK Packet [MQTT-3.2.0-1]. If the Client does not receive a CONNACK Packet from the Server within a reasonable amount of time, the Client SHOULD close the Network Connection. A "reasonable" amount of time depends on the type of application and the communications infrastructure.

func NewConnAck

func NewConnAck(v ProtocolVersion) *ConnAck

NewConnAck creates a new CONNACK packet

func (*ConnAck) Desc

func (h *ConnAck) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*ConnAck) Encode

func (h *ConnAck) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*ConnAck) Flags

func (h *ConnAck) Flags() byte

Flags returns the fixed header flags for this message.

func (*ConnAck) ID

func (h *ConnAck) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*ConnAck) Name

func (h *ConnAck) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*ConnAck) PropertiesDiscard

func (h *ConnAck) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*ConnAck) PropertyForEach

func (h *ConnAck) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*ConnAck) PropertyGet

func (h *ConnAck) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*ConnAck) PropertySet

func (h *ConnAck) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*ConnAck) RemainingLength

func (h *ConnAck) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*ConnAck) ReturnCode

func (msg *ConnAck) ReturnCode() ReasonCode

ReturnCode returns the return code received for the CONNECT message. The return type is an error

func (*ConnAck) SessionPresent

func (msg *ConnAck) SessionPresent() bool

SessionPresent returns the session present flag value

func (*ConnAck) SetReturnCode

func (msg *ConnAck) SetReturnCode(ret ReasonCode) error

SetReturnCode of conn

func (*ConnAck) SetSessionPresent

func (msg *ConnAck) SetSessionPresent(v bool)

SetSessionPresent sets the value of the session present flag

func (*ConnAck) SetVersion

func (h *ConnAck) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*ConnAck) Size

func (h *ConnAck) Size() (int, error)

Size of message

func (*ConnAck) Type

func (h *ConnAck) Type() Type

Type returns the MessageType of the Message

func (*ConnAck) Version

func (h *ConnAck) Version() ProtocolVersion

Version protocol version used by packet

type Connect

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

Connect Accept After a Network Connection is established by a Client to a Server, the first Packet sent from the Client to the Server MUST be a CONNECT Packet [MQTT-3.1.0-1].

A Client can only send the CONNECT Packet once over a Network Connection. The Server MUST process a second CONNECT Packet sent from a Client as a protocol violation and disconnect the Client [MQTT-3.1.0-2]. See section 4.8 for information about handling errors.

func NewConnect

func NewConnect(v ProtocolVersion) *Connect

NewConnect creates a new CONNECT packet

func (*Connect) ClientID

func (msg *Connect) ClientID() []byte

ClientID returns an ID that identifies the Client to the Server. Each Client connecting to the Server has a unique ClientId. The ClientId MUST be used by Clients and by Servers to identify state that they hold relating to this MQTT Session between the Client and the Server

func (*Connect) Credentials

func (msg *Connect) Credentials() ([]byte, []byte)

Credentials returns user and password

func (*Connect) Desc

func (h *Connect) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*Connect) Encode

func (h *Connect) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*Connect) Flags

func (h *Connect) Flags() byte

Flags returns the fixed header flags for this message.

func (*Connect) ID

func (h *Connect) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*Connect) IsClean

func (msg *Connect) IsClean() bool

IsClean returns the bit that specifies the handling of the Session state. The Client and Server can store Session state to enable reliable messaging to continue across a sequence of Network Connections. This bit is used to control the lifetime of the Session state.

func (*Connect) KeepAlive

func (msg *Connect) KeepAlive() uint16

KeepAlive returns a time interval measured in seconds. Expressed as a 16-bit word, it is the maximum time interval that is permitted to elapse between the point at which the Client finishes transmitting one Control Packet and the point it starts sending the next.

func (*Connect) Name

func (h *Connect) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*Connect) PropertiesDiscard

func (h *Connect) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*Connect) PropertyForEach

func (h *Connect) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*Connect) PropertyGet

func (h *Connect) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*Connect) PropertySet

func (h *Connect) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*Connect) RemainingLength

func (h *Connect) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*Connect) ResetWill

func (msg *Connect) ResetWill()

ResetWill reset will state of message

func (*Connect) SetClean

func (msg *Connect) SetClean(v bool)

SetClean sets the bit that specifies the handling of the Session state.

func (*Connect) SetClientID

func (msg *Connect) SetClientID(v []byte) error

SetClientID sets an ID that identifies the Client to the Server.

func (*Connect) SetCredentials

func (msg *Connect) SetCredentials(u []byte, p []byte) error

SetCredentials set username and password

func (*Connect) SetKeepAlive

func (msg *Connect) SetKeepAlive(v uint16)

SetKeepAlive sets the time interval in which the server should keep the connection alive.

func (*Connect) SetVersion

func (h *Connect) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*Connect) SetWill

func (msg *Connect) SetWill(m *Publish) error

SetWill state of message

func (*Connect) Size

func (h *Connect) Size() (int, error)

Size of message

func (*Connect) Type

func (h *Connect) Type() Type

Type returns the MessageType of the Message

func (*Connect) Version

func (h *Connect) Version() ProtocolVersion

Version protocol version used by packet

func (*Connect) Will

func (msg *Connect) Will() *Publish

Will returns the topic in which the Will Message should be published to. If the Will Flag is set to 1, the Will Topic must be in the payload. returns will topic, will message, will qos , will retain, will if last param is false will is not set

type Disconnect

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

Disconnect The DISCONNECT Packet is the final Control Packet sent from the Client to the Server. It indicates that the Client is disconnecting cleanly.

func NewDisconnect

func NewDisconnect(v ProtocolVersion) *Disconnect

NewDisconnect creates a new DISCONNECT packet

func (*Disconnect) Desc

func (h *Disconnect) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*Disconnect) Encode

func (h *Disconnect) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*Disconnect) Flags

func (h *Disconnect) Flags() byte

Flags returns the fixed header flags for this message.

func (*Disconnect) ID

func (h *Disconnect) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*Disconnect) Name

func (h *Disconnect) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*Disconnect) PropertiesDiscard

func (h *Disconnect) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*Disconnect) PropertyForEach

func (h *Disconnect) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*Disconnect) PropertyGet

func (h *Disconnect) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*Disconnect) PropertySet

func (h *Disconnect) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*Disconnect) ReasonCode

func (msg *Disconnect) ReasonCode() ReasonCode

ReasonCode get disconnect reason

func (*Disconnect) RemainingLength

func (h *Disconnect) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*Disconnect) SetReasonCode

func (msg *Disconnect) SetReasonCode(c ReasonCode)

SetReasonCode set disconnect reason

func (*Disconnect) SetVersion

func (h *Disconnect) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*Disconnect) Size

func (h *Disconnect) Size() (int, error)

Size of message

func (*Disconnect) Type

func (h *Disconnect) Type() Type

Type returns the MessageType of the Message

func (*Disconnect) Version

func (h *Disconnect) Version() ProtocolVersion

Version protocol version used by packet

type Error

type Error byte

Error errors

const (
	// ErrInvalidUnSubscribe Invalid UNSUBSCRIBE message
	ErrInvalidUnSubscribe Error = iota
	// ErrInvalidUnSubAck Invalid UNSUBACK message
	ErrInvalidUnSubAck
	ErrDupViolation
	// ErrPackedIDNotMatched Packet ID does not match
	ErrPackedIDNotMatched
	ErrInvalid
	// ErrPackedIDZero cannot be 0
	ErrPackedIDZero
	// ErrOnPublishNil Publisher is nil
	ErrOnPublishNil
	// ErrInvalidMessageType Invalid message type
	ErrInvalidMessageType
	// ErrInvalidMessageTypeFlags Invalid message flags
	ErrInvalidMessageTypeFlags
	// ErrInvalidQoS Invalid message QoS
	ErrInvalidQoS
	// ErrInvalidLength Invalid message length
	ErrInvalidLength
	// ErrProtocolViolation Message Will violation
	ErrProtocolViolation
	// ErrInsufficientBufferSize Insufficient buffer size
	ErrInsufficientBufferSize
	// ErrInsufficientDataSize
	ErrInsufficientDataSize
	// ErrInvalidTopic Topic is empty
	ErrInvalidTopic
	// ErrEmptyPayload Payload is empty
	ErrEmptyPayload
	// ErrInvalidReturnCode invalid return code
	ErrInvalidReturnCode
	// ErrUnimplemented method not implemented
	ErrUnimplemented
	// ErrInvalidLPStringSize LP string size is bigger than expected
	ErrInvalidLPStringSize
	// ErrMalformedTopic topic string is not UTF8
	ErrMalformedTopic
	ErrMalformedStream
	ErrInvalidProtocolVersion
	ErrNotSet
	ErrPanicDetected
	ErrInvalidArgs
	ErrInvalidUtf8
	ErrNotSupported
	ErrProtocolInvalidName
)

nolint: golint

func (Error) Error

func (e Error) Error() string

Error returns the corresponding error string for the ConnAckCode

type IDType

type IDType uint16

IDType as per [MQTT-2.2.1]

type IFace

type IFace interface {
	// Desc returns a string description of the message type. For example, a
	// CONNECT message would return "Client request to connect to Server." These
	// descriptions are statically defined (copied from the MQTT spec) and cannot
	// be changed.
	Desc() string

	// Type returns the MessageType of the Message. The returned value should be one
	// of the constants defined for MessageType.
	Type() Type

	// IDType returns packet id
	// if has not been set return ErrNotSet
	ID() (IDType, error)

	// Encode writes the message bytes into the byte array from the argument. It
	// returns the number of bytes encoded and whether there's any errors along
	// the way. If there's any errors, then the byte slice and count should be
	// considered invalid.
	Encode([]byte) (int, error)

	// Size of whole message
	Size() (int, error)

	// SetVersion set protocol version used by message
	SetVersion(v ProtocolVersion)

	// Version get protocol version used by message
	Version() ProtocolVersion

	PropertiesDiscard()

	PropertyGet(PropertyID) PropertyToType

	PropertySet(PropertyID, interface{}) error

	PropertyForEach(func(PropertyID, PropertyToType)) error
	// contains filtered or unexported methods
}

IFace is an interface defined for all MQTT message types.

func Decode

func Decode(v ProtocolVersion, buf []byte) (msg IFace, total int, err error)

Decode buf into message and return IFace type

func New

func New(v ProtocolVersion, t Type) (IFace, error)

New creates a new message based on the message type. It is a shortcut to call one of the New*Message functions. If an error is returned then the message type is invalid.

type PingReq

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

PingReq The PINGREQ Packet is sent from a Client to the Server. It can be used to: 1. Indicate to the Server that the Client is alive in the absence of any other

Control Packets being sent from the Client to the Server.

2. Request that the Server responds to confirm that it is alive. 3. Exercise the network to indicate that the Network Connection is active.

func NewPingReq

func NewPingReq(v ProtocolVersion) *PingReq

NewPingReq creates a new PINGREQ packet

func (*PingReq) Desc

func (h *PingReq) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*PingReq) Encode

func (h *PingReq) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*PingReq) Flags

func (h *PingReq) Flags() byte

Flags returns the fixed header flags for this message.

func (*PingReq) ID

func (h *PingReq) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*PingReq) Name

func (h *PingReq) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*PingReq) PropertiesDiscard

func (h *PingReq) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*PingReq) PropertyForEach

func (h *PingReq) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*PingReq) PropertyGet

func (h *PingReq) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*PingReq) PropertySet

func (h *PingReq) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*PingReq) RemainingLength

func (h *PingReq) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*PingReq) SetVersion

func (h *PingReq) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*PingReq) Size

func (h *PingReq) Size() (int, error)

Size of message

func (*PingReq) Type

func (h *PingReq) Type() Type

Type returns the MessageType of the Message

func (*PingReq) Version

func (h *PingReq) Version() ProtocolVersion

Version protocol version used by packet

type PingResp

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

PingResp A PINGRESP Packet is sent by the Server to the Client in response to a PINGREQ Packet. It indicates that the Server is alive.

func NewPingResp

func NewPingResp(v ProtocolVersion) *PingResp

NewPingResp creates a new PINGRESP packet

func (*PingResp) Desc

func (h *PingResp) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*PingResp) Encode

func (h *PingResp) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*PingResp) Flags

func (h *PingResp) Flags() byte

Flags returns the fixed header flags for this message.

func (*PingResp) ID

func (h *PingResp) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*PingResp) Name

func (h *PingResp) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*PingResp) PropertiesDiscard

func (h *PingResp) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*PingResp) PropertyForEach

func (h *PingResp) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*PingResp) PropertyGet

func (h *PingResp) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*PingResp) PropertySet

func (h *PingResp) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*PingResp) RemainingLength

func (h *PingResp) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*PingResp) SetVersion

func (h *PingResp) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*PingResp) Size

func (h *PingResp) Size() (int, error)

Size of message

func (*PingResp) Type

func (h *PingResp) Type() Type

Type returns the MessageType of the Message

func (*PingResp) Version

func (h *PingResp) Version() ProtocolVersion

Version protocol version used by packet

type PropertyError

type PropertyError int

PropertyError encodes property error

const (
	ErrPropertyNotFound PropertyError = iota
	ErrPropertyInvalidID
	ErrPropertyPacketTypeMismatch
	ErrPropertyTypeMismatch
	ErrPropertyDuplicate
	ErrPropertyUnsupported
	ErrPropertyWrongType
)

nolint: golint

func (PropertyError) Error

func (e PropertyError) Error() string

Error description

type PropertyID

type PropertyID uint32

PropertyID id as per [MQTT-2.2.2]

func (PropertyID) DupAllowed

func (p PropertyID) DupAllowed(t Type) bool

DupAllowed check if property id allows keys duplication

func (PropertyID) IsValid

func (p PropertyID) IsValid() bool

IsValid check if property id is valid spec value

func (PropertyID) IsValidPacketType

func (p PropertyID) IsValidPacketType(t Type) bool

IsValidPacketType check either property id can be used for given packet type

type PropertyToType

type PropertyToType interface {
	Type() PropertyType
	AsByte() (byte, error)
	AsShort() (uint16, error)
	AsInt() (uint32, error)
	AsString() (string, error)
	AsStringPair() (StringPair, error)
	AsStringPairs() ([]StringPair, error)
	AsBinary() ([]byte, error)
}

PropertyToType represent property value as requested type

type PropertyType

type PropertyType byte

PropertyType value type used by property ID

type ProtocolVersion

type ProtocolVersion byte

ProtocolVersion describes versions implemented by this package

func (ProtocolVersion) IsValid

func (p ProtocolVersion) IsValid() bool

IsValid check if protocol version is valid for this implementation

type Publish

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

Publish A PUBLISH Control Packet is sent from a Client to a Server or from Server to a Client to transport an Application Message.

func NewPublish

func NewPublish(v ProtocolVersion) *Publish

NewPublish creates a new PUBLISH packet

func (*Publish) Clone

func (msg *Publish) Clone(v ProtocolVersion) (*Publish, error)

Clone packet qos, topic, payload, retain and properties

func (*Publish) Desc

func (h *Publish) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*Publish) Dup

func (msg *Publish) Dup() bool

Dup returns the value specifying the duplicate delivery of a PUBLISH Control Packet. If the DUP flag is set to 0, it indicates that this is the first occasion that the Client or Server has attempted to send this MQTT PUBLISH Packet. If the DUP flag is set to 1, it indicates that this might be re-delivery of an earlier attempt to send the Packet.

func (*Publish) Encode

func (h *Publish) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*Publish) Expired

func (msg *Publish) Expired() (time.Time, uint32, bool)

Expired check if packet has elapsed it's time or not returns false if does not expire

func (*Publish) Flags

func (h *Publish) Flags() byte

Flags returns the fixed header flags for this message.

func (*Publish) ID

func (h *Publish) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*Publish) Name

func (h *Publish) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*Publish) Payload

func (msg *Publish) Payload() []byte

Payload returns the application message that's part of the PUBLISH message.

func (*Publish) PropertiesDiscard

func (h *Publish) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*Publish) PropertyForEach

func (h *Publish) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*Publish) PropertyGet

func (h *Publish) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*Publish) PropertySet

func (h *Publish) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*Publish) PublishID

func (msg *Publish) PublishID() uintptr

PublishID get publish ID to check No Local

func (*Publish) QoS

func (msg *Publish) QoS() QosType

QoS returns the field that indicates the level of assurance for delivery of an Application Message. The values are QoS0, QoS1 and QoS2.

func (*Publish) RemainingLength

func (h *Publish) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*Publish) Retain

func (msg *Publish) Retain() bool

Retain returns the value of the RETAIN flag. This flag is only used on the PUBLISH Packet. If the RETAIN flag is set to 1, in a PUBLISH Packet sent by a Client to a Server, the Server MUST store the Application Message and its QoS, so that it can be delivered to future subscribers whose subscriptions match its topic name.

func (*Publish) Set

func (msg *Publish) Set(t string, p []byte, q QosType, r bool, d bool) error

Set topic/payload/qos/retained/bool

func (*Publish) SetDup

func (msg *Publish) SetDup(v bool)

SetDup sets the value specifying the duplicate delivery of a PUBLISH Control Packet.

func (*Publish) SetExpireAt

func (msg *Publish) SetExpireAt(tm time.Time)

SetExpireAt time object

func (*Publish) SetPacketID

func (msg *Publish) SetPacketID(v IDType)

SetPacketID sets the ID of the packet.

func (*Publish) SetPayload

func (msg *Publish) SetPayload(v []byte)

SetPayload sets the application message that's part of the PUBLISH message.

func (*Publish) SetPublishID

func (msg *Publish) SetPublishID(id uintptr)

SetPublishID internally used publish id to allow No Local option

func (*Publish) SetQoS

func (msg *Publish) SetQoS(v QosType) error

SetQoS sets the field that indicates the level of assurance for delivery of an Application Message. The values are QoS0, QoS1 and QoS2. An error is returned if the value is not one of these.

func (*Publish) SetRetain

func (msg *Publish) SetRetain(v bool)

SetRetain sets the value of the RETAIN flag.

func (*Publish) SetTopic

func (msg *Publish) SetTopic(v string) error

SetTopic sets the the topic name that identifies the information channel to which payload data is published. An error is returned if ValidTopic() is false.

func (*Publish) SetVersion

func (h *Publish) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*Publish) Size

func (h *Publish) Size() (int, error)

Size of message

func (*Publish) Topic

func (msg *Publish) Topic() string

Topic returns the the topic name that identifies the information channel to which payload data is published.

func (*Publish) Type

func (h *Publish) Type() Type

Type returns the MessageType of the Message

func (*Publish) Version

func (h *Publish) Version() ProtocolVersion

Version protocol version used by packet

type QosType

type QosType byte

QosType QoS type

const (
	// QoS0 At most once delivery
	// The message is delivered according to the capabilities of the underlying network.
	// No response is sent by the receiver and no retry is performed by the sender. The
	// message arrives at the receiver either once or not at all.
	QoS0 QosType = iota

	// QoS1 At least once delivery
	// This quality of service ensures that the message arrives at the receiver at least once.
	// A QoS 1 PUBLISH Packet has a Packet Identifier in its variable header and is acknowledged
	// by a PUBACK Packet. Section 2.3.1 provides more information about Packet Identifiers.
	QoS1

	// QoS2 Exactly once delivery
	// This is the highest quality of service, for use when neither loss nor duplication of
	// messages are acceptable. There is an increased overhead associated with this quality of
	// service.
	QoS2

	// QosFailure is a return value for a subscription if there's a problem while subscribing
	// to a specific topic.
	QosFailure = 0x80
)

func (QosType) Desc

func (c QosType) Desc() string

Desc get string representation of QoS value

func (QosType) IsValid

func (c QosType) IsValid() bool

IsValid checks the QoS value to see if it's valid. Valid QoS are QoS0, QoS1, and QoS2.

func (QosType) IsValidFull

func (c QosType) IsValidFull() bool

IsValidFull checks the QoS value to see if it's valid. Valid QoS are QoS0, QoS1, QoS2 and QosFailure.

type ReasonCode

type ReasonCode byte

ReasonCode contains return codes across all MQTT specs

const (
	CodeSuccess                            ReasonCode = 0x00 //    |    \    |
	CodeRefusedUnacceptableProtocolVersion ReasonCode = 0x01 //    |    \    |
	CodeRefusedIdentifierRejected          ReasonCode = 0x02 //    |    \    |
	CodeRefusedServerUnavailable           ReasonCode = 0x03 //    |    \    |
	CodeRefusedBadUsernameOrPassword       ReasonCode = 0x04 //    |    \    |
	CodeRefusedNotAuthorized               ReasonCode = 0x05 // <--|    \    | // V3.1.1 ONLY
	CodeNoMatchingSubscribers              ReasonCode = 0x10 //         \    |
	CodeNoSubscriptionExisted              ReasonCode = 0x11 //         \    |
	CodeContinueAuthentication             ReasonCode = 0x18 //         \    |
	CodeReAuthenticate                     ReasonCode = 0x19 //         \    |
	CodeUnspecifiedError                   ReasonCode = 0x80 //         \    |
	CodeMalformedPacket                    ReasonCode = 0x81 //         \    |
	CodeProtocolError                      ReasonCode = 0x82 //         \    |
	CodeImplementationSpecificError        ReasonCode = 0x83 //         \    |
	CodeUnsupportedProtocol                ReasonCode = 0x84 //         \    |
	CodeInvalidClientID                    ReasonCode = 0x85 //         \    |
	CodeBadUserOrPassword                  ReasonCode = 0x86 //         \    |
	CodeNotAuthorized                      ReasonCode = 0x87 //         \    |
	CodeServerUnavailable                  ReasonCode = 0x88 //         \    |
	CodeServerBusy                         ReasonCode = 0x89 //         \    |
	CodeBanned                             ReasonCode = 0x8A //         \    |
	CodeServerShuttingDown                 ReasonCode = 0x8B //         \    |
	CodeBadAuthMethod                      ReasonCode = 0x8C //         \    |
	CodeKeepAliveTimeout                   ReasonCode = 0x8D //         \    |
	CodeSessionTakenOver                   ReasonCode = 0x8E //         \    |
	CodeInvalidTopicFilter                 ReasonCode = 0x8F //         \    |
	CodeInvalidTopicName                   ReasonCode = 0x90 //         \    |
	CodePacketIDInUse                      ReasonCode = 0x91 //         \    |
	CodePacketIDNotFound                   ReasonCode = 0x92 //         \    |
	CodeReceiveMaximumExceeded             ReasonCode = 0x93 //         \    |
	CodeInvalidTopicAlias                  ReasonCode = 0x94 //         \    |
	CodePacketTooLarge                     ReasonCode = 0x95 //         \    |
	CodeMessageRateTooHigh                 ReasonCode = 0x96 //         \    |
	CodeQuotaExceeded                      ReasonCode = 0x97 //         \    |
	CodeAdministrativeAction               ReasonCode = 0x98 //         \    |
	CodeInvalidPayloadFormat               ReasonCode = 0x99 //         \    |
	CodeRetainNotSupported                 ReasonCode = 0x9A //         \    |
	CodeNotSupportedQoS                    ReasonCode = 0x9B //         \    |
	CodeUseAnotherServer                   ReasonCode = 0x9C //         \    |
	CodeServerMoved                        ReasonCode = 0x9D //         \    |
	CodeSharedSubscriptionNotSupported     ReasonCode = 0x9E //         \    |
	CodeConnectionRateExceeded             ReasonCode = 0x9F //         \    |
	CodeMaximumConnectTime                 ReasonCode = 0xA0 //         \    |
	CodeSubscriptionIDNotSupported         ReasonCode = 0xA1 //         \    |
	CodeWildcardSubscriptionsNotSupported  ReasonCode = 0xA2 //         \ <--|
)

nolint: golint // V3.1.1 \ V5.0

func (ReasonCode) Desc

func (c ReasonCode) Desc() string

Desc return code description

func (ReasonCode) Error

func (c ReasonCode) Error() string

Error returns the description of the ReturnCode

func (ReasonCode) IsValid

func (c ReasonCode) IsValid() bool

IsValid check either reason code is valid across all MQTT specs

func (ReasonCode) IsValidForType

func (c ReasonCode) IsValidForType(p Type) bool

IsValidForType check either reason code is valid for giver packet type

func (ReasonCode) IsValidV3

func (c ReasonCode) IsValidV3() bool

IsValidV3 check either reason code is valid for MQTT V3.1/V3.1.1 or not

func (ReasonCode) IsValidV5

func (c ReasonCode) IsValidV5() bool

IsValidV5 check either reason code is valid for MQTT V5.0 or not

func (ReasonCode) PacketTypeDir

func (c ReasonCode) PacketTypeDir(p Type) (CodeIssuer, error)

PacketTypeDir check direction of packet type

func (ReasonCode) Value

func (c ReasonCode) Value() byte

Value convert reason code to byte type

type RetainHandling

type RetainHandling uint8

RetainHandling describe how retained messages are handled during subscribe

const (
	// RetainHandlingRetain publish retained messages on subscribe
	RetainHandlingRetain RetainHandling = iota
	// RetainHandlingIfNotExists publish retained messages on subscribe only when it's new subscription to given topic
	RetainHandlingIfNotExists
)

type StringPair

type StringPair struct {
	K string
	V string
}

StringPair user defined properties

type SubAck

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

SubAck A SUBACK Packet is sent by the Server to the Client to confirm receipt and processing of a SUBSCRIBE Packet.

A SUBACK Packet contains a list of return codes, that specify the maximum QoS level that was granted in each Subscription that was requested by the SUBSCRIBE.

func NewSubAck

func NewSubAck(v ProtocolVersion) *SubAck

NewSubAck creates a new SUBACK packet

func (*SubAck) AddReturnCode

func (msg *SubAck) AddReturnCode(ret ReasonCode) error

AddReturnCode adds a single QoS return value.

func (*SubAck) AddReturnCodes

func (msg *SubAck) AddReturnCodes(ret []ReasonCode) error

AddReturnCodes sets the list of QoS returns from the subscriptions sent in the SUBSCRIBE message. An error is returned if any of the QoS values are not valid.

func (*SubAck) Desc

func (h *SubAck) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*SubAck) Encode

func (h *SubAck) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*SubAck) Flags

func (h *SubAck) Flags() byte

Flags returns the fixed header flags for this message.

func (*SubAck) ID

func (h *SubAck) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*SubAck) Name

func (h *SubAck) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*SubAck) PropertiesDiscard

func (h *SubAck) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*SubAck) PropertyForEach

func (h *SubAck) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*SubAck) PropertyGet

func (h *SubAck) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*SubAck) PropertySet

func (h *SubAck) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*SubAck) RemainingLength

func (h *SubAck) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*SubAck) ReturnCodes

func (msg *SubAck) ReturnCodes() []ReasonCode

ReturnCodes returns the list of QoS returns from the subscriptions sent in the SUBSCRIBE message.

func (*SubAck) SetPacketID

func (msg *SubAck) SetPacketID(v IDType)

SetPacketID sets the ID of the packet.

func (*SubAck) SetVersion

func (h *SubAck) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*SubAck) Size

func (h *SubAck) Size() (int, error)

Size of message

func (*SubAck) Type

func (h *SubAck) Type() Type

Type returns the MessageType of the Message

func (*SubAck) Version

func (h *SubAck) Version() ProtocolVersion

Version protocol version used by packet

type Subscribe

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

Subscribe The SUBSCRIBE Packet is sent from the Client to the Server to create one or more Subscriptions. Each Subscription registers a Client’s interest in one or more Topics. The Server sends PUBLISH Packets to the Client in order to forward Application Messages that were published to Topics that match these Subscriptions. The SUBSCRIBE Packet also specifies (for each Subscription) the maximum QoS with which the Server can send Application Messages to the Client.

func NewSubscribe

func NewSubscribe(v ProtocolVersion) *Subscribe

NewSubscribe creates a new SUBSCRIBE packet

func (*Subscribe) AddTopic

func (msg *Subscribe) AddTopic(topic *Topic) error

AddTopic adds a single topic to the message, along with the corresponding QoS. An error is returned if QoS is invalid.

func (*Subscribe) Desc

func (h *Subscribe) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*Subscribe) Encode

func (h *Subscribe) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*Subscribe) Flags

func (h *Subscribe) Flags() byte

Flags returns the fixed header flags for this message.

func (*Subscribe) ForEachTopic

func (msg *Subscribe) ForEachTopic(fn func(*Topic) error) error

ForEachTopic loop through list of topics

func (*Subscribe) ID

func (h *Subscribe) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*Subscribe) Name

func (h *Subscribe) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*Subscribe) PropertiesDiscard

func (h *Subscribe) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*Subscribe) PropertyForEach

func (h *Subscribe) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*Subscribe) PropertyGet

func (h *Subscribe) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*Subscribe) PropertySet

func (h *Subscribe) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*Subscribe) RemainingLength

func (h *Subscribe) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*Subscribe) SetPacketID

func (msg *Subscribe) SetPacketID(v IDType)

SetPacketID sets the ID of the packet.

func (*Subscribe) SetVersion

func (h *Subscribe) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*Subscribe) Size

func (h *Subscribe) Size() (int, error)

Size of message

func (*Subscribe) Type

func (h *Subscribe) Type() Type

Type returns the MessageType of the Message

func (*Subscribe) Version

func (h *Subscribe) Version() ProtocolVersion

Version protocol version used by packet

type SubscriptionOptions

type SubscriptionOptions byte

SubscriptionOptions as per [MQTT-3.8.3.1]

func (SubscriptionOptions) NL

func (s SubscriptionOptions) NL() bool

NL No Local option

if true Application Messages MUST NOT be forwarded to a connection with a ClientID equal
to the ClientID of the publishing connection

V5.0 ONLY

func (SubscriptionOptions) QoS

func (s SubscriptionOptions) QoS() QosType

QoS quality of service

func (SubscriptionOptions) RAP

func (s SubscriptionOptions) RAP() bool

RAP Retain As Published option

true: Application Messages forwarded using this subscription keep the RETAIN flag they were published with
false : Application Messages forwarded using this subscription have the RETAIN flag set to 0.

Retained messages sent when the subscription is established have the RETAIN flag set to 1. V5.0 ONLY

func (SubscriptionOptions) Raw

func (s SubscriptionOptions) Raw() byte

Raw just return byte

func (SubscriptionOptions) RetainHandling

func (s SubscriptionOptions) RetainHandling() RetainHandling

RetainHandling specifies whether retained messages are sent when the subscription is established. This does not affect the sending of retained messages at any point after the subscribe. If there are no retained messages matching the Topic Filter, all of these values act the same. The values are:

0 = Send retained messages at the time of the subscribe
1 = Send retained messages at subscribe only if the subscription does not currently exist
2 = Do not send retained messages at the time of the subscribe

V5.0 ONLY

type Topic

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

Topic container encapsulates topic verification

func NewSubscribeTopic

func NewSubscribeTopic(topic []byte, ops SubscriptionOptions) (*Topic, error)

NewSubscribeTopic allocate new subscription topic

func NewTopic

func NewTopic(topic []byte) (*Topic, error)

NewTopic allocate new topic

func (*Topic) DollarPrefix

func (t *Topic) DollarPrefix() string

DollarPrefix return $ prefix if not exist returns empty string

func (*Topic) Filter

func (t *Topic) Filter() string

Filter return topic filter

func (*Topic) Full

func (t *Topic) Full() string

Full return raw topic

func (*Topic) Ops

func (t *Topic) Ops() SubscriptionOptions

Ops return subscription options

func (*Topic) ShareName

func (t *Topic) ShareName() string

ShareName return share name if not exists returns empty string

func (*Topic) Topic

func (t *Topic) Topic() (string, SubscriptionOptions)

Topic return filter and subscription options

type TopicQos

type TopicQos map[string]SubscriptionOptions

TopicQos map containing topics as a keys with respective subscription options as value

type Type

type Type byte

Type is the type representing the MQTT packet types. In the MQTT spec, MQTT control packet type is represented as a 4-bit unsigned value.

const (
	// RESERVED is a reserved value and should be considered an invalid message type
	RESERVED Type = iota

	// CONNECT Client request to connect to Server
	// version: v3.1, v3.1.1, v5.0
	//      Dir: Client to Server
	CONNECT

	// CONNACK Accept acknowledgement
	// version: v3.1, v3.1.1, v5.0
	//      Dir: Server to Client
	CONNACK

	// PUBLISH Client to Server, or Server to Client. Publish message.
	PUBLISH

	// PUBACK Client to Server, or Server to Client. Publish acknowledgment for
	// QoS 1 messages.
	PUBACK

	// PUBREC Client to Server, or Server to Client. Publish received for QoS 2 messages.
	// Assured delivery part 1.
	PUBREC

	// PUBREL Client to Server, or Server to Client. Publish release for QoS 2 messages.
	// Assured delivery part 1.
	PUBREL

	// PUBCOMP Client to Server, or Server to Client. Publish complete for QoS 2 messages.
	// Assured delivery part 3.
	PUBCOMP

	// SUBSCRIBE Client to Server. Client subscribe request.
	SUBSCRIBE

	// SUBACK Server to Client. Subscribe acknowledgement.
	SUBACK

	// UNSUBSCRIBE Client to Server. Unsubscribe request.
	UNSUBSCRIBE

	// UNSUBACK Server to Client. Unsubscribe acknowlegment.
	UNSUBACK

	// PINGREQ Client to Server. PING request.
	PINGREQ

	// PINGRESP Server to Client. PING response.
	PINGRESP

	// DISCONNECT Client to Server. Client is disconnecting.
	DISCONNECT

	// AUTH is a reserved value and should be considered an invalid message type.
	AUTH
)

func (Type) DefaultFlags

func (t Type) DefaultFlags() byte

DefaultFlags returns the default flag values for the message type, as defined by the MQTT spec.

func (Type) Desc

func (t Type) Desc() string

Desc returns the description of the message type. It is statically defined (copied from MQTT spec) and cannot be changed.

func (Type) Name

func (t Type) Name() string

Name returns the name of the message type. It should correspond to one of the constant values defined for MessageType. It is statically defined and cannot be changed.

func (Type) Valid

func (t Type) Valid(v ProtocolVersion) (bool, error)

Valid returns a boolean indicating whether the message type is valid or not.

type UnSubAck

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

UnSubAck The UNSUBACK Packet is sent by the Server to the Client to confirm receipt of an UNSUBSCRIBE Packet.

func NewUnSubAck

func NewUnSubAck(v ProtocolVersion) *UnSubAck

NewUnSubAck creates a new UNSUBACK packet

func (*UnSubAck) AddReturnCode

func (msg *UnSubAck) AddReturnCode(ret ReasonCode) error

AddReturnCode adds a single QoS return value.

func (*UnSubAck) AddReturnCodes

func (msg *UnSubAck) AddReturnCodes(ret []ReasonCode) error

AddReturnCodes sets the list of QoS returns from the subscriptions sent in the SUBSCRIBE message. An error is returned if any of the QoS values are not valid.

func (*UnSubAck) Desc

func (h *UnSubAck) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*UnSubAck) Encode

func (h *UnSubAck) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*UnSubAck) Flags

func (h *UnSubAck) Flags() byte

Flags returns the fixed header flags for this message.

func (*UnSubAck) ID

func (h *UnSubAck) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*UnSubAck) Name

func (h *UnSubAck) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*UnSubAck) PropertiesDiscard

func (h *UnSubAck) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*UnSubAck) PropertyForEach

func (h *UnSubAck) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*UnSubAck) PropertyGet

func (h *UnSubAck) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*UnSubAck) PropertySet

func (h *UnSubAck) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*UnSubAck) RemainingLength

func (h *UnSubAck) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*UnSubAck) ReturnCodes

func (msg *UnSubAck) ReturnCodes() []ReasonCode

ReturnCodes returns the list of QoS returns from the subscriptions sent in the SUBSCRIBE message.

func (*UnSubAck) SetPacketID

func (msg *UnSubAck) SetPacketID(v IDType)

SetPacketID sets the ID of the packet.

func (*UnSubAck) SetVersion

func (h *UnSubAck) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*UnSubAck) Size

func (h *UnSubAck) Size() (int, error)

Size of message

func (*UnSubAck) Type

func (h *UnSubAck) Type() Type

Type returns the MessageType of the Message

func (*UnSubAck) Version

func (h *UnSubAck) Version() ProtocolVersion

Version protocol version used by packet

type UnSubscribe

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

UnSubscribe An UNSUBSCRIBE Packet is sent by the Client to the Server, to unsubscribe from topics.

func NewUnSubscribe

func NewUnSubscribe(v ProtocolVersion) *UnSubscribe

NewUnSubscribe creates a new UNSUBSCRIBE packet

func (*UnSubscribe) AddTopic

func (msg *UnSubscribe) AddTopic(topic *Topic) error

AddTopic adds a single topic to the message.

func (*UnSubscribe) Desc

func (h *UnSubscribe) Desc() string

Desc returns a string description of the message type. For example, a CONNECT message would return "Client request to connect to Server." These descriptions are statically defined (copied from the MQTT spec) and cannot be changed.

func (*UnSubscribe) Encode

func (h *UnSubscribe) Encode(to []byte) (int, error)

Encode packet into buffer, Size() should be called to determine expected buffer size

func (*UnSubscribe) Flags

func (h *UnSubscribe) Flags() byte

Flags returns the fixed header flags for this message.

func (*UnSubscribe) ForEachTopic

func (msg *UnSubscribe) ForEachTopic(fn func(*Topic) error) error

ForEachTopic iterate over all sent by the Client if fn return error iteration stopped

func (*UnSubscribe) ID

func (h *UnSubscribe) ID() (IDType, error)

ID packet id, valid only for PUBLISH (QoS 1/2), PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK

func (*UnSubscribe) Name

func (h *UnSubscribe) Name() string

Name returns a string representation of the message type. Examples include "PUBLISH", "SUBSCRIBE", and others. This is statically defined for each of the message types and cannot be changed.

func (*UnSubscribe) PropertiesDiscard

func (h *UnSubscribe) PropertiesDiscard()

PropertiesDiscard discard all previously set properties

func (*UnSubscribe) PropertyForEach

func (h *UnSubscribe) PropertyForEach(f func(PropertyID, PropertyToType)) error

PropertyForEach iterate over properties

func (*UnSubscribe) PropertyGet

func (h *UnSubscribe) PropertyGet(id PropertyID) PropertyToType

PropertyGet get property value, nil if not present

func (*UnSubscribe) PropertySet

func (h *UnSubscribe) PropertySet(id PropertyID, val interface{}) error

PropertySet set value

func (*UnSubscribe) RemainingLength

func (h *UnSubscribe) RemainingLength() int32

RemainingLength returns the length of the non-fixed-header part of the message.

func (*UnSubscribe) SetPacketID

func (msg *UnSubscribe) SetPacketID(v IDType)

SetPacketID sets the ID of the packet.

func (*UnSubscribe) SetVersion

func (h *UnSubscribe) SetVersion(v ProtocolVersion)

SetVersion protocol version used to encode packet

func (*UnSubscribe) Size

func (h *UnSubscribe) Size() (int, error)

Size of message

func (*UnSubscribe) Type

func (h *UnSubscribe) Type() Type

Type returns the MessageType of the Message

func (*UnSubscribe) Version

func (h *UnSubscribe) Version() ProtocolVersion

Version protocol version used by packet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL