mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 21:18:23 +01:00
erlang: Make pack_map/1 api private
This commit is contained in:
parent
2c29377abf
commit
02c882bda3
@ -23,7 +23,6 @@
|
|||||||
%% APIs are almost compatible with C API (http://msgpack.sourceforge.jp/c:doc)
|
%% APIs are almost compatible with C API (http://msgpack.sourceforge.jp/c:doc)
|
||||||
%% except buffering functions (both copying and zero-copying).
|
%% except buffering functions (both copying and zero-copying).
|
||||||
-export([pack/1, unpack/1, unpack_all/1]).
|
-export([pack/1, unpack/1, unpack_all/1]).
|
||||||
-export([pack_map/1]).
|
|
||||||
|
|
||||||
% compile:
|
% compile:
|
||||||
% erl> c(msgpack).
|
% erl> c(msgpack).
|
||||||
@ -72,16 +71,6 @@ unpack_all(Data)->
|
|||||||
[Term|unpack_all(Binary)]
|
[Term|unpack_all(Binary)]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec pack_map(M::[{msgpack_term(),msgpack_term()}]) -> binary() | no_return().
|
|
||||||
pack_map(M)->
|
|
||||||
case length(M) of
|
|
||||||
Len when Len < 16 ->
|
|
||||||
<< 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>;
|
|
||||||
Len when Len < 16#10000 -> % 65536
|
|
||||||
<< 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>;
|
|
||||||
Len ->
|
|
||||||
<< 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>
|
|
||||||
end.
|
|
||||||
|
|
||||||
% ===== internal APIs ===== %
|
% ===== internal APIs ===== %
|
||||||
|
|
||||||
@ -188,6 +177,17 @@ unpack_array_(Bin, Len, Acc) ->
|
|||||||
{Term, Rest} = unpack_(Bin),
|
{Term, Rest} = unpack_(Bin),
|
||||||
unpack_array_(Rest, Len-1, [Term|Acc]).
|
unpack_array_(Rest, Len-1, [Term|Acc]).
|
||||||
|
|
||||||
|
-spec pack_map(M::[{msgpack_term(),msgpack_term()}]) -> binary() | no_return().
|
||||||
|
pack_map(M)->
|
||||||
|
case length(M) of
|
||||||
|
Len when Len < 16 ->
|
||||||
|
<< 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>;
|
||||||
|
Len when Len < 16#10000 -> % 65536
|
||||||
|
<< 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>;
|
||||||
|
Len ->
|
||||||
|
<< 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>
|
||||||
|
end.
|
||||||
|
|
||||||
pack_map_([], Acc) -> Acc;
|
pack_map_([], Acc) -> Acc;
|
||||||
pack_map_([{Key,Value}|Tail], Acc) ->
|
pack_map_([{Key,Value}|Tail], Acc) ->
|
||||||
pack_map_(Tail, << Acc/binary, (pack_(Key))/binary, (pack_(Value))/binary>>).
|
pack_map_(Tail, << Acc/binary, (pack_(Key))/binary, (pack_(Value))/binary>>).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user