Skip to content

Commit 0827966

Browse files
committed
Fix Subscribe.subscriptionID is optional
1 parent ec4c100 commit 0827966

17 files changed

+116
-100
lines changed

auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ func (p *Auth) properties(b []byte, i int) int {
9595
return i - n
9696
}
9797

98-
func (p *Auth) propertyMap() map[Ident]wireType {
99-
return map[Ident]wireType{
100-
AuthMethod: &p.authMethod,
101-
AuthData: &p.authData,
102-
ReasonString: &p.reasonString,
98+
func (p *Auth) propertyMap() map[Ident]func() wireType {
99+
return map[Ident]func() wireType{
100+
AuthMethod: func() wireType { return &p.authMethod },
101+
AuthData: func() wireType { return &p.authData },
102+
ReasonString: func() wireType { return &p.reasonString },
103103
}
104104
}

buffer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type buffer struct {
2222
// getAny reads all properties from the current offset starting with
2323
// the variable length. fields map UserProp identity codes to wire
2424
// type fields and the addProp func is used for each user property.
25-
func (b *buffer) getAny(fields map[Ident]wireType, addProp func(UserProp)) {
25+
func (b *buffer) getAny(fields map[Ident]func() wireType, addProp func(UserProp)) {
2626
if b.atEnd() {
2727
return
2828
}
@@ -39,7 +39,7 @@ func (b *buffer) getAny(fields map[Ident]wireType, addProp func(UserProp)) {
3939
field, hasField := fields[id]
4040
switch {
4141
case hasField:
42-
b.get(field)
42+
b.get(field())
4343

4444
case id == UserProperty:
4545
var p UserProp

buffer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
func Test_buffer(t *testing.T) {
99
{ // missing data
1010
b := &buffer{}
11-
b.getAny(map[Ident]wireType{}, func(UserProp) {})
11+
b.getAny(map[Ident]func() wireType{}, func(UserProp) {})
1212
if b.err != nil {
1313
t.Error("getAny failes on empty data")
1414
}
1515
}
1616
{ // unknown user property
1717
b := &buffer{data: []byte{2, 0xff, 0}}
18-
b.getAny(map[Ident]wireType{}, func(UserProp) {})
18+
b.getAny(map[Ident]func() wireType{}, func(UserProp) {})
1919
if b.err == nil {
2020
t.Error("expect getAny to fail")
2121
}

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html.
66

77
## [unreleased]
88

9+
- Fix Subscribe.subscriptionID is optional
910
- Add func Unsubscribe.Filters
1011
- Update dependencies
1112

connack.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,24 @@ func (p *ConnAck) UnmarshalBinary(data []byte) error {
198198
return b.err
199199
}
200200

201-
func (p *ConnAck) propertyMap() map[Ident]wireType {
202-
return map[Ident]wireType{
203-
ReceiveMax: &p.receiveMax,
204-
SessionExpiryInterval: &p.sessionExpiryInterval,
205-
MaxQoS: &p.maxQoS,
206-
RetainAvailable: &p.retainAvailable,
207-
MaxPacketSize: &p.maxPacketSize,
208-
AssignedClientID: &p.assignedClientID,
209-
TopicAliasMax: &p.topicAliasMax,
210-
ReasonString: &p.reasonString,
211-
WildcardSubAvailable: &p.wildcardSubAvailable,
212-
SubIDsAvailable: &p.subIdentifiersAvailable,
213-
SharedSubAvailable: &p.sharedSubAvailable,
214-
ServerKeepAlive: &p.serverKeepAlive,
215-
ResponseInformation: &p.responseInformation,
216-
ServerReference: &p.serverReference,
217-
AuthMethod: &p.authMethod,
218-
AuthData: &p.authData,
201+
func (p *ConnAck) propertyMap() map[Ident]func() wireType {
202+
return map[Ident]func() wireType{
203+
ReceiveMax: func() wireType { return &p.receiveMax },
204+
SessionExpiryInterval: func() wireType { return &p.sessionExpiryInterval },
205+
MaxQoS: func() wireType { return &p.maxQoS },
206+
RetainAvailable: func() wireType { return &p.retainAvailable },
207+
MaxPacketSize: func() wireType { return &p.maxPacketSize },
208+
AssignedClientID: func() wireType { return &p.assignedClientID },
209+
TopicAliasMax: func() wireType { return &p.topicAliasMax },
210+
ReasonString: func() wireType { return &p.reasonString },
211+
WildcardSubAvailable: func() wireType { return &p.wildcardSubAvailable },
212+
SubIDsAvailable: func() wireType { return &p.subIdentifiersAvailable },
213+
SharedSubAvailable: func() wireType { return &p.sharedSubAvailable },
214+
ServerKeepAlive: func() wireType { return &p.serverKeepAlive },
215+
ResponseInformation: func() wireType { return &p.responseInformation },
216+
ServerReference: func() wireType { return &p.serverReference },
217+
AuthMethod: func() wireType { return &p.authMethod },
218+
AuthData: func() wireType { return &p.authData },
219219
}
220220
}
221221

connect.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (p *Connect) payload(b []byte, i int) int {
283283
n := i
284284

285285
for id, v := range p.willPropertyMap() {
286-
i += v.fillProp(b, i, id)
286+
i += v().fillProp(b, i, id)
287287
}
288288
i += p.will.UserProperties.properties(b, i)
289289

@@ -340,27 +340,27 @@ func (p *Connect) UnmarshalBinary(data []byte) error {
340340

341341
return buf.Err()
342342
}
343-
func (p *Connect) willPropertyMap() map[Ident]wireType {
344-
return map[Ident]wireType{
345-
WillDelayInterval: &p.willDelayInterval,
346-
PayloadFormatIndicator: &p.will.payloadFormat,
347-
MessageExpiryInterval: &p.will.messageExpiryInterval,
348-
ContentType: &p.will.contentType,
349-
ResponseTopic: &p.will.responseTopic,
350-
CorrelationData: &p.will.correlationData,
343+
func (p *Connect) willPropertyMap() map[Ident]func() wireType {
344+
return map[Ident]func() wireType{
345+
WillDelayInterval: func() wireType { return &p.willDelayInterval },
346+
PayloadFormatIndicator: func() wireType { return &p.will.payloadFormat },
347+
MessageExpiryInterval: func() wireType { return &p.will.messageExpiryInterval },
348+
ContentType: func() wireType { return &p.will.contentType },
349+
ResponseTopic: func() wireType { return &p.will.responseTopic },
350+
CorrelationData: func() wireType { return &p.will.correlationData },
351351
}
352352
}
353353

354-
func (p *Connect) propertyMap() map[Ident]wireType {
355-
return map[Ident]wireType{
356-
ReceiveMax: &p.receiveMax,
357-
SessionExpiryInterval: &p.sessionExpiryInterval,
358-
MaxPacketSize: &p.maxPacketSize,
359-
TopicAliasMax: &p.topicAliasMax,
360-
RequestResponseInfo: &p.requestResponseInfo,
361-
RequestProblemInfo: &p.requestProblemInfo,
362-
AuthMethod: &p.authMethod,
363-
AuthData: &p.authData,
354+
func (p *Connect) propertyMap() map[Ident]func() wireType {
355+
return map[Ident]func() wireType{
356+
ReceiveMax: func() wireType { return &p.receiveMax },
357+
SessionExpiryInterval: func() wireType { return &p.sessionExpiryInterval },
358+
MaxPacketSize: func() wireType { return &p.maxPacketSize },
359+
TopicAliasMax: func() wireType { return &p.topicAliasMax },
360+
RequestResponseInfo: func() wireType { return &p.requestResponseInfo },
361+
RequestProblemInfo: func() wireType { return &p.requestProblemInfo },
362+
AuthMethod: func() wireType { return &p.authMethod },
363+
AuthData: func() wireType { return &p.authData },
364364
}
365365
}
366366

disconnect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ func (p *Disconnect) UnmarshalBinary(data []byte) error {
7272
return b.err
7373
}
7474

75-
func (p *Disconnect) propertyMap() map[Ident]wireType {
76-
return map[Ident]wireType{}
75+
func (p *Disconnect) propertyMap() map[Ident]func() wireType {
76+
return map[Ident]func() wireType{}
7777
}

puback.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ func (p *PubAck) UnmarshalBinary(data []byte) error {
9595
return b.err
9696
}
9797

98-
func (p *PubAck) propertyMap() map[Ident]wireType {
99-
return map[Ident]wireType{
100-
ReasonString: &p.reason,
98+
func (p *PubAck) propertyMap() map[Ident]func() wireType {
99+
return map[Ident]func() wireType{
100+
ReasonString: func() wireType { return &p.reason },
101101
}
102102
}

pubcomp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func (p *PubComp) UnmarshalBinary(data []byte) error {
102102
return b.err
103103
}
104104

105-
func (p *PubComp) propertyMap() map[Ident]wireType {
106-
return map[Ident]wireType{
107-
ReasonString: &p.reason,
105+
func (p *PubComp) propertyMap() map[Ident]func() wireType {
106+
return map[Ident]func() wireType{
107+
ReasonString: func() wireType { return &p.reason },
108108
}
109109
}

publish.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ func (p *Publish) UnmarshalBinary(data []byte) error {
250250
return buf.err
251251
}
252252

253-
func (p *Publish) propertyMap() map[Ident]wireType {
254-
return map[Ident]wireType{
255-
PayloadFormatIndicator: &p.payloadFormat,
256-
MessageExpiryInterval: &p.messageExpiryInterval,
257-
TopicAlias: &p.topicAlias,
258-
ResponseTopic: &p.responseTopic,
259-
CorrelationData: &p.correlationData,
260-
ContentType: &p.contentType,
253+
func (p *Publish) propertyMap() map[Ident]func() wireType {
254+
return map[Ident]func() wireType{
255+
PayloadFormatIndicator: func() wireType { return &p.payloadFormat },
256+
MessageExpiryInterval: func() wireType { return &p.messageExpiryInterval },
257+
TopicAlias: func() wireType { return &p.topicAlias },
258+
ResponseTopic: func() wireType { return &p.responseTopic },
259+
CorrelationData: func() wireType { return &p.correlationData },
260+
ContentType: func() wireType { return &p.contentType },
261261
}
262262
}

0 commit comments

Comments
 (0)