diff --git a/src/bert.erl b/src/bert.erl index 0faf7fb..61f4ee7 100644 --- a/src/bert.erl +++ b/src/bert.erl @@ -34,7 +34,7 @@ encode_term(Term) -> [] -> {bert, nil}; true -> {bert, true}; false -> {bert, false}; - Dict when is_record(Term, dict, 8) -> + Dict when is_tuple(Term) andalso element(1, Term) =:= dict -> {bert, dict, dict:to_list(Dict)}; List when is_list(Term) -> lists:map((fun encode_term/1), List); diff --git a/test/bert_test.erl b/test/bert_test.erl index 56dc1ba..8845c91 100644 --- a/test/bert_test.erl +++ b/test/bert_test.erl @@ -10,6 +10,11 @@ encode_tuple_nesting_test() -> Bert = term_to_binary({foo, {bert, true}}), Bert = encode({foo, true}). +encode_dict_test() -> + Bert = term_to_binary({ bert, dict, + dict:to_list(dict:store(foo, true, dict:new())) }), + Bert = encode(dict:store(foo, true, dict:new())). + %% decode decode_list_nesting_test() -> @@ -20,4 +25,11 @@ decode_list_nesting_test() -> decode_tuple_nesting_test() -> Bert = term_to_binary({foo, {bert, true}}), Term = {foo, true}, - Term = decode(Bert). \ No newline at end of file + Term = decode(Bert). + +decode_dict_test() -> + Bert = term_to_binary({ bert, dict, + dict:to_list(dict:store(foo, true, dict:new())) }), + Term = dict:store(foo, true, dict:new()), + Term = decode(Bert). +