erlang: bugfix(serialization of -234 goes <<208,22>> while it should go int16 <<0xD1, ...>>)

This commit is contained in:
UENISHI Kota 2010-06-26 08:40:36 +09:00
parent ad052cb510
commit a1b2b41cdc
2 changed files with 11 additions and 10 deletions

View File

@ -86,15 +86,12 @@ pack_uint_(N) when is_integer( N ) , N < 128 ->
% uint 8 % uint 8
pack_uint_( N ) when is_integer( N ) andalso N < 256 -> pack_uint_( N ) when is_integer( N ) andalso N < 256 ->
<< 16#CC:8, N:8 >>; << 16#CC:8, N:8 >>;
% uint 16 % uint 16
pack_uint_( N ) when is_integer( N ) andalso N < 65536 -> pack_uint_( N ) when is_integer( N ) andalso N < 65536 ->
<< 16#CD:8, N:16/big-unsigned-integer-unit:1 >>; << 16#CD:8, N:16/big-unsigned-integer-unit:1 >>;
% uint 32 % uint 32
pack_uint_( N ) when is_integer( N ) andalso N < 16#FFFFFFFF-> pack_uint_( N ) when is_integer( N ) andalso N < 16#FFFFFFFF->
<< 16#CE:8, N:32/big-unsigned-integer-unit:1 >>; << 16#CE:8, N:32/big-unsigned-integer-unit:1 >>;
% uint 64 % uint 64
pack_uint_( N ) when is_integer( N )-> pack_uint_( N ) when is_integer( N )->
<< 16#CF:8, N:64/big-unsigned-integer-unit:1 >>. << 16#CF:8, N:64/big-unsigned-integer-unit:1 >>.
@ -103,13 +100,13 @@ pack_uint_( N ) when is_integer( N )->
pack_int_( N ) when is_integer( N ) , N >= -32-> pack_int_( N ) when is_integer( N ) , N >= -32->
<< 2#111:3, N:5 >>; << 2#111:3, N:5 >>;
% int 8 % int 8
pack_int_( N ) when is_integer( N ) , N >= -256 -> pack_int_( N ) when is_integer( N ) , N > -128 ->
<< 16#D0:8, N:8 >>; << 16#D0:8, N:8/big-signed-integer-unit:1 >>;
% int 16 % int 16
pack_int_( N ) when is_integer( N ), N >= -65536 -> pack_int_( N ) when is_integer( N ), N > -32768 ->
<< 16#D1:8, N:16/big-signed-integer-unit:1 >>; << 16#D1:8, N:16/big-signed-integer-unit:1 >>;
% int 32 % int 32
pack_int_( N ) when is_integer( N ), N >= -16#FFFFFFFF -> pack_int_( N ) when is_integer( N ), N > -16#FFFFFFFF ->
<< 16#D2:8, N:32/big-signed-integer-unit:1 >>; << 16#D2:8, N:32/big-signed-integer-unit:1 >>;
% int 64 % int 64
pack_int_( N ) when is_integer( N )-> pack_int_( N ) when is_integer( N )->
@ -351,6 +348,7 @@ test_data()->
<<"hogehoge">>, <<"243546rf7g68h798j", 0, 23, 255>>, <<"hogehoge">>, <<"243546rf7g68h798j", 0, 23, 255>>,
<<"hoasfdafdas][">>, <<"hoasfdafdas][">>,
[0,42, <<"sum">>, [1,2]], [1,42, nil, [3]], [0,42, <<"sum">>, [1,2]], [1,42, nil, [3]],
-234, -40000, -16#10000000, -16#100000000,
42 42
]. ].
@ -409,6 +407,7 @@ unknown_test()->
[23, 234, 0.23], [23, 234, 0.23],
[0,42,<<"sum">>, [1,2]], [1,42, nil, [3]], [0,42,<<"sum">>, [1,2]], [1,42, nil, [3]],
dict:from_list([{1,2},{<<"hoge">>,nil}]), dict:from_list([{1,2},{<<"hoge">>,nil}]),
-234, -50000,
42 42
], ],
Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]), Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]),
@ -419,9 +418,10 @@ unknown_test()->
port_close(Port). port_close(Port).
test_([]) -> 0; test_([]) -> 0;
test_([S|Rest])-> test_([Before|Rest])->
Pack = msgpack:pack(S), Pack = msgpack:pack(Before),
{S, <<>>} = msgpack:unpack( Pack ), {After, <<>>} = msgpack:unpack( Pack ),
?assertEqual(Before, After),
1+test_(Rest). 1+test_(Rest).
other_test()-> other_test()->

View File

@ -45,6 +45,7 @@ objs = [0, 1, 2, 123, 512, 1230, 678908,
[23, 234, 0.23], [23, 234, 0.23],
[0,42,"sum", [1,2]], [1,42, nil, [3]], [0,42,"sum", [1,2]], [1,42, nil, [3]],
{ 1 => 2, "hoge" => nil }, { 1 => 2, "hoge" => nil },
-234, -50000,
42 42
] ]
begin begin