paho

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: EPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrManualAcknowledgmentDisabled = errors.New("manual acknowledgments disabled")
)
View Source
var ErrPacketNotFound = errors.New("packet not found")
View Source
var ErrorMidsExhausted = errors.New("all message ids in use")

ErrorMidsExhausted is returned from Request() when there are no free message ids to be used.

Functions

func BoolToByte

func BoolToByte(b bool) *byte

BoolToByte is a helper function that take a bool and returns a pointer to a byte of value 1 if true or 0 if false

func Byte

func Byte(b byte) *byte

Byte is a helper function that take a byte and returns a pointer to a byte of that value

func Uint16

func Uint16(u uint16) *uint16

Uint16 is a helper function that take a uint16 and returns a pointer to a uint16 of that value

func Uint32

func Uint32(u uint32) *uint32

Uint32 is a helper function that take a uint32 and returns a pointer to a uint32 of that value

Types

type Auth

type Auth struct {
	Properties *AuthProperties
	ReasonCode byte
}

Auth is a representation of the MQTT Auth packet

func AuthFromPacketAuth

func AuthFromPacketAuth(a *packets.Auth) *Auth

AuthFromPacketAuth takes a packets library Auth and returns a paho library Auth

func (*Auth) InitProperties

func (a *Auth) InitProperties(p *packets.Properties)

InitProperties is a function that takes a lower level Properties struct and completes the properties of the Auth on which it is called

func (*Auth) Packet

func (a *Auth) Packet() *packets.Auth

Packet returns a packets library Auth from the paho Auth on which it is called

type AuthProperties

type AuthProperties struct {
	AuthData     []byte
	AuthMethod   string
	ReasonString string
	User         UserProperties
}

AuthProperties is a struct of the properties that can be set for a Auth packet

type AuthResponse

type AuthResponse struct {
	Properties *AuthProperties
	ReasonCode byte
	Success    bool
}

AuthResponse is a represenation of the response to an Auth packet

func AuthResponseFromPacketAuth

func AuthResponseFromPacketAuth(a *packets.Auth) *AuthResponse

AuthResponseFromPacketAuth takes a packets library Auth and returns a paho library AuthResponse

func AuthResponseFromPacketDisconnect

func AuthResponseFromPacketDisconnect(d *packets.Disconnect) *AuthResponse

AuthResponseFromPacketDisconnect takes a packets library Disconnect and returns a paho library AuthResponse

type Auther

type Auther interface {
	Authenticate(*Auth) *Auth
	Authenticated()
}

Auther is the interface for something that implements the extended authentication flows in MQTT v5

type CPContext

type CPContext struct {
	Context context.Context
	Return  chan packets.ControlPacket
}

CPContext is the struct that is used to return responses to ControlPackets that have them, eg: the suback to a subscribe. The response packet is send down the Return channel and the Context is used to track timeouts.

type Client

type Client struct {
	ClientConfig
	// contains filtered or unexported fields
}

Client is the struct representing an MQTT client

func NewClient

func NewClient(conf ClientConfig) *Client

NewClient is used to create a new default instance of an MQTT client. It returns a pointer to the new client instance. The default client uses the provided PingHandler, MessageID and StandardRouter implementations, and a noop Persistence. These should be replaced if desired before the client is connected. client.Conn *MUST* be set to an already connected net.Conn before Connect() is called.

func (*Client) Ack

func (c *Client) Ack(pb *Publish) error

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context, a *Auth) (*AuthResponse, error)

Authenticate is used to initiate a reauthentication of credentials with the server. This function sends the initial Auth packet to start the reauthentication then relies on the client AuthHandler managing any further requests from the server until either a successful Auth packet is passed back, or a Disconnect is received.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, cp *Connect) (*Connack, error)

Connect is used to connect the client to a server. It presumes that the Client instance already has a working network connection. The function takes a pre-prepared Connect packet, and uses that to establish an MQTT connection. Assuming the connection completes successfully the rest of the client is initiated and the Connack returned. Otherwise the failure Connack (if there is one) is returned along with an error indicating the reason for the failure to connect.

