mqtt_parsing

package module
v0.0.0-...-6ae49ea Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2016 License: Apache-2.0 Imports: 5 Imported by: 18

README

mqtt_parsing

A golang MQTT parsing library.

Documentation

Index

Constants

View Source
const (
	CONNECT = uint8(iota + 1)
	CONNACK
	PUBLISH
	PUBACK
	PUBREC
	PUBREL
	PUBCOMP
	SUBSCRIBE
	SUBACK
	UNSUBSCRIBE
	UNSUBACK
	PINGREQ
	PINGRESP
	DISCONNECT
)

Variables

This section is empty.

Functions

func SetMaxPacketSize

func SetMaxPacketSize(lim int64)

SetMaxPacketSize allows us to limit the size of an incoming packet below the mqtt minimum 256MB

Types

type Connack

type Connack struct {
	ReturnCode uint8
}

Connack struct, the return codes are as follows 0x00 connection accepted 0x01 refused: unacceptable proto version 0x02 refused: identifier rejected 0x03 refused server unavailiable 0x04 bad user or password 0x05 not authorized

func (*Connack) Encode

func (c *Connack) Encode() []byte

Encode (ing) connacks is relatively easy

func (*Connack) Type

func (c *Connack) Type() uint8

Type returns enum val

type Connect

type Connect struct {
	ProtoName      string
	Version        uint8
	UsernameFlag   bool
	PasswordFlag   bool
	WillRetainFlag bool
	WillQOS        uint8
	WillFlag       bool
	CleanSeshFlag  bool
	KeepAlive      uint16

	ClientId    string
	WillTopic   TopicPath
	WillMessage string
	Username    string
	Password    string
}

/Connect is a struct for the packet of the same name

func (*Connect) Encode

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

Encode for *Connect. now this actually implements the Message interface

func (*Connect) Type

func (c *Connect) Type() uint8

Type returns the type from the "enum"

type Disconnect

type Disconnect struct {
}

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

func (*Disconnect) Encode

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

Encode for disconnect reutrns the encoded disconnect value

func (*Disconnect) Type

func (d *Disconnect) Type() uint8

Type returns the the enum value

type Message

type Message interface {
	Encode() []byte
	Type() uint8
}

Message is the interface all our packets will be implementing

func DecodePacket

func DecodePacket(rdr io.Reader) (Message, error)

DecodePacket allows us to

type Pingreq

type Pingreq struct {
}

Pingreq is a keepalive

func (*Pingreq) Encode

func (p *Pingreq) Encode() []byte

Encode for pingreq is simply the static header

func (*Pingreq) Type

func (p *Pingreq) Type() uint8

Type retursn the enum value for pingreq

type Pingresp

type Pingresp struct {
}

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

func (*Pingresp) Encode

func (p *Pingresp) Encode() []byte

Encode returns the encoded pingresp packet

func (*Pingresp) Type

func (p *Pingresp) Type() uint8

Type returns the enum value

type Puback

type Puback struct {
	MessageId uint16
}

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

func (*Puback) Encode

func (p *Puback) Encode() []byte

Encode encodes the puback, simple from here on out

func (*Puback) Type

func (p *Puback) Type() uint8

Type returns the enum value

type Pubcomp

type Pubcomp struct {
	MessageId uint16
}

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

func (*Pubcomp) Encode

func (p *Pubcomp) Encode() []byte

Encode encodes the final member of the QOS2 quartet

func (*Pubcomp) Type

func (p *Pubcomp) Type() uint8

Type returns the enum value

type Publish

type Publish struct {
	Header    *StaticHeader
	Topic     TopicPath
	MessageId uint16
	Payload   []byte
}

Pubit

func (*Publish) Encode

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

Encode writes the publish to a buffer

func (*Publish) Type

func (p *Publish) Type() uint8

Type returns the enum value

type Pubrec

type Pubrec struct {
	MessageId uint16
}

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

func (*Pubrec) Encode

func (p *Pubrec) Encode() []byte

Encode encodes that sweet qos2 packet

func (*Pubrec) Type

func (p *Pubrec) Type() uint8

Type returns the enum value

type Pubrel

type Pubrel struct {
	MessageId uint16
	//QOS1
	Header *StaticHeader
}

Pubrelis third, a response to pubrec from either the client or server.

func (*Pubrel) Encode

func (p *Pubrel) Encode() []byte

Encode encodes that pubrel sound you're so familiar with

func (*Pubrel) Type

func (p *Pubrel) Type() uint8

Type returns the enum value

type StaticHeader

type StaticHeader struct {
	DUP    bool
	Retain bool
	QOS    uint8
}

StaticHeader as defined in http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#fixed-header Though it's fixed header there

type Suback

type Suback struct {
	MessageId uint16
	Qos       []uint8
}

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

func (*Suback) Encode

func (s *Suback) Encode() []byte

Encode suback encodes the suback for great good

func (*Suback) Type

func (s *Suback) Type() uint8

Type returns the enum value

type Subscribe

type Subscribe struct {
	Header        *StaticHeader
	MessageId     uint16
	Subscriptions []TopicQOSTuple
}

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

func (*Subscribe) Encode

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

Encode encodes the subscribe packet

func (*Subscribe) Type

func (s *Subscribe) Type() uint8

Type returns the enum value of a subscribe

type TopicPath

type TopicPath struct {
	Wildcard bool
	Split    []string
	Whole    string
}

func CutOffSystemKey

func CutOffSystemKey(pth TopicPath, idx int, wildcard bool) (string, TopicPath)

func NewTopicPath

func NewTopicPath(path string) (TopicPath, bool)

NewTopicPath creates a TopicPath object from the this function could be more efficient

func TrimPath

func TrimPath(pth TopicPath, idx int, wildcard bool) TopicPath

so much garbage

type TopicQOSTuple

type TopicQOSTuple struct {
	Qos   uint8
	Topic TopicPath
}

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

type Unsuback

type Unsuback struct {
	MessageId uint16
}

Unsuback is to unsubscribe as suback is to subscribe

func (*Unsuback) Encode

func (u *Unsuback) Encode() []byte

Unsuback merely acks the fact we recieved a message

func (*Unsuback) Type

func (u *Unsuback) Type() uint8

Type returns the enum value

type Unsubscribe

type Unsubscribe struct {
	Header    *StaticHeader
	MessageId uint16
	Topics    []TopicQOSTuple
}

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

func (*Unsubscribe) Encode

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

Encode encodes the unsubscribe. All it is is the bodies of the subscribes

func (*Unsubscribe) Type

func (u *Unsubscribe) Type() uint8

Type returns the enum value

Jump to

Keyboard shortcuts

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