message

package
v0.0.0-...-d6b2f08 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMessageTypeAvailable

func IsMessageTypeAvailable(v uint8) bool

func IsQoSAvaliable

func IsQoSAvaliable(v uint8) bool

func IsReasonCodeAvailable

func IsReasonCodeAvailable(v uint8) bool

func WithQoS

func WithQoS(qos QoSLevel) option

func WithRetain

func WithRetain() option

func WriteFrame

func WriteFrame(w io.Writer, m Encoder) error

Types

type Auth

type Auth struct {
	*Frame

	ReasonCode ReasonCode
	Property   *AuthProperty
}

func NewAuth

func NewAuth(reason ReasonCode, opts ...option) *Auth

func ParseAuth

func ParseAuth(f *Frame, p []byte) (a *Auth, err error)

func (*Auth) Encode

func (a *Auth) Encode() ([]byte, error)

type AuthProperty

type AuthProperty struct {
	AuthenticationMethod string
	AuthenticationData   []byte
	ReasonString         string
	UserProperty         map[string]string
}

func (*AuthProperty) ToProp

func (a *AuthProperty) ToProp() *Property

type ConnAck

type ConnAck struct {
	*Frame

	Property           *ConnAckProperty
	SessionPresentFlag bool
	ReasonCode         ReasonCode
}

func NewConnAck

func NewConnAck(code ReasonCode, opts ...option) *ConnAck

func ParseConnAck

func ParseConnAck(f *Frame, p []byte) (c *ConnAck, err error)

func (*ConnAck) Encode

func (c *ConnAck) Encode() ([]byte, error)

func (*ConnAck) Validate

func (c *ConnAck) Validate() error

type ConnAckProperty

type ConnAckProperty struct {
	SessionExpiryInterval          uint32
	AssignedClientIdentifier       string
	ServerKeepAlive                uint16
	AuthenticationMethod           string
	AuthenticationData             []byte
	ResponseInformation            string
	ServerReference                string
	ReasonString                   string
	ReceiveMaximum                 uint16
	TopicAliasMaximum              uint16
	MaximumQoS                     uint8
	RetainAvalilable               bool
	UserProperty                   map[string]string
	MaximumPacketSize              uint32
	WildcardSubscriptionAvailable  bool
	SubscrptionIdentifierAvailable bool
	SharedSubscriptionsAvaliable   bool
}

func (*ConnAckProperty) ToProp

func (c *ConnAckProperty) ToProp() *Property

type Connect

type Connect struct {
	*Frame

	// Protocol defintions
	ProtocolName    string
	ProtocolVersion uint8

	// Connection flags
	FlagUsername bool
	FlagPassword bool
	WillRetain   bool
	WillQoS      QoSLevel
	FlagWill     bool
	CleanStart   bool
	KeepAlive    uint16

	// Connection properties
	Property     *ConnectProperty
	WillProperty *WillProperty

	// Payloads
	ClientId    string
	WillTopic   string
	WillPayload string
	Username    string
	Password    []byte
}

func NewConnect

func NewConnect(opts ...option) *Connect

func ParseConnect

func ParseConnect(f *Frame, p []byte) (c *Connect, err error)

func (*Connect) Encode

func (c *Connect) Encode() ([]byte, error)

func (*Connect) Validate

func (c *Connect) Validate() error

type ConnectProperty

type ConnectProperty struct {
	SessionExpiryInterval      uint32
	AuthenticationMethod       string
	AuthenticationData         []byte
	RequestProblemInformation  bool
	RequestResponseInformation bool
	ReceiveMaximum             uint16
	TopicAliasMaximum          uint16
	UserProperty               map[string]string
	MaximumPacketSize          uint32

	// Extra field for application: stack auth challenge data
	ChallengeData interface{}
}

func (*ConnectProperty) ToProp

func (c *ConnectProperty) ToProp() *Property

type Disconnect

type Disconnect struct {
	*Frame

	ReasonCode ReasonCode
	Property   *DisconnectProperty
}

func NewDisconnect

func NewDisconnect(code ReasonCode, opts ...option) *Disconnect

func ParseDisconnect

func ParseDisconnect(f *Frame, p []byte) (d *Disconnect, err error)

func (*Disconnect) Encode

func (d *Disconnect) Encode() ([]byte, error)

type DisconnectProperty