func (*Client) Disconnect

func (c *Client) Disconnect(d *Disconnect) error

Disconnect is used to send a Disconnect packet to the MQTT server Whether or not the attempt to send the Disconnect packet fails (and if it does this function returns any error) the network connection is closed.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, p *Publish) (*PublishResponse, error)

Publish is used to send a publication to the MQTT server. It is passed a pre-prepared Publish packet and blocks waiting for the appropriate response, or for the timeout to fire. Any response message is returned from the function, along with any errors.

func (*Client) SetDebugLogger

func (c *Client) SetDebugLogger(l Logger)

SetDebugLogger takes an instance of the paho Logger interface and sets it to be used by the debug log endpoint

func (*Client) SetErrorLogger

func (c *Client) SetErrorLogger(l Logger)

SetErrorLogger takes an instance of the paho Logger interface and sets it to be used by the error log endpoint

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, s *Subscribe) (*Suback, error)

Subscribe is used to send a Subscription request to the MQTT server. It is passed a pre-prepared Subscribe packet and blocks waiting for a response Suback, or for the timeout to fire. Any response Suback is returned from the function, along with any errors.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, u *Unsubscribe) (*Unsuback, error)

Unsubscribe is used to send an Unsubscribe request to the MQTT server. It is passed a pre-prepared Unsubscribe packet and blocks waiting for a response Unsuback, or for the timeout to fire. Any response Unsuback is returned from the function, along with any errors.

type ClientConfig

type ClientConfig struct {
	ClientID string
	// Conn is the connection to broker.
	// BEWARE that most wrapped net.Conn implementations like tls.Conn are
	// not thread safe for writing. To fix, use packets.NewThreadSafeConn
	// wrapper or extend the custom net.Conn struct with sync.Locker.
	Conn          net.Conn
	MIDs          MIDService
	AuthHandler   Auther
	PingHandler   Pinger
	Router        Router
	Persistence   Persistence
	PacketTimeout time.Duration
	// OnServerDisconnect is called only when a packets.DISCONNECT is received from server
	OnServerDisconnect func(*Disconnect)
	// OnClientError is for example called on net.Error
	OnClientError func(error)
	// PublishHook allows a user provided function to be called before
	// a Publish packet is sent allowing it to inspect or modify the
	// Publish, an example of the utility of this is provided in the
	// Topic Alias Handler extension which will automatically assign
	// and use topic alias values rather than topic strings.
	PublishHook func(*Publish)
	// EnableManualAcknowledgment is used to control the acknowledgment of packets manually.
	// BEWARE that the MQTT specs require clients to send acknowledgments in the order in which the corresponding
	// PUBLISH packets were received.
	// Consider the following scenario: the client receives packets 1,2,3,4
	// If you acknowledge 3 first, no ack is actually sent to the server but it's buffered until also 1 and 2
	// are acknowledged.
	EnableManualAcknowledgment bool
	// SendAcksInterval is used only when EnableManualAcknowledgment is true
	// it determines how often the client tries to send a batch of acknowledgments in the right order to the server.
	SendAcksInterval time.Duration
}

ClientConfig are the user configurable options for the client, an instance of this struct is passed into NewClient(), not all options are required to be set, defaults are provided for Persistence, MIDs, PingHandler, PacketTimeout and Router.

type CommsProperties

type CommsProperties struct {
	MaximumPacketSize    uint32
	ReceiveMaximum       uint16
	TopicAliasMaximum    uint16
	MaximumQoS           byte
	RetainAvailable      bool
	WildcardSubAvailable bool
	SubIDAvailable       bool
	SharedSubAvailable   bool
}

CommsProperties is a struct of the communication properties that may be set by the server in the Connack and that the client needs to be aware of for future subscribes/publishes

type Connack

type Connack struct {
	Properties     *ConnackProperties
	ReasonCode     byte
	SessionPresent bool
}

