summaryrefslogtreecommitdiff
path: root/erlang
diff options
context:
space:
mode:
authorVincent de Phily <vincent.dephily@gmail.com>2010-07-09 17:36:36 +0200
committerVincent de Phily <vincent.dephily@gmail.com>2010-07-09 17:36:36 +0200
commit8a3f090684f0835958e60e6a5e3e81b4d8ff541a (patch)
tree495e3c228b92fec055d25119f28021fb74b0392f /erlang
parentba4a971bfaabe7da2159a634cd07977e06c61e3a (diff)
downloadmsgpack-python-8a3f090684f0835958e60e6a5e3e81b4d8ff541a.tar.gz
erlang: Fix some existing specs and add a few other.
dialyzer still complains about dict() and ?assert(false), but I don't think they're real issues.
Diffstat (limited to 'erlang')
-rw-r--r--erlang/msgpack.erl18
1 files changed, 12 insertions, 6 deletions
diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl
index ff3eac7..fb9a3e1 100644
--- a/erlang/msgpack.erl
+++ b/erlang/msgpack.erl
@@ -29,7 +29,7 @@
% erl> c(msgpack).
% erl> S = <some term>.
% erl> {S, <<>>} = msgpack:unpack( msgpack:pack(S) ).
--type reason() :: enomem | badarg | no_code_matches | undefined.
+-type reason() :: badarg | short.
-type msgpack_term() :: [msgpack_term()]
| {[{msgpack_term(),msgpack_term()}]}
| integer() | float() | binary().
@@ -73,7 +73,7 @@ unpack_all(Data)->
[Term|unpack_all(Binary)]
end.
--spec pack_map(M::[{msgpack_term(),msgpack_term()}])-> binary() | {error, badarg}.
+-spec pack_map(M::[{msgpack_term(),msgpack_term()}]) -> binary() | no_return().
pack_map(M)->
case length(M) of
Len when Len < 16 ->
@@ -109,8 +109,9 @@ pack_({Map}) when is_list(Map) ->
pack_(Map) when is_tuple(Map), element(1,Map)=:=dict ->
pack_map(dict:to_list(Map));
pack_(_Other) ->
- throw({error, undefined}).
+ throw({error, badarg}).
+-spec pack_uint_(non_neg_integer()) -> binary().
% positive fixnum
pack_uint_(N) when N < 128 ->
<< 2#0:1, N:7 >>;
@@ -127,6 +128,7 @@ pack_uint_(N) when N < 16#FFFFFFFF->
pack_uint_(N) ->
<< 16#CF:8, N:64/big-unsigned-integer-unit:1 >>.
+-spec pack_int_(integer()) -> binary().
% negative fixnum
pack_int_(N) when N >= -32->
<< 2#111:3, N:5 >>;
@@ -143,6 +145,7 @@ pack_int_(N) when N > -16#FFFFFFFF ->
pack_int_(N) ->
<< 16#D3:8, N:64/big-signed-integer-unit:1 >>.
+-spec pack_double(float()) -> binary().
% float : erlang's float is always IEEE 754 64bit format.
% pack_float(F) when is_float(F)->
% << 16#CA:8, F:32/big-float-unit:1 >>.
@@ -151,6 +154,7 @@ pack_int_(N) ->
pack_double(F) ->
<< 16#CB:8, F:64/big-float-unit:1 >>.
+-spec pack_raw(binary()) -> binary().
% raw bytes
pack_raw(Bin) ->
case byte_size(Bin) of
@@ -162,6 +166,7 @@ pack_raw(Bin) ->
<< 16#DB:8, Len:32/big-unsigned-integer-unit:1, Bin/binary >>
end.
+-spec pack_array([msgpack_term()]) -> binary() | no_return().
% list
pack_array(L) ->
case length(L) of
@@ -178,6 +183,7 @@ pack_array_([Head|Tail], Acc) ->
pack_array_(Tail, <<Acc/binary, (pack_(Head))/binary>>).
% Users SHOULD NOT send too long list: this uses lists:reverse/1
+-spec unpack_array_(binary(), non_neg_integer(), [msgpack_term()]) -> {[msgpack_term()], binary()} | no_return().
unpack_array_(Bin, 0, Acc) -> {lists:reverse(Acc), Bin};
unpack_array_(Bin, Len, Acc) ->
{Term, Rest} = unpack_(Bin),
@@ -188,8 +194,8 @@ pack_map_([{Key,Value}|Tail], Acc) ->
pack_map_(Tail, << Acc/binary, (pack_(Key))/binary, (pack_(Value))/binary>>).
% Users SHOULD NOT send too long list: this uses lists:reverse/1
--spec unpack_map_(binary(), non_neg_integer(), [{msgpack_term(), msgpack_term()}])->
- {[{msgpack_term(), msgpack_term()}], binary()} | no_return().
+-spec unpack_map_(binary(), non_neg_integer(), [{msgpack_term(), msgpack_term()}]) ->
+ {{[{msgpack_term(), msgpack_term()}]}, binary()} | no_return().
unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin};
unpack_map_(Bin, Len, Acc) ->
{Key, Rest} = unpack_(Bin),
@@ -197,7 +203,7 @@ unpack_map_(Bin, Len, Acc) ->
unpack_map_(Rest2, Len-1, [{Key,Value}|Acc]).
% unpack them all
--spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | {error, reason()} | no_return().
+-spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | no_return().
unpack_(Bin) ->
case Bin of
% ATOMS