type DisconnectProperty struct {
	SessionExpiryInterval uint32
	ServerReference       string
	ReasonString          string
	UserProperty          map[string]string
}

func (*DisconnectProperty) ToProp

func (d *DisconnectProperty) ToProp() *Property

type Encoder

type Encoder interface {
	Duplicate()
	GetType() MessageType
	Encode() ([]byte, error)
}

type Frame

type Frame struct {
	Type   MessageType
	DUP    bool
	QoS    QoSLevel
	RETAIN bool
	Size   uint64
}

func ReceiveFrame

func ReceiveFrame(r io.Reader) (*Frame, []byte, error)

func (*Frame) Duplicate

func (f *Frame) Duplicate()

func (*Frame) Encode

func (f *Frame) Encode(payload []byte) []byte

func (*Frame) GetType

func (f *Frame) GetType() MessageType

func (*Frame) SetQoS

func (f *Frame) SetQoS(qos QoSLevel)

func (*Frame) SetRetain

func (f *Frame) SetRetain(retain bool)

type MessageType

type MessageType uint8
const (
	CONNECT MessageType
	CONNACK
	PUBLISH
	PUBACK
	PUBREC
	PUBREL
	PUBCOMP
	SUBSCRIBE
	SUBACK
	UNSUBSCRIBE
	UNSUBACK
	PINGREQ
	PINGRESP
	DISCONNECT
	AUTH
)

func (MessageType) String

func (i MessageType) String() string

type Packet

type Packet struct {
	Frame   *Frame
	Payload []byte
}

func NewPacket

func NewPacket(f *Frame, p []byte) *Packet

type PingReq

type PingReq struct {
	*Frame
}

func NewPingReq

func NewPingReq() *PingReq

func ParsePingReq

func ParsePingReq(f *Frame, p []byte) (*PingReq, error)

func (*PingReq) Encode

func (p *PingReq) Encode() ([]byte, error)

type PingResp

type PingResp struct {
	*Frame
}

func NewPingResp

func NewPingResp() *PingResp

func ParsePingResp

func ParsePingResp(f *Frame, p []byte) (*PingResp, error)

func (*PingResp) Encode

func (p *PingResp) Encode() ([]byte, error)

type Property

type Property struct {
	PayloadFormatIndicator         uint8
	MessageExpiryInterval          uint32
	ContentType                    string
	ResponseTopic                  string
	CorrelationData                []byte
	SubscriptionIdentifier         uint64
	SessionExpiryInterval          uint32
	AssignedClientIdentifier       string
	ServerKeepAlive                uint16
	AuthenticationMethod           string
	AuthenticationData             []byte
	RequestProblemInformation      bool
	WillDelayInterval              uint32
	RequestResponseInformation     bool
	ResponseInformation            string
	ServerReference                string
	ReasonString                   string
	ReceiveMaximum                 uint16
	TopicAliasMaximum              uint16
	TopicAlias                     uint16
	MaximumQoS                     uint8
	RetainAvalilable               bool
	UserProperty                   map[string]string
	MaximumPacketSize              uint32
	WildcardSubscriptionAvailable  bool
	SubscrptionIdentifierAvailable bool
	SharedSubscriptionsAvaliable   bool
}

func (*Property) ToAuth

func (p *Property) ToAuth() *AuthProperty

func (*Property) ToConnAck

func (p *Property) ToConnAck() *ConnAckProperty

func (*Property) ToConnect

func (p *Property) ToConnect() *ConnectProperty

func (*Property) ToDisconnect

func (p *Property) ToDisconnect() *DisconnectProperty

func (*Property) ToPubAck

func (p *Property) ToPubAck() *PubAckProperty

func (*Property) ToPubComp

func (p *Property) ToPubComp() *PubCompProperty

func (*Property) ToPubRec

func (p *Property) ToPubRec() *PubRecProperty

func (*Property) ToPubRel

func (p *Property) ToPubRel() *PubRelProperty

func (*Property) ToPublish

func (p *Property) ToPublish() *PublishProperty

func (*Property) ToSubAck

func (p *Property) ToSubAck() *SubAckProperty

func (*Property) ToSubscribe

func (p *Property) ToSubscribe() *SubscribeProperty

func (*Property) ToUnsubAck

func (p *Property) ToUnsubAck() *UnsubAckProperty

