diff --git a/src/msgpack.erl b/src/msgpack.erl index 55199f7..98af3c6 100644 --- a/src/msgpack.erl +++ b/src/msgpack.erl @@ -52,9 +52,9 @@ [{spec, new|old} | {allow_atom, none|pack} | {known_atoms, [atom()]} | - {unpack_str, as_binary|as_list|with_tag} | + {unpack_str, as_binary|as_list|as_tagged_list} | {validate_string, boolean()} | - {pack_str, from_binary|from_list|with_tag|none} | + {pack_str, from_binary|from_list|from_tagged_list|none} | {map_format, map|jiffy|jsx} | {ext, {msgpack:ext_packer(), msgpack:ext_unpacker()} | module()}]. @@ -158,14 +158,14 @@ parse_options([{allow_atom,Type}|T], Opt0) -> parse_options([{known_atoms, Atoms}|T], Opt0) when is_list(Atoms) -> parse_options(T, Opt0?OPTION{known_atoms=Atoms}); -parse_options([{unpack_str, As}|T], Opt0) when As =:= as_binary orelse As =:= as_list orelse As =:= with_tag -> +parse_options([{unpack_str, As}|T], Opt0) when As =:= as_binary orelse As =:= as_list orelse As =:= as_tagged_list -> parse_options(T, Opt0?OPTION{unpack_str=As}); parse_options([{validate_string, Bool}|T], Opt) when is_boolean(Bool) -> parse_options(T, Opt?OPTION{validate_string=Bool}); parse_options([{pack_str, From}|T], Opt) - when From =:= from_binary orelse From =:= from_list orelse From =:= with_tag orelse From =:= none -> + when From =:= from_binary orelse From =:= from_list orelse From =:= from_tagged_list orelse From =:= none -> parse_options(T, Opt?OPTION{pack_str=From}); parse_options([{map_format,Type}|T], Opt0) diff --git a/src/msgpack.hrl b/src/msgpack.hrl index 6e27cd7..4806543 100644 --- a/src/msgpack.hrl +++ b/src/msgpack.hrl @@ -26,7 +26,7 @@ %% Erlang representation of msgpack data. -type msgpack_term() :: [msgpack_term()] | msgpack_map() | - integer() | float() | boolean() | binary(). + integer() | float() | boolean() | binary() | string() | {string, string()}. -type format_type() :: jsx|jiffy|map. @@ -37,9 +37,9 @@ spec = new :: new | old, allow_atom = pack :: none | pack, %% allows atom when packing known_atoms = [] :: [atom()], - unpack_str = as_list :: as_binary | as_list | with_tag, + unpack_str = as_list :: as_binary | as_list | as_tagged_list, validate_string = false :: boolean(), - pack_str = from_list :: from_binary | from_list | with_tag | none, + pack_str = from_list :: from_binary | from_list | from_tagged_list | none, map_format = ?DEFAULT_MAP_FORMAT :: format_type(), map_unpack_fun = ?DEFAULT_MAP_UNPACKER_FUN :: msgpack_map_unpacker(), ext_packer = undefined :: msgpack:ext_packer() | undefined, diff --git a/src/msgpack_packer.erl b/src/msgpack_packer.erl index 0b6a8b6..861f3ff 100644 --- a/src/msgpack_packer.erl +++ b/src/msgpack_packer.erl @@ -61,7 +61,7 @@ pack(Map, Opt = ?OPTION{map_format=jsx}) when Map =:= [{}]-> pack([{_,_}|_] = Map, Opt = ?OPTION{map_format=jsx}) -> pack_map(Map, Opt); -pack({string, String}, ?OPTION{spec=new, pack_str=with_tag}=Opt) -> +pack({string, String}, ?OPTION{spec=new, pack_str=from_tagged_list}=Opt) -> case pack_string(String, Opt) of {error, _} -> throw({badarg, String}); Bin when is_binary(Bin) -> Bin diff --git a/src/msgpack_unpacker.erl b/src/msgpack_unpacker.erl index 516702a..b999af0 100644 --- a/src/msgpack_unpacker.erl +++ b/src/msgpack_unpacker.erl @@ -234,7 +234,7 @@ unpack_str_or_raw(V, ?OPTION{spec=new, as_binary when ValidateString -> unpack_str(V), maybe_bin(V, Opt); as_binary -> maybe_bin(V, Opt); as_list -> unpack_str(V); - with_tag -> {string, unpack_str(V)} + as_tagged_list -> {string, unpack_str(V)} end, Rest}. maybe_bin(Bin, _) -> diff --git a/test/msgpack_tests.erl b/test/msgpack_tests.erl index 0845dbb..c703530 100644 --- a/test/msgpack_tests.erl +++ b/test/msgpack_tests.erl @@ -569,15 +569,15 @@ new_spec_pack_test_() -> msgpack:pack(list_minus_one(65536), [{spec,new},{pack_str,PackStr}]))] || PackStr <- [from_list, from_binary, none]] }, - {"pack_str with_tag", + {"pack_str from_tagged_list", [?_assertEqual(<<2#101:3, 3:5, 97,97,97>>, - msgpack:pack({string, "aaa"}, [{spec,new},{pack_str,with_tag}])), + msgpack:pack({string, "aaa"}, [{spec,new},{pack_str,from_tagged_list}])), ?_assertMatch(<<16#D9, 32, _:32/binary>>, - msgpack:pack({string, list_a(32)}, [{spec,new},{pack_str,with_tag}])), + msgpack:pack({string, list_a(32)}, [{spec,new},{pack_str,from_tagged_list}])), ?_assertMatch(<<16#DA, 1, 0, _:256/binary>>, - msgpack:pack({string, list_a(256)}, [{spec,new},{pack_str,with_tag}])), + msgpack:pack({string, list_a(256)}, [{spec,new},{pack_str,from_tagged_list}])), ?_assertMatch(<<16#DB, 0, 1, 0, 0, _:65536/binary>>, - msgpack:pack({string, list_a(65536)}, [{spec,new},{pack_str,with_tag}])) + msgpack:pack({string, list_a(65536)}, [{spec,new},{pack_str,from_tagged_list}])) ] }]. @@ -616,7 +616,7 @@ new_spec_unpack_test_() -> ?_assertEqual({ok, list_a(65536)}, msgpack:unpack(<<16#DB, 0,1,0,0, (binary_a(65536))/binary>>, [{spec,new},{unpack_str,as_list}])), ?_assertEqual({ok, {string, "aaa"}}, - msgpack:unpack(<<2#101:3, 3:5, 97,97,97>>, [{spec,new},{unpack_str,with_tag}])) + msgpack:unpack(<<2#101:3, 3:5, 97,97,97>>, [{spec,new},{unpack_str,as_tagged_list}])) ]}]. unpack_str_validation_test_() ->