build: upgrade to go 1.17 and dependencies

This commit is contained in:
2021-09-01 21:01:28 +02:00
parent de6f39bddc
commit 8b5888ee1b
321 changed files with 41511 additions and 9444 deletions

View File

@ -6,8 +6,8 @@ import (
"io"
)
//ConnackPacket is an internal representation of the fields of the
//Connack MQTT packet
// ConnackPacket is an internal representation of the fields of the
// Connack MQTT packet
type ConnackPacket struct {
FixedHeader
SessionPresent bool
@ -15,10 +15,7 @@ type ConnackPacket struct {
}
func (ca *ConnackPacket) String() string {
str := fmt.Sprintf("%s", ca.FixedHeader)
str += " "
str += fmt.Sprintf("sessionpresent: %t returncode: %d", ca.SessionPresent, ca.ReturnCode)
return str
return fmt.Sprintf("%s sessionpresent: %t returncode: %d", ca.FixedHeader, ca.SessionPresent, ca.ReturnCode)
}
func (ca *ConnackPacket) Write(w io.Writer) error {
@ -35,8 +32,8 @@ func (ca *ConnackPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (ca *ConnackPacket) Unpack(b io.Reader) error {
flags, err := decodeByte(b)
if err != nil {
@ -48,8 +45,8 @@ func (ca *ConnackPacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (ca *ConnackPacket) Details() Details {
return Details{Qos: 0, MessageID: 0}
}

View File

@ -6,8 +6,8 @@ import (
"io"
)
//ConnectPacket is an internal representation of the fields of the
//Connect MQTT packet
// ConnectPacket is an internal representation of the fields of the
// Connect MQTT packet
type ConnectPacket struct {
FixedHeader
ProtocolName string
@ -29,10 +29,11 @@ type ConnectPacket struct {
}
func (c *ConnectPacket) String() string {
str := fmt.Sprintf("%s", c.FixedHeader)
str += " "
str += fmt.Sprintf("protocolversion: %d protocolname: %s cleansession: %t willflag: %t WillQos: %d WillRetain: %t Usernameflag: %t Passwordflag: %t keepalive: %d clientId: %s willtopic: %s willmessage: %s Username: %s Password: %s", c.ProtocolVersion, c.ProtocolName, c.CleanSession, c.WillFlag, c.WillQos, c.WillRetain, c.UsernameFlag, c.PasswordFlag, c.Keepalive, c.ClientIdentifier, c.WillTopic, c.WillMessage, c.Username, c.Password)
return str
var password string
if len(c.Password) > 0 {
password = "<redacted>"
}
return fmt.Sprintf("%s protocolversion: %d protocolname: %s cleansession: %t willflag: %t WillQos: %d WillRetain: %t Usernameflag: %t Passwordflag: %t keepalive: %d clientId: %s willtopic: %s willmessage: %s Username: %s Password: %s", c.FixedHeader, c.ProtocolVersion, c.ProtocolName, c.CleanSession, c.WillFlag, c.WillQos, c.WillRetain, c.UsernameFlag, c.PasswordFlag, c.Keepalive, c.ClientIdentifier, c.WillTopic, c.WillMessage, c.Username, password)
}
func (c *ConnectPacket) Write(w io.Writer) error {
@ -62,8 +63,8 @@ func (c *ConnectPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (c *ConnectPacket) Unpack(b io.Reader) error {
var err error
c.ProtocolName, err = decodeString(b)
@ -119,36 +120,36 @@ func (c *ConnectPacket) Unpack(b io.Reader) error {
return nil
}
//Validate performs validation of the fields of a Connect packet
// Validate performs validation of the fields of a Connect packet
func (c *ConnectPacket) Validate() byte {
if c.PasswordFlag && !c.UsernameFlag {
return ErrRefusedBadUsernameOrPassword
}
if c.ReservedBit != 0 {
//Bad reserved bit
// Bad reserved bit
return ErrProtocolViolation
}
if (c.ProtocolName == "MQIsdp" && c.ProtocolVersion != 3) || (c.ProtocolName == "MQTT" && c.ProtocolVersion != 4) {
//Mismatched or unsupported protocol version
// Mismatched or unsupported protocol version
return ErrRefusedBadProtocolVersion
}
if c.ProtocolName != "MQIsdp" && c.ProtocolName != "MQTT" {
//Bad protocol name
// Bad protocol name
return ErrProtocolViolation
}
if len(c.ClientIdentifier) > 65535 || len(c.Username) > 65535 || len(c.Password) > 65535 {
//Bad size field
// Bad size field
return ErrProtocolViolation
}
if len(c.ClientIdentifier) == 0 && !c.CleanSession {
//Bad client identifier
// Bad client identifier
return ErrRefusedIDRejected
}
return Accepted
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (c *ConnectPacket) Details() Details {
return Details{Qos: 0, MessageID: 0}
}

View File

@ -1,19 +1,17 @@
package packets
import (
"fmt"
"io"
)
//DisconnectPacket is an internal representation of the fields of the
//Disconnect MQTT packet
// DisconnectPacket is an internal representation of the fields of the
// Disconnect MQTT packet
type DisconnectPacket struct {
FixedHeader
}
func (d *DisconnectPacket) String() string {
str := fmt.Sprintf("%s", d.FixedHeader)
return str
return d.FixedHeader.String()
}
func (d *DisconnectPacket) Write(w io.Writer) error {
@ -23,14 +21,14 @@ func (d *DisconnectPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (d *DisconnectPacket) Unpack(b io.Reader) error {
return nil
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (d *DisconnectPacket) Details() Details {
return Details{Qos: 0, MessageID: 0}
}

View File

@ -8,9 +8,9 @@ import (
"io"
)
//ControlPacket defines the interface for structs intended to hold
//decoded MQTT packets, either from being read or before being
//written
// ControlPacket defines the interface for structs intended to hold
// decoded MQTT packets, either from being read or before being
// written
type ControlPacket interface {
Write(io.Writer) error
Unpack(io.Reader) error
@ -18,8 +18,8 @@ type ControlPacket interface {
Details() Details
}
//PacketNames maps the constants for each of the MQTT packet types
//to a string representation of their name.
// PacketNames maps the constants for each of the MQTT packet types
// to a string representation of their name.
var PacketNames = map[uint8]string{
1: "CONNECT",
2: "CONNACK",
@ -37,7 +37,7 @@ var PacketNames = map[uint8]string{
14: "DISCONNECT",
}
//Below are the constants assigned to each of the MQTT packet types
// Below are the constants assigned to each of the MQTT packet types
const (
Connect = 1
Connack = 2
@ -55,8 +55,8 @@ const (
Disconnect = 14
)
//Below are the const definitions for error codes returned by
//Connect()
// Below are the const definitions for error codes returned by
// Connect()
const (
Accepted = 0x00
ErrRefusedBadProtocolVersion = 0x01
@ -68,8 +68,8 @@ const (
ErrProtocolViolation = 0xFF
)
//ConnackReturnCodes is a map of the error codes constants for Connect()
//to a string representation of the error
// ConnackReturnCodes is a map of the error codes constants for Connect()
// to a string representation of the error
var ConnackReturnCodes = map[uint8]string{
0: "Connection Accepted",
1: "Connection Refused: Bad Protocol Version",
@ -81,23 +81,33 @@ var ConnackReturnCodes = map[uint8]string{
255: "Connection Refused: Protocol Violation",
}
//ConnErrors is a map of the errors codes constants for Connect()
//to a Go error
var (
ErrorRefusedBadProtocolVersion = errors.New("unacceptable protocol version")
ErrorRefusedIDRejected = errors.New("identifier rejected")
ErrorRefusedServerUnavailable = errors.New("server Unavailable")
ErrorRefusedBadUsernameOrPassword = errors.New("bad user name or password")
ErrorRefusedNotAuthorised = errors.New("not Authorized")
ErrorNetworkError = errors.New("network Error")
ErrorProtocolViolation = errors.New("protocol Violation")
)
// ConnErrors is a map of the errors codes constants for Connect()
// to a Go error
var ConnErrors = map[byte]error{
Accepted: nil,
ErrRefusedBadProtocolVersion: errors.New("Unnacceptable protocol version"),
ErrRefusedIDRejected: errors.New("Identifier rejected"),
ErrRefusedServerUnavailable: errors.New("Server Unavailable"),
ErrRefusedBadUsernameOrPassword: errors.New("Bad user name or password"),
ErrRefusedNotAuthorised: errors.New("Not Authorized"),
ErrNetworkError: errors.New("Network Error"),
ErrProtocolViolation: errors.New("Protocol Violation"),
ErrRefusedBadProtocolVersion: ErrorRefusedBadProtocolVersion,
ErrRefusedIDRejected: ErrorRefusedIDRejected,
ErrRefusedServerUnavailable: ErrorRefusedServerUnavailable,
ErrRefusedBadUsernameOrPassword: ErrorRefusedBadUsernameOrPassword,
ErrRefusedNotAuthorised: ErrorRefusedNotAuthorised,
ErrNetworkError: ErrorNetworkError,
ErrProtocolViolation: ErrorProtocolViolation,
}
//ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts
//to read an MQTT packet from the stream. It returns a ControlPacket
//representing the decoded MQTT packet and an error. One of these returns will
//always be nil, a nil ControlPacket indicating an error occurred.
// ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts
// to read an MQTT packet from the stream. It returns a ControlPacket
// representing the decoded MQTT packet and an error. One of these returns will
// always be nil, a nil ControlPacket indicating an error occurred.
func ReadPacket(r io.Reader) (ControlPacket, error) {
var fh FixedHeader
b := make([]byte, 1)
@ -123,17 +133,17 @@ func ReadPacket(r io.Reader) (ControlPacket, error) {
return nil, err
}
if n != fh.RemainingLength {
return nil, errors.New("Failed to read expected data")
return nil, errors.New("failed to read expected data")
}
err = cp.Unpack(bytes.NewBuffer(packetBytes))
return cp, err
}
//NewControlPacket is used to create a new ControlPacket of the type specified
//by packetType, this is usually done by reference to the packet type constants
//defined in packets.go. The newly created ControlPacket is empty and a pointer
//is returned.
// NewControlPacket is used to create a new ControlPacket of the type specified
// by packetType, this is usually done by reference to the packet type constants
// defined in packets.go. The newly created ControlPacket is empty and a pointer
// is returned.
func NewControlPacket(packetType byte) ControlPacket {
switch packetType {
case Connect:
@ -168,9 +178,9 @@ func NewControlPacket(packetType byte) ControlPacket {
return nil
}
//NewControlPacketWithHeader is used to create a new ControlPacket of the type
//specified within the FixedHeader that is passed to the function.
//The newly created ControlPacket is empty and a pointer is returned.
// NewControlPacketWithHeader is used to create a new ControlPacket of the type
// specified within the FixedHeader that is passed to the function.
// The newly created ControlPacket is empty and a pointer is returned.
func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error) {
switch fh.MessageType {
case Connect:
@ -205,16 +215,16 @@ func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error) {
return nil, fmt.Errorf("unsupported packet type 0x%x", fh.MessageType)
}
//Details struct returned by the Details() function called on
//ControlPackets to present details of the Qos and MessageID
//of the ControlPacket
// Details struct returned by the Details() function called on
// ControlPackets to present details of the Qos and MessageID
// of the ControlPacket
type Details struct {
Qos byte
MessageID uint16
}
//FixedHeader is a struct to hold the decoded information from
//the fixed header of an MQTT ControlPacket
// FixedHeader is a struct to hold the decoded information from
// the fixed header of an MQTT ControlPacket
type FixedHeader struct {
MessageType byte
Dup bool
@ -274,9 +284,9 @@ func decodeUint16(b io.Reader) (uint16, error) {
}
func encodeUint16(num uint16) []byte {
bytes := make([]byte, 2)
binary.BigEndian.PutUint16(bytes, num)
return bytes
bytesResult := make([]byte, 2)
binary.BigEndian.PutUint16(bytesResult, num)
return bytesResult
}
func encodeString(field string) []byte {
@ -329,7 +339,7 @@ func decodeLength(r io.Reader) (int, error) {
var rLength uint32
var multiplier uint32
b := make([]byte, 1)
for multiplier < 27 { //fix: Infinite '(digit & 128) == 1' will cause the dead loop
for multiplier < 27 { // fix: Infinite '(digit & 128) == 1' will cause the dead loop
_, err := io.ReadFull(r, b)
if err != nil {
return 0, err

View File

@ -1,19 +1,17 @@
package packets
import (
"fmt"
"io"
)
//PingreqPacket is an internal representation of the fields of the
//Pingreq MQTT packet
// PingreqPacket is an internal representation of the fields of the
// Pingreq MQTT packet
type PingreqPacket struct {
FixedHeader
}
func (pr *PingreqPacket) String() string {
str := fmt.Sprintf("%s", pr.FixedHeader)
return str
return pr.FixedHeader.String()
}
func (pr *PingreqPacket) Write(w io.Writer) error {
@ -23,14 +21,14 @@ func (pr *PingreqPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (pr *PingreqPacket) Unpack(b io.Reader) error {
return nil
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (pr *PingreqPacket) Details() Details {
return Details{Qos: 0, MessageID: 0}
}

View File

@ -1,19 +1,17 @@
package packets
import (
"fmt"
"io"
)
//PingrespPacket is an internal representation of the fields of the
//Pingresp MQTT packet
// PingrespPacket is an internal representation of the fields of the
// Pingresp MQTT packet
type PingrespPacket struct {
FixedHeader
}
func (pr *PingrespPacket) String() string {
str := fmt.Sprintf("%s", pr.FixedHeader)
return str
return pr.FixedHeader.String()
}
func (pr *PingrespPacket) Write(w io.Writer) error {
@ -23,14 +21,14 @@ func (pr *PingrespPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (pr *PingrespPacket) Unpack(b io.Reader) error {
return nil
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (pr *PingrespPacket) Details() Details {
return Details{Qos: 0, MessageID: 0}
}

View File

@ -5,18 +5,15 @@ import (
"io"
)
//PubackPacket is an internal representation of the fields of the
//Puback MQTT packet
// PubackPacket is an internal representation of the fields of the
// Puback MQTT packet
type PubackPacket struct {
FixedHeader
MessageID uint16
}
func (pa *PubackPacket) String() string {
str := fmt.Sprintf("%s", pa.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", pa.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", pa.FixedHeader, pa.MessageID)
}
func (pa *PubackPacket) Write(w io.Writer) error {
@ -29,8 +26,8 @@ func (pa *PubackPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (pa *PubackPacket) Unpack(b io.Reader) error {
var err error
pa.MessageID, err = decodeUint16(b)
@ -38,8 +35,8 @@ func (pa *PubackPacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (pa *PubackPacket) Details() Details {
return Details{Qos: pa.Qos, MessageID: pa.MessageID}
}

View File

@ -5,18 +5,15 @@ import (
"io"
)
//PubcompPacket is an internal representation of the fields of the
//Pubcomp MQTT packet
// PubcompPacket is an internal representation of the fields of the
// Pubcomp MQTT packet
type PubcompPacket struct {
FixedHeader
MessageID uint16
}
func (pc *PubcompPacket) String() string {
str := fmt.Sprintf("%s", pc.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", pc.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", pc.FixedHeader, pc.MessageID)
}
func (pc *PubcompPacket) Write(w io.Writer) error {
@ -29,8 +26,8 @@ func (pc *PubcompPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (pc *PubcompPacket) Unpack(b io.Reader) error {
var err error
pc.MessageID, err = decodeUint16(b)
@ -38,8 +35,8 @@ func (pc *PubcompPacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (pc *PubcompPacket) Details() Details {
return Details{Qos: pc.Qos, MessageID: pc.MessageID}
}

View File

@ -6,8 +6,8 @@ import (
"io"
)
//PublishPacket is an internal representation of the fields of the
//Publish MQTT packet
// PublishPacket is an internal representation of the fields of the
// Publish MQTT packet
type PublishPacket struct {
FixedHeader
TopicName string
@ -16,12 +16,7 @@ type PublishPacket struct {
}
func (p *PublishPacket) String() string {
str := fmt.Sprintf("%s", p.FixedHeader)
str += " "
str += fmt.Sprintf("topicName: %s MessageID: %d", p.TopicName, p.MessageID)
str += " "
str += fmt.Sprintf("payload: %s", string(p.Payload))
return str
return fmt.Sprintf("%s topicName: %s MessageID: %d payload: %s", p.FixedHeader, p.TopicName, p.MessageID, string(p.Payload))
}
func (p *PublishPacket) Write(w io.Writer) error {
@ -41,8 +36,8 @@ func (p *PublishPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (p *PublishPacket) Unpack(b io.Reader) error {
var payloadLength = p.FixedHeader.RemainingLength
var err error
@ -61,7 +56,7 @@ func (p *PublishPacket) Unpack(b io.Reader) error {
payloadLength -= len(p.TopicName) + 2
}
if payloadLength < 0 {
return fmt.Errorf("Error unpacking publish, payload length < 0")
return fmt.Errorf("error unpacking publish, payload length < 0")
}
p.Payload = make([]byte, payloadLength)
_, err = b.Read(p.Payload)
@ -69,10 +64,10 @@ func (p *PublishPacket) Unpack(b io.Reader) error {
return err
}
//Copy creates a new PublishPacket with the same topic and payload
//but an empty fixed header, useful for when you want to deliver
//a message with different properties such as Qos but the same
//content
// Copy creates a new PublishPacket with the same topic and payload
// but an empty fixed header, useful for when you want to deliver
// a message with different properties such as Qos but the same
// content
func (p *PublishPacket) Copy() *PublishPacket {
newP := NewControlPacket(Publish).(*PublishPacket)
newP.TopicName = p.TopicName
@ -81,8 +76,8 @@ func (p *PublishPacket) Copy() *PublishPacket {
return newP
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (p *PublishPacket) Details() Details {
return Details{Qos: p.Qos, MessageID: p.MessageID}
}

View File

@ -5,18 +5,15 @@ import (
"io"
)
//PubrecPacket is an internal representation of the fields of the
//Pubrec MQTT packet
// PubrecPacket is an internal representation of the fields of the
// Pubrec MQTT packet
type PubrecPacket struct {
FixedHeader
MessageID uint16
}
func (pr *PubrecPacket) String() string {
str := fmt.Sprintf("%s", pr.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", pr.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", pr.FixedHeader, pr.MessageID)
}
func (pr *PubrecPacket) Write(w io.Writer) error {
@ -29,8 +26,8 @@ func (pr *PubrecPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (pr *PubrecPacket) Unpack(b io.Reader) error {
var err error
pr.MessageID, err = decodeUint16(b)
@ -38,8 +35,8 @@ func (pr *PubrecPacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (pr *PubrecPacket) Details() Details {
return Details{Qos: pr.Qos, MessageID: pr.MessageID}
}

View File

@ -5,18 +5,15 @@ import (
"io"
)
//PubrelPacket is an internal representation of the fields of the
//Pubrel MQTT packet
// PubrelPacket is an internal representation of the fields of the
// Pubrel MQTT packet
type PubrelPacket struct {
FixedHeader
MessageID uint16
}
func (pr *PubrelPacket) String() string {
str := fmt.Sprintf("%s", pr.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", pr.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", pr.FixedHeader, pr.MessageID)
}
func (pr *PubrelPacket) Write(w io.Writer) error {
@ -29,8 +26,8 @@ func (pr *PubrelPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (pr *PubrelPacket) Unpack(b io.Reader) error {
var err error
pr.MessageID, err = decodeUint16(b)
@ -38,8 +35,8 @@ func (pr *PubrelPacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (pr *PubrelPacket) Details() Details {
return Details{Qos: pr.Qos, MessageID: pr.MessageID}
}

View File

@ -6,8 +6,8 @@ import (
"io"
)
//SubackPacket is an internal representation of the fields of the
//Suback MQTT packet
// SubackPacket is an internal representation of the fields of the
// Suback MQTT packet
type SubackPacket struct {
FixedHeader
MessageID uint16
@ -15,10 +15,7 @@ type SubackPacket struct {
}
func (sa *SubackPacket) String() string {
str := fmt.Sprintf("%s", sa.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", sa.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", sa.FixedHeader, sa.MessageID)
}
func (sa *SubackPacket) Write(w io.Writer) error {
@ -34,8 +31,8 @@ func (sa *SubackPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (sa *SubackPacket) Unpack(b io.Reader) error {
var qosBuffer bytes.Buffer
var err error
@ -53,8 +50,8 @@ func (sa *SubackPacket) Unpack(b io.Reader) error {
return nil
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (sa *SubackPacket) Details() Details {
return Details{Qos: 0, MessageID: sa.MessageID}
}

View File

@ -6,8 +6,8 @@ import (
"io"
)
//SubscribePacket is an internal representation of the fields of the
//Subscribe MQTT packet
// SubscribePacket is an internal representation of the fields of the
// Subscribe MQTT packet
type SubscribePacket struct {
FixedHeader
MessageID uint16
@ -16,10 +16,7 @@ type SubscribePacket struct {
}
func (s *SubscribePacket) String() string {
str := fmt.Sprintf("%s", s.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d topics: %s", s.MessageID, s.Topics)
return str
return fmt.Sprintf("%s MessageID: %d topics: %s", s.FixedHeader, s.MessageID, s.Topics)
}
func (s *SubscribePacket) Write(w io.Writer) error {
@ -39,8 +36,8 @@ func (s *SubscribePacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (s *SubscribePacket) Unpack(b io.Reader) error {
var err error
s.MessageID, err = decodeUint16(b)
@ -59,14 +56,14 @@ func (s *SubscribePacket) Unpack(b io.Reader) error {
return err
}
s.Qoss = append(s.Qoss, qos)
payloadLength -= 2 + len(topic) + 1 //2 bytes of string length, plus string, plus 1 byte for Qos
payloadLength -= 2 + len(topic) + 1 // 2 bytes of string length, plus string, plus 1 byte for Qos
}
return nil
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (s *SubscribePacket) Details() Details {
return Details{Qos: 1, MessageID: s.MessageID}
}

View File

@ -5,18 +5,15 @@ import (
"io"
)
//UnsubackPacket is an internal representation of the fields of the
//Unsuback MQTT packet
// UnsubackPacket is an internal representation of the fields of the
// Unsuback MQTT packet
type UnsubackPacket struct {
FixedHeader
MessageID uint16
}
func (ua *UnsubackPacket) String() string {
str := fmt.Sprintf("%s", ua.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", ua.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", ua.FixedHeader, ua.MessageID)
}
func (ua *UnsubackPacket) Write(w io.Writer) error {
@ -29,8 +26,8 @@ func (ua *UnsubackPacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (ua *UnsubackPacket) Unpack(b io.Reader) error {
var err error
ua.MessageID, err = decodeUint16(b)
@ -38,8 +35,8 @@ func (ua *UnsubackPacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (ua *UnsubackPacket) Details() Details {
return Details{Qos: 0, MessageID: ua.MessageID}
}

View File

@ -6,8 +6,8 @@ import (
"io"
)
//UnsubscribePacket is an internal representation of the fields of the
//Unsubscribe MQTT packet
// UnsubscribePacket is an internal representation of the fields of the
// Unsubscribe MQTT packet
type UnsubscribePacket struct {
FixedHeader
MessageID uint16
@ -15,10 +15,7 @@ type UnsubscribePacket struct {
}
func (u *UnsubscribePacket) String() string {
str := fmt.Sprintf("%s", u.FixedHeader)
str += " "
str += fmt.Sprintf("MessageID: %d", u.MessageID)
return str
return fmt.Sprintf("%s MessageID: %d", u.FixedHeader, u.MessageID)
}
func (u *UnsubscribePacket) Write(w io.Writer) error {
@ -36,8 +33,8 @@ func (u *UnsubscribePacket) Write(w io.Writer) error {
return err
}
//Unpack decodes the details of a ControlPacket after the fixed
//header has been read
// Unpack decodes the details of a ControlPacket after the fixed
// header has been read
func (u *UnsubscribePacket) Unpack(b io.Reader) error {
var err error
u.MessageID, err = decodeUint16(b)
@ -52,8 +49,8 @@ func (u *UnsubscribePacket) Unpack(b io.Reader) error {
return err
}
//Details returns a Details struct containing the Qos and
//MessageID of this ControlPacket
// Details returns a Details struct containing the Qos and
// MessageID of this ControlPacket
func (u *UnsubscribePacket) Details() Details {
return Details{Qos: 1, MessageID: u.MessageID}
}