func (*Property) ToUnsubscribe

func (p *Property) ToUnsubscribe() *UnsubscribeProperty

func (*Property) ToWill

func (p *Property) ToWill() *WillProperty

type PropertyType

type PropertyType uint8
const (
	PayloadFormatIndicator         PropertyType = 0x01
	MessageExpiryInterval          PropertyType = 0x02
	ContentType                    PropertyType = 0x03
	ResponseTopic                  PropertyType = 0x08
	CorrelationData                PropertyType = 0x09
	SubscriptionIdentifier         PropertyType = 0x0B
	SessionExpiryInterval          PropertyType = 0x11
	AssignedClientIdentifier       PropertyType = 0x12
	ServerKeepAlive                PropertyType = 0x13
	AuthenticationMethod           PropertyType = 0x15
	AuthenticationData             PropertyType = 0x16
	RequestProblemInformation      PropertyType = 0x17
	WillDelayInterval              PropertyType = 0x18
	RequestResponseInformation     PropertyType = 0x19
	ResponseInformation            PropertyType = 0x1A
	ServerReference                PropertyType = 0x1C
	ReasonString                   PropertyType = 0x1F
	ReceiveMaximum                 PropertyType = 0x21
	TopicAliasMaximum              PropertyType = 0x22
	TopicAlias                     PropertyType = 0x23
	MaximumQoS                     PropertyType = 0x24
	RetainAvalilable               PropertyType = 0x25
	UserProperty                   PropertyType = 0x26
	MaximumPacketSize              PropertyType = 0x27
	WildcardSubscriptionAvailable  PropertyType = 0x28
	SubscrptionIdentifierAvailable PropertyType = 0x29
	SharedSubscriptionsAvaliable   PropertyType = 0x2A
)

func (PropertyType) Byte

func (p PropertyType) Byte() byte

type PubAck

type PubAck struct {
	*Frame

	PacketId   uint16
	ReasonCode ReasonCode
	Property   *PubAckProperty
}

func NewPubAck

func NewPubAck(packetId uint16, opts ...option) *PubAck

func ParsePubAck

func ParsePubAck(f *Frame, p []byte) (pa *PubAck, err error)

func (*PubAck) Encode

func (p *PubAck) Encode() ([]byte, error)

func (*PubAck) Validate

func (p *PubAck) Validate() error

type PubAckProperty

type PubAckProperty struct {
	ReasonString string
	UserProperty map[string]string
}

func (*PubAckProperty) ToProp

func (p *PubAckProperty) ToProp() *Property

type PubComp

type PubComp struct {
	*Frame

	PacketId   uint16
	ReasonCode ReasonCode
	Property   *PubCompProperty
}

func NewPubComp

func NewPubComp(packetId uint16, opts ...option) *PubComp

func ParsePubComp

func ParsePubComp(f *Frame, p []byte) (pc *PubComp, err error)

func (*PubComp) Encode

func (p *PubComp) Encode() ([]byte, error)

func (*PubComp) Validate

func (p *PubComp) Validate() error

type PubCompProperty

type PubCompProperty struct {
	ReasonString string
	UserProperty map[string]string
}

func (*PubCompProperty) ToProp

func (p *PubCompProperty) ToProp() *Property

type PubRec

type PubRec struct {
	*Frame

	PacketId   uint16
	ReasonCode ReasonCode
	Property   *PubRecProperty
}

func NewPubRec

func NewPubRec(packetId uint16, opts ...option) *PubRec

func ParsePubRec

func ParsePubRec(f *Frame, p []byte) (pr *PubRec, err error)

func (*PubRec) Encode

func (p *PubRec) Encode() ([]byte, error)

func (*PubRec) Validate

func (p *PubRec) Validate() error

type PubRecProperty

type PubRecProperty struct {
	ReasonString string
	UserProperty map[string]string
}

func (*PubRecProperty) ToProp

func (p *PubRecProperty) ToProp() *Property

type PubRel

type PubRel struct {
	*Frame

	PacketId   uint16
	ReasonCode ReasonCode
	Property   *PubRelProperty
}

func NewPubRel

func NewPubRel(packetId uint16, opts ...option) *PubRel

func ParsePubRel

func ParsePubRel(f *Frame, p []byte) (pr *PubRel, err error)

func (*PubRel) Encode

