Skip to content

Commit 90586fb

Browse files
committed
Merge pull request #33 from iced/master
Proper use of null for jiffy-style encoding/decoding.
2 parents 952f85f + c8a0b44 commit 90586fb

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/msgpack.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ parse_options([{ext, {Packer,Unpacker}}|TL], Opt0) when
166166
-include_lib("eunit/include/eunit.hrl").
167167

168168
test_data()->
169-
[true, false, nil,
169+
[true, false, null,
170170
0, 1, 2, 123, 512, 1230, 678908, 16#FFFFFFFFFF,
171171
-1, -23, -512, -1230, -567898, -16#FFFFFFFFFF,
172172
-16#80000001,
173173
123.123, -234.4355, 1.0e-34, 1.0e64,
174174
[23, 234, 0.23],
175175
<<"hogehoge">>, <<"243546rf7g68h798j", 0, 23, 255>>,
176176
<<"hoasfdafdas][">>,
177-
[0,42, <<"sum">>, [1,2]], [1,42, nil, [3]],
177+
[0,42, <<"sum">>, [1,2]], [1,42, null, [3]],
178178
-234, -40000, -16#10000000, -16#100000000,
179179
42
180180
].

src/msgpack_packer.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ pack(F, _) when is_float(F) ->
3434
pack_double(F);
3535
pack(null, _Opt = ?OPTION{interface=jsx}) ->
3636
<< 16#C0:8 >>;
37+
pack(null, _Opt = ?OPTION{interface=jiffy}) ->
38+
<< 16#C0:8 >>;
3739
pack(nil, _Opt = ?OPTION{interface=Interface})
38-
when Interface =/= jsx ->
40+
when Interface =/= jsx andalso Interface =/= jiffy ->
3941
<< 16#C0:8 >>;
4042
pack(false, _) ->
4143
<< 16#C2:8 >>;

src/msgpack_unpacker.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
%% ATOMS
3636
unpack_stream(<<16#C0, Rest/binary>>, _Opt = ?OPTION{interface=jsx}) ->
3737
{null, Rest};
38+
unpack_stream(<<16#C0, Rest/binary>>, _Opt = ?OPTION{interface=jiffy}) ->
39+
{null, Rest};
3840
unpack_stream(<<16#C0, Rest/binary>>, _) ->
3941
{nil, Rest};
4042
unpack_stream(<<16#C2, Rest/binary>>, _) ->

test/msgpack_test.erl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,22 @@ issue_jiffy_5_test() ->
146146

147147
issue_27_test_() ->
148148
[
149-
%% nil(jiffy) => nil(msgpack) => null(jsx)
149+
%% null(jiffy) => nil(msgpack) => null(jsx)
150150
?_assertEqual({ok, null},
151-
msgpack:unpack(msgpack:pack(nil), [{format,jsx}])),
151+
msgpack:unpack(msgpack:pack(null), [{format,jsx}])),
152152

153-
%% nil(jiffy) => nil(msgpack) => nil(jiffy)
154-
?_assertEqual({ok, nil},
155-
msgpack:unpack(msgpack:pack(nil, [{format,jiffy}]))),
153+
%% null(jiffy) => nil(msgpack) => null(jiffy)
154+
?_assertEqual({ok, null},
155+
msgpack:unpack(msgpack:pack(null, [{format,jiffy}]))),
156156

157157

158-
%% null(jsx) => nil(msgpack) => nil(jiffy)
159-
?_assertEqual({ok, nil},
158+
%% null(jsx) => nil(msgpack) => null(jiffy)
159+
?_assertEqual({ok, null},
160160
msgpack:unpack(msgpack:pack(null, [{format,jsx}]))),
161161

162-
%% null(jiffy-atom) => <<null>>(msgpack-binary) => <<"nil">>
163-
?_assertEqual({ok, <<"null">>},
164-
msgpack:unpack(msgpack:pack(null, [{allow_atom,pack}]))),
162+
%% nil(jiffy-atom) => <<nil>>(msgpack-binary) => <<"nil">>
163+
?_assertEqual({ok, <<"nil">>},
164+
msgpack:unpack(msgpack:pack(nil, [{allow_atom,pack}]))),
165165

166166
%% nil(jsx-atom) => <<nil>>(msgpack-binary) => <<"nil">>
167167
?_assertEqual({ok, <<"nil">>},

0 commit comments

Comments
 (0)