Skip to content

Commit

Permalink
fix: expanding field that has only one component (#483)
Browse files Browse the repository at this point in the history
* fix: should expand if a field only has one component even if its value is zero

* test: add test case
  • Loading branch information
muktihari authored Oct 5, 2024
1 parent e4a908f commit 190e0e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,9 +877,11 @@ func (d *Decoder) expandComponents(mesg *proto.Message, containingField *proto.F
componentField = d.factory.CreateField(mesg.Num, component.FieldNum)
componentField.IsExpandedField = true

// A component can only have max 32 bits value
// A component can only have max 32 bits value.
// If a field has only one component, expand it even if its value is zero
// e.g. speed (0) -> enhanced_speed (0).
val, ok := vbits.Pull(component.Bits)
if !ok {
if !ok && len(components) > 1 {
break
}

Expand Down
10 changes: 10 additions & 0 deletions decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,16 @@ func TestExpandComponents(t *testing.T) {
{FieldBase: factory.CreateField(mesgnum.Record, fieldnum.RecordDistance).FieldBase, Value: proto.Uint32(100), IsExpandedField: true}, // (1600 / 16) * 1
},
},
{
name: "expand field that only has one component and its value is zero",
mesg: proto.Message{Num: mesgnum.Record, Fields: []proto.Field{
factory.CreateField(mesgnum.Record, fieldnum.RecordSpeed).WithValue(uint16(0)),
}},
fieldsAfterExpansion: []proto.Field{
factory.CreateField(mesgnum.Record, fieldnum.RecordSpeed).WithValue(uint16(0)),
{FieldBase: factory.CreateField(mesgnum.Record, fieldnum.RecordEnhancedSpeed).FieldBase, Value: proto.Uint32(0), IsExpandedField: true},
},
},
{
// Real world use case from "testdata/from_official_sdk/activity_poolswim_with_hr.csv"
// prior Hr message event_timestamp value: 3.6201171875 -> 3707
Expand Down

0 comments on commit 190e0e4

Please sign in to comment.