func (p *PubRel) Encode() ([]byte, error)

func (*PubRel) Validate

func (p *PubRel) Validate() error

type PubRelProperty

type PubRelProperty struct {
	ReasonString string
	UserProperty map[string]string
}

func (*PubRelProperty) ToProp

func (p *PubRelProperty) ToProp() *Property

type Publish

type Publish struct {
	*Frame

	TopicName string
	PacketId  uint16
	Body      []byte

	Property *PublishProperty
}

func NewPublish

func NewPublish(packetId uint16, opts ...option) *Publish

func ParsePublish

func ParsePublish(f *Frame, p []byte) (pb *Publish, err error)

func (*Publish) Downgrade

func (p *Publish) Downgrade(qos QoSLevel) *Publish

Downgrade QoS. Create new pointer in order to avoid unpexected copy data

func (*Publish) Encode

func (p *Publish) Encode() ([]byte, error)

func (*Publish) Validate

func (p *Publish) Validate() error

type PublishProperty

type PublishProperty struct {
	PayloadFormatIndicator uint8
	MessageExpiryInterval  uint32
	ContentType            string
	ResponseTopic          string
	CorrelationData        []byte
	SubscriptionIdentifier uint64
	TopicAlias             uint16
	UserProperty           map[string]string
}

func (*PublishProperty) ToProp

func (p *PublishProperty) ToProp() *Property

type QoSLevel

type QoSLevel uint8
const (
	QoS0 QoSLevel = iota
	QoS1
	QoS2
)

type ReasonCode

type ReasonCode uint8
const (
	Success                             ReasonCode = 0x00
	NormalDisconnection                 ReasonCode = 0x00
	GrantedQoS0                         ReasonCode = 0x00
	GrantedQoS1                         ReasonCode = 0x01
	GrantedQoS2                         ReasonCode = 0x02
	DisconnectWithWillMessage           ReasonCode = 0x04
	NoMatchingSubscribers               ReasonCode = 0x10
	NoSubscriptionExisted               ReasonCode = 0x11
	ContinueAuthentication              ReasonCode = 0x18
	ReAuthenticate                      ReasonCode = 0x19
	UnspecifiedError                    ReasonCode = 0x80
	MalformedPacket                     ReasonCode = 0x81
	ProtocolError                       ReasonCode = 0x82
	ImplementationSpecificError         ReasonCode = 0x83
	UnsupportedProtocolVersion          ReasonCode = 0x84
	ClientIdentifierNotValid            ReasonCode = 0x85
	BadUsernameOrPassword               ReasonCode = 0x86
	NotAuthorized                       ReasonCode = 0x87
	ServerUnavailable                   ReasonCode = 0x88
	ServerBusy                          ReasonCode = 0x89
	Banned                              ReasonCode = 0x8A
	ServerShuttingDown                  ReasonCode = 0x8B
	BadAuthenticationMethod             ReasonCode = 0x8C
	KeepAliveTimeout                    ReasonCode = 0x8D
	SessionTakenOver                    ReasonCode = 0x8E
	TopicFilterInvalid                  ReasonCode = 0x8F
	TopicNameInvalid                    ReasonCode = 0x90
	PacketIdentifierInUse               ReasonCode = 0x91
	PacketIdentifierNotFound            ReasonCode = 0x92
	ReceiveMaximumExceeded              ReasonCode = 0x93
	TopicAliasInvalid                   ReasonCode = 0x94
	PacketTooLarge                      ReasonCode = 0x95
	MessageRateTooHigh                  ReasonCode = 0x96
	QuotaExceeded                       ReasonCode = 0x97
	AdministrativeAction                ReasonCode = 0x98
	PayloadFormatInvalid                ReasonCode = 0x99
	RetianlNotSupported                 ReasonCode = 0x9A
	QoSNotSupported                     ReasonCode = 0x9B
	UseAnotherServer                    ReasonCode = 0x9C
	ServerMoved                         ReasonCode = 0x9D
	SharedSubscriptionsNotSupported     ReasonCode = 0x9E
	ConnectionRateExceeded              ReasonCode = 0x9F
	MaximumConnectionTime               ReasonCode = 0xA0
	SubscriptionIdentifiersNotSupported ReasonCode = 0xA1
	WildcardSubscriptionsNotSupported   ReasonCode = 0xA2
)