Connack is a representation of the MQTT Connack packet

func ConnackFromPacketConnack

func ConnackFromPacketConnack(c *packets.Connack) *Connack

ConnackFromPacketConnack takes a packets library Connack and returns a paho library Connack

func (*Connack) InitProperties

func (c *Connack) InitProperties(p *packets.Properties)

InitProperties is a function that takes a lower level Properties struct and completes the properties of the Connack on which it is called

func (*Connack) String added in v0.10.7

func (c *Connack) String() string

String implement fmt.Stringer (mainly to simplify debugging)

type ConnackProperties

type ConnackProperties struct {
	SessionExpiryInterval *uint32
	AuthData              []byte
	AuthMethod            string
	ResponseInfo          string
	ServerReference       string
	ReasonString          string
	AssignedClientID      string
	MaximumPacketSize     *uint32
	ReceiveMaximum        *uint16
	TopicAliasMaximum     *uint16
	ServerKeepAlive       *uint16
	MaximumQoS            *byte
	User                  UserProperties
	WildcardSubAvailable  bool
	SubIDAvailable        bool
	SharedSubAvailable    bool
	RetainAvailable       bool
}

ConnackProperties is a struct of the properties that can be set for a Connack packet

func (*ConnackProperties) String added in v0.10.7

func (p *ConnackProperties) String() string

String implement fmt.Stringer (mainly to simplify debugging)

type Connect

type Connect struct {
	Password       []byte
	Username       string
	ClientID       string
	Properties     *ConnectProperties
	WillMessage    *WillMessage
	WillProperties *WillProperties
	KeepAlive      uint16
	CleanStart     bool
	UsernameFlag   bool
	PasswordFlag   bool
}

Connect is a representation of the MQTT Connect packet

func ConnectFromPacketConnect

func ConnectFromPacketConnect(p *packets.Connect) *Connect

ConnectFromPacketConnect takes a packets library Connect and returns a paho library Connect

func (*Connect) InitProperties

func (c *Connect) InitProperties(p *packets.Properties)

InitProperties is a function that takes a lower level Properties struct and completes the properties of the Connect on which it is called

func (*Connect) InitWillProperties

func (c *Connect) InitWillProperties(p *packets.Properties)

InitWillProperties is a function that takes a lower level Properties struct and completes the properties of the Will in the Connect on which it is called

func (*Connect) Packet

func (c *Connect) Packet() *packets.Connect

Packet returns a packets library Connect from the paho Connect on which it is called

type ConnectProperties

type ConnectProperties struct {
	AuthData              []byte
	AuthMethod            string
	SessionExpiryInterval *uint32
	WillDelayInterval     *uint32
	ReceiveMaximum        *uint16
	TopicAliasMaximum     *uint16
	MaximumQOS            *byte
	MaximumPacketSize     *uint32
	User                  UserProperties
	RequestProblemInfo    bool
	RequestResponseInfo   bool
}

ConnectProperties is a struct of the properties that can be set for a Connect packet

type Disconnect

type Disconnect struct {
	Properties *DisconnectProperties
	ReasonCode byte
}

Disconnect is a representation of the MQTT Disconnect packet

func DisconnectFromPacketDisconnect

func DisconnectFromPacketDisconnect(p *packets.Disconnect) *Disconnect

DisconnectFromPacketDisconnect takes a packets library Disconnect and returns a paho library Disconnect

func (*Disconnect) InitProperties

func (d *Disconnect) InitProperties(p *packets.Properties)

InitProperties is a function that takes a lower level Properties struct and completes the properties of the Disconnect on which it is called

func (*Disconnect) Packet

func (d *Disconnect) Packet() *packets.Disconnect

Packet returns a packets library Disconnect from the paho Disconnect on which it is called

type DisconnectProperties

type DisconnectProperties struct {
	ServerReference       string
	ReasonString          string
	SessionExpiryInterval *uint32
	User                  UserProperties
}

DisconnectProperties is a struct of the properties that can be set for a Disconnect packet

type Logger

type Logger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger interface allows implementations to provide to this package any object that implements the methods defined in it.

type MIDService

type MIDService interface {
	Request(*CPContext) (uint16, error)
	Get(uint16) *CPContext
	Free(uint16)
	Clear()
}

MIDService defines the interface for a struct that handles the relationship between message ids and CPContexts Request() takes a *CPContext and returns a uint16 that is the messageid that should be used by the code that called Request() Get() takes a uint16 that is a messageid and returns the matching *CPContext that the MIDService has associated with that messageid Free() takes a uint16 that is a messageid and instructs the MIDService to mark that messageid as available for reuse Clear() resets the internal state of the MIDService

type MIDs

type MIDs struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MIDs is the default MIDService provided by this library. It uses a slice of *CPContext to track responses to messages with a messageid tracking the last used message id

func (*MIDs) Clear

func (m *MIDs) Clear()

Clear is the library provided MIDService's implementation of the required interface function()

func (*MIDs) Free

func (m *MIDs) Free(i uint16)

Free is the library provided MIDService's implementation of the required interface function()

func (*MIDs) Get

func (m *MIDs) Get(i uint16) *CPContext

Get is the library provided MIDService's implementation of the required interface function()

func (*MIDs) Request

func (m *MIDs) Request(c *CPContext) (uint16, error)

Request is the library provided MIDService's implementation of the required interface function()

type MQTTVersion

type MQTTVersion byte
const (
	MQTTv311 MQTTVersion = 4
	MQTTv5   MQTTVersion = 5
)

type MemoryPersistence

type MemoryPersistence struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MemoryPersistence is an implementation of a Persistence that stores the ControlPackets in memory using a map

func (*MemoryPersistence) All

All is the library provided MemoryPersistence's implementation of the required interface function()

func (*MemoryPersistence) Close

func (m *MemoryPersistence) Close()

Close is the library provided MemoryPersistence's implementation of the required interface function()

func (*MemoryPersistence) Delete

func (m *MemoryPersistence) Delete(id uint16)

Delete is the library provided MemoryPersistence's implementation of the required interface function()

func (*MemoryPersistence) Get

Get is the library provided MemoryPersistence's implementation of the required interface function()

func (*MemoryPersistence) Open

func (m *MemoryPersistence) Open()

Open is the library provided MemoryPersistence's implementation of the required interface function()

func (*MemoryPersistence) Put

Put is the library provided MemoryPersistence's implementation of the required interface function()

func (*MemoryPersistence) Reset

func (m *MemoryPersistence) Reset()

Reset is the library provided MemoryPersistence's implementation of the required interface function()

type MessageHandler

type MessageHandler func(*Publish)

MessageHandler is a type for a function that is invoked by a Router when it has received a Publish.

type NOOPLogger

type NOOPLogger struct{}

NOOPLogger implements the logger that does not perform any operation by default. This allows us to efficiently discard the unwanted messages.

func (NOOPLogger) Printf

func (NOOPLogger) Printf(format string, v ...interface{})

Printf is the library provided NOOPLogger's implementation of the required interface function(){}

func (NOOPLogger) Println

func (NOOPLogger) Println(v ...interface{})

Println is the library provided NOOPLogger's implementation of the required interface function()

type Persistence

type Persistence interface {
	Open()
	Put(uint16, packets.ControlPacket)
	Get(uint16) packets.ControlPacket
	All() []packets.ControlPacket
	Delete(uint16)
	Close()
	Reset()
}

Persistence is an interface of the functions for a struct that is used to persist ControlPackets. Open() is an initialiser to prepare the Persistence for use Put() takes a uint16 which is a messageid and a ControlPacket to persist against that messageid Get() takes a uint16 which is a messageid and returns the persisted ControlPacket from the Persistence for that messageid All() returns a slice of all ControlPackets persisted Delete() takes a uint16 which is a messageid and deletes the associated stored ControlPacket from the Persistence Close() closes the Persistence Reset() clears the Persistence and prepares it to be reused

