Skip to content

Commit

Permalink
Fix 128
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Dec 11, 2022
1 parent 789397c commit a9aa037
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
18 changes: 4 additions & 14 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,8 @@ func (e *Encoder) WriteUint128(i Uint128, order binary.ByteOrder) (err error) {
zlog.Debug("encode: write uint128", zap.Stringer("hex", i), zap.Uint64("lo", i.Lo), zap.Uint64("hi", i.Hi))
}
buf := make([]byte, TypeSize.Uint128)
if order == binary.BigEndian {
order.PutUint64(buf, i.Hi)
order.PutUint64(buf[TypeSize.Uint64:], i.Lo)
} else {
order.PutUint64(buf, i.Lo)
order.PutUint64(buf[TypeSize.Uint64:], i.Hi)
}
order.PutUint64(buf, i.Lo)
order.PutUint64(buf[TypeSize.Uint64:], i.Hi)
return e.toWriter(buf)
}

Expand All @@ -279,13 +274,8 @@ func (e *Encoder) WriteInt128(i Int128, order binary.ByteOrder) (err error) {
zlog.Debug("encode: write int128", zap.Stringer("hex", i), zap.Uint64("lo", i.Lo), zap.Uint64("hi", i.Hi))
}
buf := make([]byte, TypeSize.Uint128)
if order == binary.BigEndian {
order.PutUint64(buf, i.Hi)
order.PutUint64(buf[TypeSize.Uint64:], i.Lo)
} else {
order.PutUint64(buf, i.Lo)
order.PutUint64(buf[TypeSize.Uint64:], i.Hi)
}
order.PutUint64(buf, i.Lo)
order.PutUint64(buf[TypeSize.Uint64:], i.Hi)
return e.toWriter(buf)
}

Expand Down
15 changes: 6 additions & 9 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestEncoder_safeString(t *testing.T) {
assert.Equal(t, []byte{
0x5, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
}, buf.Bytes())

}

func TestEncoder_int8(t *testing.T) {
Expand Down Expand Up @@ -152,7 +151,7 @@ func TestEncoder_int64(t *testing.T) {

assert.Equal(t, []byte{
0x91, 0x7d, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, //-819823
0xe3, 0x1c, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, //72931
0xe3, 0x1c, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, // 72931
}, buf.Bytes())

// big endian
Expand All @@ -164,7 +163,7 @@ func TestEncoder_int64(t *testing.T) {

assert.Equal(t, []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x7d, 0x91, //-819823
0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x1c, 0xe3, //72931
0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x1c, 0xe3, // 72931
}, buf.Bytes())
}

Expand Down Expand Up @@ -242,8 +241,8 @@ func TestEncoder_uint64(t *testing.T) {
enc.WriteUint64(uint64(72931), LE)

assert.Equal(t, []byte{
0x6f, 0x82, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, //819823
0xe3, 0x1c, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, //72931
0x6f, 0x82, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, // 819823
0xe3, 0x1c, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, // 72931
}, buf.Bytes())

// big endian
Expand All @@ -254,8 +253,8 @@ func TestEncoder_uint64(t *testing.T) {
enc.WriteUint64(uint64(72931), BE)

assert.Equal(t, []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x82, 0x6f, //819823
0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x1c, 0xe3, //72931
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x82, 0x6f, // 819823
0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x1c, 0xe3, // 72931
}, buf.Bytes())
}

Expand Down Expand Up @@ -494,7 +493,6 @@ func TestEncoder_BinaryStruct(t *testing.T) {
}

func TestEncoder_BinaryTestStructWithTags(t *testing.T) {

s := &binaryTestStructWithTags{
F1: "abc",
F2: -75,
Expand Down Expand Up @@ -1115,7 +1113,6 @@ func Test_writeArrayOfUint32(t *testing.T) {
),
buf.Bytes())
}

}

func Test_writeArrayOfUint64(t *testing.T) {
Expand Down

0 comments on commit a9aa037

Please sign in to comment.