Skip to content

Commit

Permalink
Struct alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
alsm committed Jan 28, 2019
1 parent 09bb144 commit 62679b1
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 170 deletions.
2 changes: 1 addition & 1 deletion packets/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

// Auth is the Variable Header definition for a Auth control packet
type Auth struct {
ReasonCode byte
Properties *Properties
ReasonCode byte
}

// Unpack is the implementation of the interface required function for a packet
Expand Down
4 changes: 2 additions & 2 deletions packets/connack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Connack is the Variable Header definition for a connack control packet
type Connack struct {
SessionPresent bool
ReasonCode byte
Properties *Properties
ReasonCode byte
SessionPresent bool
}

//Unpack is the implementation of the interface required function for a packet
Expand Down
22 changes: 11 additions & 11 deletions packets/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import (

// Connect is the Variable Header definition for a connect control packet
type Connect struct {
PasswordFlag bool
UsernameFlag bool
ProtocolName string
ProtocolVersion byte
WillTopic string
WillRetain bool
WillQOS byte
WillFlag bool
WillMessage []byte
CleanStart bool
Username string
Password []byte
KeepAlive uint16
Username string
ProtocolName string
ClientID string
WillTopic string
Properties *Properties
WillProperties *Properties
KeepAlive uint16
ProtocolVersion byte
WillQOS byte
PasswordFlag bool
UsernameFlag bool
WillRetain bool
WillFlag bool
CleanStart bool
}

// PackFlags takes the Connect flags and packs them into the single byte
Expand Down
2 changes: 1 addition & 1 deletion packets/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

// Disconnect is the Variable Header definition for a Disconnect control packet
type Disconnect struct {
ReasonCode byte
Properties *Properties
ReasonCode byte
}

// DisconnectNormalDisconnection, etc are the list of valid disconnection reason codes.
Expand Down
10 changes: 5 additions & 5 deletions packets/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ type (

// FixedHeader is the definition of a control packet fixed header
FixedHeader struct {
Flags byte
Type PacketType
remainingLength int
Type PacketType
Flags byte
}

// ControlPacket is the definition of a control packet
ControlPacket struct {
FixedHeader
Content Packet
FixedHeader
}
)

Expand Down Expand Up @@ -154,7 +154,7 @@ func ReadPacket(r io.Reader) (*ControlPacket, error) {
}
cp := NewControlPacket(PacketType(t[0] >> 4))
if cp == nil {
return nil, fmt.Errorf("Invalid packet type requested, %d", t[0]>>4)
return nil, fmt.Errorf("invalid packet type requested, %d", t[0]>>4)
}
cp.Flags = t[0] & 0xF
if cp.Type == PUBLISH {
Expand All @@ -177,7 +177,7 @@ func ReadPacket(r io.Reader) (*ControlPacket, error) {
return nil, err
}
if n != int64(cp.remainingLength) {
return nil, fmt.Errorf("Failed to read packet, expected %d bytes, read %d", cp.remainingLength, n)
return nil, fmt.Errorf("failed to read packet, expected %d bytes, read %d", cp.remainingLength, n)
}
err = cp.Content.Unpack(&content)
if err != nil {
Expand Down
56 changes: 28 additions & 28 deletions packets/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ import (
// MQTT packet properties
const (
PropPayloadFormat byte = 1
PropMessageExpiry = 2
PropContentType = 3
PropResponseTopic = 8
PropCorrelationData = 9
PropSubscriptionIdentifier = 11
PropSessionExpiryInterval = 17
PropAssignedClientID = 18
PropServerKeepAlive = 19
PropAuthMethod = 21
PropAuthData = 22
PropRequestProblemInfo = 23
PropWillDelayInterval = 24
PropRequestResponseInfo = 25
PropResponseInfo = 26
PropServerReference = 28
PropReasonString = 31
PropReceiveMaximum = 33
PropTopicAliasMaximum = 34
PropTopicAlias = 35
PropMaximumQOS = 36
PropRetainAvailable = 37
PropUser = 38
PropMaximumPacketSize = 39
PropWildcardSubAvailable = 40
PropSubIDAvailable = 41
PropSharedSubAvailable = 42
PropMessageExpiry byte = 2
PropContentType byte = 3
PropResponseTopic byte = 8
PropCorrelationData byte = 9
PropSubscriptionIdentifier byte = 11
PropSessionExpiryInterval byte = 17
PropAssignedClientID byte = 18
PropServerKeepAlive byte = 19
PropAuthMethod byte = 21
PropAuthData byte = 22
PropRequestProblemInfo byte = 23
PropWillDelayInterval byte = 24
PropRequestResponseInfo byte = 25
PropResponseInfo byte = 26
PropServerReference byte = 28
PropReasonString byte = 31
PropReceiveMaximum byte = 33
PropTopicAliasMaximum byte = 34
PropTopicAlias byte = 35
PropMaximumQOS byte = 36
PropRetainAvailable byte = 37
PropUser byte = 38
PropMaximumPacketSize byte = 39
PropWildcardSubAvailable byte = 40
PropSubIDAvailable byte = 41
PropSharedSubAvailable byte = 42
)

// Properties is a struct representing the all the described properties
Expand Down Expand Up @@ -323,7 +323,7 @@ func (i *Properties) Unpack(r *bytes.Buffer, p PacketType) error {
break
}
if !ValidateID(p, PropType) {
return fmt.Errorf("Invalid Prop type %d for packet %d", PropType, p)
return fmt.Errorf("invalid Prop type %d for packet %d", PropType, p)
}
switch PropType {
case PropPayloadFormat:
Expand Down Expand Up @@ -493,7 +493,7 @@ func (i *Properties) Unpack(r *bytes.Buffer, p PacketType) error {
}
i.SharedSubAvailable = &ss
default:
return fmt.Errorf("Unknown Prop type %d", PropType)
return fmt.Errorf("unknown Prop type %d", PropType)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packets/puback.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Puback is the Variable Header definition for a Puback control packet
type Puback struct {
Properties *Properties
PacketID uint16
ReasonCode byte
Properties *Properties
}

// PubackSuccess, etc are the list of valid puback reason codes.
Expand Down
2 changes: 1 addition & 1 deletion packets/pubcomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Pubcomp is the Variable Header definition for a Pubcomp control packet
type Pubcomp struct {
Properties *Properties
PacketID uint16
ReasonCode byte
Properties *Properties
}

// PubcompSuccess, etc are the list of valid pubcomp reason codes.
Expand Down
10 changes: 5 additions & 5 deletions packets/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

// Publish is the Variable Header definition for a publish control packet
type Publish struct {
Duplicate bool
QoS byte
Retain bool
Payload []byte
Topic string
PacketID uint16
Properties *Properties
Payload []byte
PacketID uint16
QoS byte
Duplicate bool
Retain bool
}

//Unpack is the implementation of the interface required function for a packet
Expand Down
2 changes: 1 addition & 1 deletion packets/pubrec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Pubrec is the Variable Header definition for a Pubrec control packet
type Pubrec struct {
Properties *Properties
PacketID uint16
ReasonCode byte
Properties *Properties
}

// PubrecSuccess, etc are the list of valid Pubrec reason codes
Expand Down
2 changes: 1 addition & 1 deletion packets/pubrel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Pubrel is the Variable Header definition for a Pubrel control packet
type Pubrel struct {
Properties *Properties
PacketID uint16
ReasonCode byte
Properties *Properties
}

//Unpack is the implementation of the interface required function for a packet
Expand Down
2 changes: 1 addition & 1 deletion packets/suback.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Suback is the Variable Header definition for a Suback control packet
type Suback struct {
PacketID uint16
Properties *Properties
Reasons []byte
PacketID uint16
}

// SubackGrantedQoS0, etc are the list of valid suback reason codes.
Expand Down
4 changes: 2 additions & 2 deletions packets/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (

// Subscribe is the Variable Header definition for a Subscribe control packet
type Subscribe struct {
PacketID uint16
Properties *Properties
Subscriptions map[string]SubOptions
PacketID uint16
}

// SubOptions is the struct representing the options for a subscription
type SubOptions struct {
QoS byte
RetainHandling byte
NoLocal bool
RetainAsPublished bool
RetainHandling byte
}

// Pack is the implementation of the interface required function for a packet
Expand Down
4 changes: 2 additions & 2 deletions packets/unsuback.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Unsuback is the Variable Header definition for a Unsuback control packet
type Unsuback struct {
PacketID uint16
Properties *Properties
Reasons []byte
Properties *Properties
PacketID uint16
}

// UnsubackSuccess, etc are the list of valid unsuback reason codes.
Expand Down
4 changes: 2 additions & 2 deletions packets/unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// Unsubscribe is the Variable Header definition for a Unsubscribe control packet
type Unsubscribe struct {
PacketID uint16
Properties *Properties
Topics []string
Properties *Properties
PacketID uint16
}

// Unpack is the implementation of the interface required function for a packet
Expand Down
Loading

0 comments on commit 62679b1

Please sign in to comment.