type PingFailHandler

type PingFailHandler func(error)

PingFailHandler is a type for the function that is invoked when we have sent a Pingreq to the server and not received a Pingresp within 1.5x our pingtimeout

type PingHandler

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

PingHandler is the library provided default Pinger

func DefaultPingerWithCustomFailHandler

func DefaultPingerWithCustomFailHandler(pfh PingFailHandler) *PingHandler

DefaultPingerWithCustomFailHandler returns an instance of the default Pinger but with a custom PingFailHandler that is called when the client has not received a response to a PingRequest within the appropriate amount of time

func (*PingHandler) PingResp

func (p *PingHandler) PingResp()

PingResp is the library provided Pinger's implementation of the required interface function()

func (*PingHandler) SetDebug

func (p *PingHandler) SetDebug(l Logger)

SetDebug sets the logger l to be used for printing debug information for the pinger

func (*PingHandler) Start

func (p *PingHandler) Start(c net.Conn, pt time.Duration)

Start is the library provided Pinger's implementation of the required interface function()

func (*PingHandler) Stop

func (p *PingHandler) Stop()

Stop is the library provided Pinger's implementation of the required interface function()

type Pinger

type Pinger interface {
	Start(net.Conn, time.Duration)
	Stop()
	PingResp()
	SetDebug(Logger)
}

Pinger is an interface of the functions for a struct that is used to manage sending PingRequests and responding to PingResponses Start() takes a net.Conn which is a connection over which an MQTT session has already been established, and a time.Duration of the keepalive setting passed to the server when the MQTT session was established. Stop() is used to stop the Pinger PingResp() is the function that is called by the Client when a PingResponse is received SetDebug() is used to pass in a Logger to be used to log debug information, for example sharing a logger with the main client

type Publish

type Publish struct {
	PacketID   uint16
	QoS        byte
	Retain     bool
	Topic      string
	Properties *PublishProperties
	Payload    []byte
}

Publish is a representation of the MQTT Publish packet

func PublishFromPacketPublish

func PublishFromPacketPublish(p *packets.Publish) *Publish

PublishFromPacketPublish takes a packets library Publish and returns a paho library Publish

func (*Publish) InitProperties

func (p *Publish) InitProperties(prop *packets.Properties)

InitProperties is a function that takes a lower level Properties struct and completes the properties of the Publish on which it is called

func (*Publish) Packet

func (p *Publish) Packet() *packets.Publish

Packet returns a packets library Publish from the paho Publish on which it is called

func (*Publish) String

func (p *Publish) String() string

type PublishProperties

type PublishProperties struct {
	CorrelationData        []byte
	ContentType            string
	ResponseTopic          string
	PayloadFormat          *byte
	MessageExpiry          *uint32
	SubscriptionIdentifier *int
	TopicAlias             *uint16
	User                   UserProperties
}

PublishProperties is a struct of the properties that can be set for a Publish packet

type PublishResponse

type PublishResponse struct {
	Properties *PublishResponseProperties
	ReasonCode byte
}

PublishResponse is a generic representation of a response to a QoS1 or QoS2 Publish

func PublishResponseFromPuback

func PublishResponseFromPuback(pa *packets.Puback) *PublishResponse

PublishResponseFromPuback takes a packets library Puback and returns a paho library PublishResponse

func PublishResponseFromPubcomp

func PublishResponseFromPubcomp(pc *packets.Pubcomp) *PublishResponse

PublishResponseFromPubcomp takes a packets library Pubcomp and returns a paho library PublishResponse

func PublishResponseFromPubrec

func PublishResponseFromPubrec(pr *packets.Pubrec) *PublishResponse

PublishResponseFromPubrec takes a packets library Pubrec and returns a paho library PublishResponse

type PublishResponseProperties

type PublishResponseProperties struct {
	ReasonString string
	User         UserProperties
}

