msgpack-erlang
msgpack-erlang copied to clipboard
known_atoms option
Hi, according to documentation "msgpacked binaries are decoded as atoms with erlang:binary_to_existing_atom/2
with encoding utf8". It's not working for me and looking at the code I couldn't find any call to erlang:binary_to_existing_atom/2
. Am I missing something?
Kind regards
I would suggest using a map for know_atoms
and then modifying msgpack_unpacker:maybe_bin
as follow:
maybe_bin(Bin, ?OPTION{known_atoms=KnownAtoms}) ->
maps:get(Bin, KnownAtoms, Bin).
or without further modifications (to msgpack:parse_options
) I'm using something like this:
maybe_bin(Bin, ?OPTION{known_atoms=KnownAtoms}) ->
case lists:any(fun(X) -> erlang:atom_to_binary(X, utf8) =:= Bin end, KnownAtoms) of
true ->
erlang:binary_to_existing_atom(Bin, utf8);
_ ->
Bin
end;
maybe_bin(Bin, _) ->
Bin.
I thought I'd already implemented that, but somehow it's gone (from my head). You're missing nothing; it's missing. I discussed it with @mururu yesterday and will find a resolution for this soon. Thank you for pointing this out.
Any news about this issue? Still no code for decoding atoms.
Thanks to @cleverfox at https://github.com/msgpack/msgpack-erlang/pull/77, this issue was fixed as of 0.8.0.