Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions aper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,46 @@ func TestStructInteger(t *testing.T) {
}
}

type intMarshalRegressionLargeRange4096To131071 struct {
Value int64 `aper:"valueLB:4096,valueUB:131071"`
}

type intMarshalRegressionLargeRange0To100000 struct {
Value int64 `aper:"valueLB:0,valueUB:100000"`
}

func TestMarshalIntegerLengthRegression(t *testing.T) {
tests := []struct {
name string
input interface{}
expected []byte
}{
{
name: "range_4096_131071_value_5000",
input: intMarshalRegressionLargeRange4096To131071{Value: 5000},
expected: []byte{0x40, 0x03, 0x88},
},
{
name: "range_0_100000_value_65535",
input: intMarshalRegressionLargeRange0To100000{Value: 65535},
expected: []byte{0x40, 0xFF, 0xFF},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
encoded, err := Marshal(tc.input)
assert.NoError(t, err)
assert.Equal(t, tc.expected, encoded)

out := reflect.New(reflect.TypeOf(tc.input))
err = Unmarshal(encoded, out.Interface())
assert.NoError(t, err)
assert.Equal(t, tc.input, out.Elem().Interface())
})
}
}

// TEST ENUMERATED

// value is unconstraint
Expand Down
2 changes: 1 addition & 1 deletion marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (pd *perRawBitData) appendInteger(value int64, extensive bool, lowerBoundPt
unsignedValueRange := uint64(valueRange - 1)
for byteLen = 1; byteLen <= 127; byteLen++ {
unsignedValueRange >>= 8
if unsignedValueRange <= 1 {
if unsignedValueRange == 0 {
break
}
}
Expand Down
Loading