summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUENISHI Kota <kuenishi+github@gmail.com>2010-06-26 08:40:36 +0900
committerUENISHI Kota <kuenishi+github@gmail.com>2010-06-26 08:40:36 +0900
commita1b2b41cdcb4bbc98e21bcd334b729ec6e7b90d5 (patch)
tree042ffd7e8fbdac77ebce78b6fe7b0c8b0c169b1a
parentad052cb510e3be659df0322cbf33e4840c010b9b (diff)
downloadmsgpack-python-a1b2b41cdcb4bbc98e21bcd334b729ec6e7b90d5.tar.gz
erlang: bugfix(serialization of -234 goes <<208,22>> while it should go int16 <<0xD1, ...>>)
-rw-r--r--erlang/msgpack.erl20
-rw-r--r--erlang/testcase_generator.rb1
2 files changed, 11 insertions, 10 deletions
diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl
index 789ed53..63d648c 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 cfc36f9..8445bdd 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