From a1b2b41cdcb4bbc98e21bcd334b729ec6e7b90d5 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Sat, 26 Jun 2010 08:40:36 +0900 Subject: [PATCH] erlang: bugfix(serialization of -234 goes <<208,22>> while it should go int16 <<0xD1, ...>>) --- erlang/msgpack.erl | 20 ++++++++++---------- erlang/testcase_generator.rb | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index 789ed535..63d648cd 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -86,15 +86,12 @@ pack_uint_(N) when is_integer( N ) , N < 128 -> % uint 8 pack_uint_( N ) when is_integer( N ) andalso N < 256 -> << 16#CC:8, N:8 >>; - % uint 16 pack_uint_( N ) when is_integer( N ) andalso N < 65536 -> << 16#CD:8, N:16/big-unsigned-integer-unit:1 >>; - % uint 32 pack_uint_( N ) when is_integer( N ) andalso N < 16#FFFFFFFF-> << 16#CE:8, N:32/big-unsigned-integer-unit:1 >>; - % uint 64 pack_uint_( N ) when is_integer( N )-> << 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-> << 2#111:3, N:5 >>; % int 8 -pack_int_( N ) when is_integer( N ) , N >= -256 -> - << 16#D0:8, N:8 >>; +pack_int_( N ) when is_integer( N ) , N > -128 -> + << 16#D0:8, N:8/big-signed-integer-unit:1 >>; % 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 >>; % 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 >>; % int 64 pack_int_( N ) when is_integer( N )-> @@ -351,6 +348,7 @@ test_data()-> <<"hogehoge">>, <<"243546rf7g68h798j", 0, 23, 255>>, <<"hoasfdafdas][">>, [0,42, <<"sum">>, [1,2]], [1,42, nil, [3]], + -234, -40000, -16#10000000, -16#100000000, 42 ]. @@ -409,6 +407,7 @@ unknown_test()-> [23, 234, 0.23], [0,42,<<"sum">>, [1,2]], [1,42, nil, [3]], dict:from_list([{1,2},{<<"hoge">>,nil}]), + -234, -50000, 42 ], Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]), @@ -419,9 +418,10 @@ unknown_test()-> port_close(Port). test_([]) -> 0; -test_([S|Rest])-> - Pack = msgpack:pack(S), - {S, <<>>} = msgpack:unpack( Pack ), +test_([Before|Rest])-> + Pack = msgpack:pack(Before), + {After, <<>>} = msgpack:unpack( Pack ), + ?assertEqual(Before, After), 1+test_(Rest). other_test()-> diff --git a/erlang/testcase_generator.rb b/erlang/testcase_generator.rb index cfc36f96..8445bdd5 100644 --- a/erlang/testcase_generator.rb +++ b/erlang/testcase_generator.rb @@ -45,6 +45,7 @@ objs = [0, 1, 2, 123, 512, 1230, 678908, [23, 234, 0.23], [0,42,"sum", [1,2]], [1,42, nil, [3]], { 1 => 2, "hoge" => nil }, + -234, -50000, 42 ] begin