diff --git a/decimal_magpack_test.go b/decimal_magpack_test.go index 41d9dd2..bc865a4 100644 --- a/decimal_magpack_test.go +++ b/decimal_magpack_test.go @@ -7,7 +7,7 @@ import ( func TestMsgPack(t *testing.T) { for _, x := range testTable { s := x.short - // limit to 31 digits + // limit to 31 digits if len(s) > 31 { s = s[:31] if s[30] == '.' { @@ -17,15 +17,15 @@ func TestMsgPack(t *testing.T) { // Prepare Test Decimal Data amount, err := NewFromString(s) - if err != nil{ + if err != nil { t.Error(err) } s = amount.String() // MarshalMsg var b []byte - out, err := amount.MarshalMsg(b) - if err != nil{ + out, err := amount.MarshalMsg(b) + if err != nil { t.Errorf("error marshalMsg %s: %v", s, err) } @@ -44,12 +44,12 @@ func TestMsgPack(t *testing.T) { // UnmarshalMsg var unmarshalAmount Decimal _, err = unmarshalAmount.UnmarshalMsg(out) - if err != nil{ + if err != nil { t.Errorf("error unmarshalMsg %s: %v", s, err) - }else if !unmarshalAmount.Equal(amount) { - t.Errorf("expected %s, got %s (%s, %d)", - amount.String(), unmarshalAmount.String(), - unmarshalAmount.value.String(), unmarshalAmount.exp) + } else if !unmarshalAmount.Equal(amount) { + t.Errorf("expected %s, got %s (%s, %d)", + amount.String(), unmarshalAmount.String(), + unmarshalAmount.value.String(), unmarshalAmount.exp) } } -} \ No newline at end of file +} diff --git a/decimal_msgpack.go b/decimal_msgpack.go index 2e205f4..55d22d2 100644 --- a/decimal_msgpack.go +++ b/decimal_msgpack.go @@ -26,7 +26,7 @@ func (d Decimal) MarshalMsg(b []byte) ([]byte, error) { str = str[:sz] } - o, n := ensure(b, 1+sz) + o, n := ensure(o, 1+sz) o[n] = byte(0xa0 | sz) n++ @@ -54,7 +54,7 @@ func (d *Decimal) UnmarshalMsg(b []byte) ([]byte, error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (d Decimal) Msgsize() int { - return 31 + return 32 } // Require ensures that cap(old)-len(old) >= extra.