mirror of
https://github.com/valitydev/msgpack-erlang.git
synced 2024-11-06 00:35:24 +00:00
commit
5eddde1828
@ -98,13 +98,13 @@ pack(Other, _) ->
|
||||
pack_int(N) when N >= -32->
|
||||
<< 2#111:3, N:5 >>;
|
||||
%% int 8
|
||||
pack_int(N) when N > -128 ->
|
||||
pack_int(N) when N >= -128 ->
|
||||
<< 16#D0:8, N:8/big-signed-integer-unit:1 >>;
|
||||
%% int 16
|
||||
pack_int(N) when N > -32768 ->
|
||||
pack_int(N) when N >= -16#8000 ->
|
||||
<< 16#D1:8, N:16/big-signed-integer-unit:1 >>;
|
||||
%% int 32
|
||||
pack_int(N) when (N band 16#FFFFFFFF) =:= N ->
|
||||
pack_int(N) when N >= -16#80000000 ->
|
||||
<< 16#D2:8, N:32/big-signed-integer-unit:1 >>;
|
||||
%% int 64
|
||||
pack_int(N) when N >= -16#8000000000000000 ->
|
||||
|
@ -232,11 +232,60 @@ map_test_()->
|
||||
|
||||
int_test_() ->
|
||||
[
|
||||
{"",
|
||||
{"negative fixnum",
|
||||
fun() ->
|
||||
Term = -2147483649,
|
||||
Term = -32,
|
||||
Binary = pack(Term),
|
||||
?assertEqual(1, byte_size(Binary)),
|
||||
?assertEqual({ok, Term}, unpack(Binary))
|
||||
end},
|
||||
{"int 8",
|
||||
fun() ->
|
||||
Term = -33,
|
||||
Binary = pack(Term),
|
||||
?assertEqual(2, byte_size(Binary)),
|
||||
?assertEqual({ok, Term}, unpack(Binary)),
|
||||
|
||||
Term2 = -128,
|
||||
Binary2 = pack(Term2),
|
||||
?assertEqual(2, byte_size(Binary2)),
|
||||
?assertEqual({ok, Term2}, unpack(Binary2))
|
||||
end},
|
||||
{"int 16",
|
||||
fun() ->
|
||||
Term = -129,
|
||||
Binary = pack(Term),
|
||||
?assertEqual(3, byte_size(Binary)),
|
||||
?assertEqual({ok, Term}, unpack(Binary)),
|
||||
|
||||
Term2 = -16#8000,
|
||||
Binary2 = pack(Term2),
|
||||
?assertEqual(3, byte_size(Binary2)),
|
||||
?assertEqual({ok, Term2}, unpack(Binary2))
|
||||
end},
|
||||
{"int 32",
|
||||
fun() ->
|
||||
Term = -16#8001,
|
||||
Binary = pack(Term),
|
||||
?assertEqual(5, byte_size(Binary)),
|
||||
?assertEqual({ok, Term}, unpack(Binary)),
|
||||
|
||||
Term2 = -16#80000000,
|
||||
Binary2 = pack(Term2),
|
||||
?assertEqual(5, byte_size(Binary2)),
|
||||
?assertEqual({ok, Term2}, unpack(Binary2))
|
||||
end},
|
||||
{"int 64",
|
||||
fun() ->
|
||||
Term = -16#80000001,
|
||||
Binary = pack(Term),
|
||||
?assertEqual(9, byte_size(Binary)),
|
||||
?assertEqual({ok, Term}, unpack(Binary)),
|
||||
|
||||
Term2 = -16#8000000000000000,
|
||||
Binary2 = pack(Term2),
|
||||
?assertEqual(9, byte_size(Binary2)),
|
||||
?assertEqual({ok, Term2}, unpack(Binary2))
|
||||
end}
|
||||
].
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user