func (ReasonCode) Byte

func (r ReasonCode) Byte() byte

func (ReasonCode) String

func (i ReasonCode) String() string

type SubAck

type SubAck struct {
	*Frame

	PacketId    uint16
	Property    *SubAckProperty
	ReasonCodes []ReasonCode
}

func NewSubAck

func NewSubAck(packetId uint16, rcs ...ReasonCode) *SubAck

func ParseSubAck

func ParseSubAck(f *Frame, p []byte) (s *SubAck, err error)

func (*SubAck) AddReasonCode

func (s *SubAck) AddReasonCode(rcs ...ReasonCode)

func (*SubAck) Encode

func (s *SubAck) Encode() ([]byte, error)

func (*SubAck) Validate

func (s *SubAck) Validate() error

type SubAckProperty

type SubAckProperty struct {
	ReasonString string
	UserProperty map[string]string
}

func (*SubAckProperty) ToProp

func (p *SubAckProperty) ToProp() *Property

type Subscribe

type Subscribe struct {
	*Frame

	PacketId      uint16
	Property      *SubscribeProperty
	Subscriptions []SubscribeTopic
}

func NewSubscribe

func NewSubscribe(opts ...option) *Subscribe

func ParseSubscribe

func ParseSubscribe(f *Frame, p []byte) (s *Subscribe, err error)

func (*Subscribe) AddTopic

func (s *Subscribe) AddTopic(sts ...SubscribeTopic)

func (*Subscribe) Encode

func (s *Subscribe) Encode() ([]byte, error)

func (*Subscribe) Validate

func (s *Subscribe) Validate() error

type SubscribeProperty

type SubscribeProperty struct {
	SubscriptionIdentifier uint64
	UserProperty           map[string]string
}

func (*SubscribeProperty) ToProp

func (s *SubscribeProperty) ToProp() *Property

type SubscribeTopic

type SubscribeTopic struct {
	RetainHandling uint8
	RAP            bool
	NoLocal        bool
	TopicName      string
	QoS            QoSLevel
}

type UnsubAck

type UnsubAck struct {
	*Frame

	PacketId    uint16
	Property    *UnsubAckProperty
	ReasonCodes []ReasonCode
}

func NewUnsubAck

func NewUnsubAck(rcs ...ReasonCode) *UnsubAck

func ParseUnsubAck

func ParseUnsubAck(f *Frame, p []byte) (u *UnsubAck, err error)

func (*UnsubAck) AddReasonCode

func (u *UnsubAck) AddReasonCode(rcs ...ReasonCode)

func (*UnsubAck) Encode

func (u *UnsubAck) Encode() ([]byte, error)

func (*UnsubAck) Validate

func (u *UnsubAck) Validate() error

type UnsubAckProperty

type UnsubAckProperty struct {
	ReasonString string
	UserProperty map[string]string
}

func (*UnsubAckProperty) ToProp

func (p *UnsubAckProperty) ToProp() *Property

type Unsubscribe

type Unsubscribe struct {
	*Frame

	PacketId uint16
	Topics   []string
	Property *UnsubscribeProperty
}

func NewUnsubscribe

func NewUnsubscribe(opts ...option) *Unsubscribe

func ParseUnsubscribe

func ParseUnsubscribe(f *Frame, p []byte) (u *Unsubscribe, err error)

func (*Unsubscribe) AddTopic

func (u *Unsubscribe) AddTopic(topics ...string)

func (*Unsubscribe) Encode

func (u *Unsubscribe) Encode() ([]byte, error)

func (*Unsubscribe) Validate

func (u *Unsubscribe) Validate() error

type UnsubscribeProperty

type UnsubscribeProperty struct {
	UserProperty map[string]string
}

func (*UnsubscribeProperty) ToProp

func (p *UnsubscribeProperty) ToProp() *Property

type WillProperty

type WillProperty struct {
	PayloadFormatIndicator uint8
	MessageExpiryInterval  uint32
	ContentType            string
	ResponseTopic          string
	CorrelationData        []byte
	WillDelayInterval      uint32
	UserProperty           map[string]string
}

func (*WillProperty) ToProp

func (w *WillProperty) ToProp() *Property

func (*WillProperty) ToPublish

func (w *WillProperty) ToPublish() *PublishProperty

Jump to

Keyboard shortcuts

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