PublishResponseProperties is the properties associated with a response to a QoS1 or QoS2 Publish

type Router

type Router interface {
	RegisterHandler(string, MessageHandler)
	UnregisterHandler(string)
	Route(*packets.Publish)
	SetDebugLogger(Logger)
}

Router is an interface of the functions for a struct that is used to handle invoking MessageHandlers depending on the the topic the message was published on. RegisterHandler() takes a string of the topic, and a MessageHandler to be invoked when Publishes are received that match that topic UnregisterHandler() takes a string of the topic to remove MessageHandlers for Route() takes a Publish message and determines which MessageHandlers should be invoked

type SingleHandlerRouter

type SingleHandlerRouter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SingleHandlerRouter is a library provided implementation of a Router that stores only a single MessageHandler and invokes this MessageHandler for all received Publishes

func NewSingleHandlerRouter

func NewSingleHandlerRouter(h MessageHandler) *SingleHandlerRouter

NewSingleHandlerRouter instantiates and returns an instance of a SingleHandlerRouter

func (*SingleHandlerRouter) RegisterHandler

func (s *SingleHandlerRouter) RegisterHandler(topic string, h MessageHandler)

RegisterHandler is the library provided SingleHandlerRouter's implementation of the required interface function()

func (*SingleHandlerRouter) Route

func (s *SingleHandlerRouter) Route(pb *packets.Publish)

Route is the library provided SingleHandlerRouter's implementation of the required interface function()

func (*SingleHandlerRouter) SetDebugLogger

func (s *SingleHandlerRouter) SetDebugLogger(l Logger)

SetDebugLogger sets the logger l to be used for printing debug information for the router

func (*SingleHandlerRouter) UnregisterHandler

func (s *SingleHandlerRouter) UnregisterHandler(topic string)

UnregisterHandler is the library provided SingleHandlerRouter's implementation of the required interface function()

type StandardRouter

type StandardRouter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StandardRouter is a library provided implementation of a Router that allows for unique and multiple MessageHandlers per topic

func NewStandardRouter

func NewStandardRouter() *StandardRouter

NewStandardRouter instantiates and returns an instance of a StandardRouter

func (*StandardRouter) RegisterHandler

func (r *StandardRouter) RegisterHandler(topic string, h MessageHandler)

RegisterHandler is the library provided StandardRouter's implementation of the required interface function()

func (*StandardRouter) Route

func (r *StandardRouter) Route(pb *packets.Publish)

Route is the library provided StandardRouter's implementation of the required interface function()

func (*StandardRouter) SetDebugLogger

func (r *StandardRouter) SetDebugLogger(l Logger)

SetDebugLogger sets the logger l to be used for printing debug information for the router

func (*StandardRouter) UnregisterHandler

func (r *StandardRouter) UnregisterHandler(topic string)

UnregisterHandler is the library provided StandardRouter's implementation of the required interface function()

type Suback

type Suback struct {
	Properties *SubackProperties
	Reasons    []byte
}

Suback is a representation of an MQTT suback packet

func SubackFromPacketSuback

func SubackFromPacketSuback(s *packets.Suback) *Suback

SubackFromPacketSuback takes a packets library Suback and returns a paho library Suback

func (*Suback) Packet

func (s *Suback) Packet() *packets.Suback

Packet returns a packets library Suback from the paho Suback on which it is called

type SubackProperties

type SubackProperties struct {
	ReasonString string
	User         UserProperties
}

SubackProperties is a struct of the properties that can be set for a Suback packet

type Subscribe

type Subscribe struct {
	Properties    *SubscribeProperties
	Subscriptions []SubscribeOptions
}

Subscribe is a representation of a MQTT subscribe packet

func (*Subscribe) InitProperties

func (s *Subscribe) InitProperties(prop *packets.Properties)

InitProperties is a function that takes a packet library Properties struct and completes the properties of the Subscribe on which it is called

func (*Subscribe) Packet

func (s *Subscribe) Packet() *packets.Subscribe

