NOISSUE - Update senml encoder#15
Conversation
5760756 to
287c0ea
Compare
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
287c0ea to
d8be9bf
Compare
| cmdStr := *sm.Records[0].StringValue | ||
| uuid := strings.TrimSuffix(sm.Records[0].BaseName, ":") | ||
| cmdType := records[0].Name | ||
| cmdStr := *records[0].StringValue |
There was a problem hiding this comment.
records[0].StringValue is not guarded: if the payload carries a float or bool record (both now encodable via the new helpers) StringValue will be nil and this dereference panics. Check for nil before dereferencing.
|
|
||
| // EncodeRecords encodes an arbitrary slice of records as a SenML JSON array. | ||
| func EncodeRecords(records []senml.Record) ([]byte, error) { | ||
| return encode(senml.Pack{Records: records}) |
There was a problem hiding this comment.
EncodeRecords calls encode directly, skipping pack, so no timestamp is injected. All other Encode* helpers stamp records with now() via pack; records encoded here will silently carry t=0 (Unix epoch 1970).
| if err != nil { | ||
| return nil, fmt.Errorf("senml decode: %w", err) | ||
| } | ||
| return p.Records, nil |
There was a problem hiding this comment.
senml.Decode does not normalize — base fields (bn, bt, bu) remain on the first record and are not resolved into subsequent records. For a multi-record payload, records[n].Name (n>0) will be an empty string if the name was carried via BaseName on the first record. Call senml.Normalize(p) before returning p.Records.
Pull request title should be
NOISSUE - descriptionorMG-XXX - descriptionwhere XXX is the ID of the issue this PR relates to.Please review the CONTRIBUTING.md file for detailed contributing guidelines.
What does this do?
Which issue(s) does this PR fix/relate to?
Put here
Resolves #XXXto auto-close the issue that your PR fixes (if such)List any changes that modify/break current functionality
Have you included tests for your changes?
Did you document any new/modified functionality?
Notes