msgpack-erlang icon indicating copy to clipboard operation
msgpack-erlang copied to clipboard

known_atoms option

Open frepond opened this issue 8 years ago • 3 comments

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

frepond avatar May 18 '16 12:05 frepond

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.

frepond avatar May 18 '16 14:05 frepond

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.

kuenishi avatar Dec 08 '16 23:12 kuenishi

Any news about this issue? Still no code for decoding atoms.

cleverfox avatar Nov 23 '17 15:11 cleverfox

Thanks to @cleverfox at https://github.com/msgpack/msgpack-erlang/pull/77, this issue was fixed as of 0.8.0.

kuenishi avatar Jun 09 '23 18:06 kuenishi