Skip to content

Commit 209cfad

Browse files
committed
fixup
1 parent 0237595 commit 209cfad

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

serialization/serialization.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ func decodeVar(r io.ReadSeeker, unsigned bool) (interface{}, error) {
296296
if unsigned {
297297
return tNum >> (tb + 1), nil
298298
}
299-
return int64(tNum >> (tb + 2)), nil
299+
if positive := (tNum>>(tb+1))&1==0; positive {
300+
return int64(tNum >> (tb + 2)), nil
301+
}
302+
return int64(-(1+(tNum >> (tb + 2)))), nil
300303
}
301304

302305
func trailingOneBitCount(b byte) int {

serialization/serialization_test.go

+21-17
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func TestDecodeVar(t *testing.T) {
157157
{
158158
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
159159
// But converted to LE
160+
// unsigned integer, 65535
160161
[]byte{0b11111011, 0b11111111, 0b00000111},
161162
true,
162163
uint64(65535),
@@ -165,27 +166,30 @@ func TestDecodeVar(t *testing.T) {
165166
{
166167
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
167168
// But converted to LE
168-
[]byte{0b11111011, 0b11111111, 0b00001111},
169+
// signed integer, 65535
170+
[]byte{0b11110011, 0b11111111, 0b00001111},
169171
false,
170172
int64(65535),
171173
"",
172174
},
173-
// {
174-
// // From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
175-
// // But converted to LE
176-
// []byte{0b11101011, 0b11111111, 0b00001111},
177-
// false,
178-
// int64(-65535),
179-
// "",
180-
// },
181-
// {
182-
// // From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
183-
// // But converted to LE
184-
// []byte{0b11111011, 0b11111111, 0b00001111},
185-
// false,
186-
// int64(-65536),
187-
// "",
188-
// },
175+
{
176+
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
177+
// But converted to LE
178+
// signed integer, -65535
179+
[]byte{0b11101011, 0b11111111, 0b00001111},
180+
false,
181+
int64(-65535),
182+
"",
183+
},
184+
{
185+
// From the example on https://dev.mysql.com/doc/dev/mysql-server/latest/PageLibsMysqlSerialization.html
186+
// But converted to LE
187+
// signed integer, 65536
188+
[]byte{0b11111011, 0b11111111, 0b00001111},
189+
false,
190+
int64(-65536),
191+
"",
192+
},
189193
{
190194
[]byte{0x5d, 0x03},
191195
true,

0 commit comments

Comments
 (0)