Packet returns a packets library Subscribe from the paho Subscribe on which it is called

func (*Subscribe) PacketSubOptionsFromSubscribeOptions

func (s *Subscribe) PacketSubOptionsFromSubscribeOptions() []packets.SubOptions

PacketSubOptionsFromSubscribeOptions returns a slice of packet library SubOptions for the paho Subscribe on which it is called

type SubscribeOptions

type SubscribeOptions struct {
	Topic             string
	QoS               byte
	RetainHandling    byte
	NoLocal           bool
	RetainAsPublished bool
}

SubscribeOptions is the struct representing the options for a subscription

type SubscribeProperties

type SubscribeProperties struct {
	SubscriptionIdentifier *int
	User                   UserProperties
}

SubscribeProperties is a struct of the properties that can be set for a Subscribe packet

type Unsuback

type Unsuback struct {
	Reasons    []byte
	Properties *UnsubackProperties
}

Unsuback is a representation of an MQTT Unsuback packet

func UnsubackFromPacketUnsuback

func UnsubackFromPacketUnsuback(u *packets.Unsuback) *Unsuback

UnsubackFromPacketUnsuback takes a packets library Unsuback and returns a paho library Unsuback

func (*Unsuback) Packet

func (u *Unsuback) Packet() *packets.Unsuback

Packet returns a packets library Unsuback from the paho Unsuback on which it is called

type UnsubackProperties

type UnsubackProperties struct {
	ReasonString string
	User         UserProperties
}

UnsubackProperties is a struct of the properties that can be set for a Unsuback packet

type Unsubscribe

type Unsubscribe struct {
	Topics     []string
	Properties *UnsubscribeProperties
}

Unsubscribe is a representation of an MQTT unsubscribe packet

func (*Unsubscribe) Packet

func (u *Unsubscribe) Packet() *packets.Unsubscribe

Packet returns a packets library Unsubscribe from the paho Unsubscribe on which it is called

type UnsubscribeProperties

type UnsubscribeProperties struct {
	User UserProperties
}

UnsubscribeProperties is a struct of the properties that can be set for a Unsubscribe packet

type UserProperties

type UserProperties []UserProperty

UserProperties is a slice of UserProperty

func UserPropertiesFromPacketUser

func UserPropertiesFromPacketUser(up []packets.User) UserProperties

UserPropertiesFromPacketUser converts a slice of packets.User to an instance of UserProperties for easier consumption within the client library

func (*UserProperties) Add

func (u *UserProperties) Add(key, value string) *UserProperties

Add is a helper function for easily adding a new user property

func (UserProperties) Get

func (u UserProperties) Get(key string) string

Get returns the first entry in the UserProperties that matches key, or an empty string if the key is not found. Note that it is permitted to have multiple entries with the same key, use GetAll if it is expected to have multiple matches

func (UserProperties) GetAll

func (u UserProperties) GetAll(key string) []string

GetAll returns a slice of all entries in the UserProperties that match key, or a nil slice if none were found.

func (UserProperties) ToPacketProperties

func (u UserProperties) ToPacketProperties() []packets.User

ToPacketProperties converts a UserProperties to a slice of packets.User which is used internally in the packets library for user properties

type UserProperty

type UserProperty struct {
	Key, Value string
}

UserProperty is a struct for the user provided values permitted in the properties section

type WillMessage

type WillMessage struct {
	Retain  bool
	QoS     byte
	Topic   string
	Payload []byte
}

WillMessage is a representation of the LWT message that can be sent with the Connect packet

type WillProperties

type WillProperties struct {
	WillDelayInterval *uint32
	PayloadFormat     *byte
	MessageExpiry     *uint32
	ContentType       string
	ResponseTopic     string
	CorrelationData   []byte
	User              UserProperties
}

WillProperties is a struct of the properties that can be set for a Will in a Connect packet

Directories

Path Synopsis
cmd
rpc
extensions
rpc

Jump to

Keyboard shortcuts

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