Skip to content

NOISSUE - Update senml encoder#15

Open
nyagamunene wants to merge 5 commits into
absmach:mainfrom
nyagamunene:Extend_SenML_encoder
Open

NOISSUE - Update senml encoder#15
nyagamunene wants to merge 5 commits into
absmach:mainfrom
nyagamunene:Extend_SenML_encoder

Conversation

@nyagamunene
Copy link
Copy Markdown
Contributor

Pull request title should be NOISSUE - description or MG-XXX - description where 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 #XXX to 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

@nyagamunene nyagamunene marked this pull request as ready for review May 8, 2026 11:56
@nyagamunene nyagamunene force-pushed the Extend_SenML_encoder branch from 5760756 to 287c0ea Compare May 8, 2026 12:19
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]>
@nyagamunene nyagamunene force-pushed the Extend_SenML_encoder branch from 287c0ea to d8be9bf Compare May 13, 2026 16:32
Comment thread pkg/conn/conn.go
cmdStr := *sm.Records[0].StringValue
uuid := strings.TrimSuffix(sm.Records[0].BaseName, ":")
cmdType := records[0].Name
cmdStr := *records[0].StringValue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/senml/senml.go

// 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})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread pkg/senml/senml.go
if err != nil {
return nil, fmt.Errorf("senml decode: %w", err)
}
return p.Records, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants