Bin key map (#2362)

Suppport nested bin-key map
This commit is contained in:
Shawn 2019-03-27 11:12:28 +08:00 committed by GitHub
parent e6d90d5758
commit a3fd8846a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -174,7 +174,7 @@ to_list(Msg) ->
to_bin_key_list(Msg) ->
lists:zipwith(
fun(Key, Val) ->
{bin(Key), Val}
{bin(Key), bin_key_map(Val)}
end, record_info(fields, message), tl(tuple_to_list(Msg))).
%% MilliSeconds
@ -192,6 +192,13 @@ format(flags, Flags) ->
format(headers, Headers) ->
io_lib:format("~p", [Headers]).
bin_key_map(Map) when is_map(Map) ->
maps:fold(fun(Key, Val, Acc) ->
Acc#{bin(Key) => bin_key_map(Val)}
end, #{}, Map);
bin_key_map(Data) ->
Data.
bin(Bin) when is_binary(Bin) -> Bin;
bin(Atom) when is_atom(Atom) -> list_to_binary(atom_to_list(Atom));
bin(Str) when is_list(Str) -> list_to_binary(Str).