Closed williamthome closed 1 month ago
Closes #36
This PR prepares Euneus for a new major release using the new OTP-27 json module.
json
The code below is just a copy-paste. More info is coming soon.
1> JSON = euneus:encode(#{title => <<"The Movie">>, year => 1990, starring => ['Mike', <<"Joe">>, "Robert"]}). <<"{\"title\":\"The Movie\",\"year\":1990,\"starring\":[\"Mike\",\"Joe\",[82,111,98,101,114,116]]}">> 2> euneus:decode(JSON). #{<<"starring">> => [<<"Mike">>,<<"Joe">>,"Robert"], <<"title">> => <<"The Movie">>,<<"year">> => 1990}
-type encode() :: fun((term()) -> iodata()). -type encode_callback(Type) :: fun((Type, encode(), #state{}) -> iodata()). -type codec(Type) :: fun((Type) -> iodata()). -type atom_codec() :: codec(atom()). -type binary_codec() :: codec(binary()). -type integer_codec() :: codec(integer()). -type float_codec() :: codec(float()). -type list_codec() :: proplist | {proplist, IsProplist :: fun((list()) -> boolean())} | codec(list()). -type map_codec() :: drop_nulls | codec(map()) | [codec(map())]. -type tuple_codec() :: datetime | timestamp | ipv4 | ipv6 | {records, [{Name :: atom(), Fields :: [atom()]}]} | codec(tuple()). -type pid_codec() :: codec(pid()). -type port_codec() :: codec(port()). -type reference_codec() :: codec(reference()). -type options() :: #{ escape => fun((binary()) -> iodata()) , nulls => [term()] , sort_keys => boolean() , atom => atom_codec() | [atom_codec()] , binary => binary_codec() | [binary_codec()] , integer => integer_codec() | [integer_codec()] , float => float_codec() | [float_codec()] , list => list_codec() | [list_codec()] , map => map_codec() | [map_codec()] , tuple => tuple_codec() | [tuple_codec()] , pid => pid_codec() | [pid_codec()] , port => port_codec() | [port_codec()] , reference => reference_codec() | [reference_codec()] , encode_atom => encode_callback(atom()) , encode_binary => encode_callback(binary()) , encode_integer => encode_callback(integer()) , encode_float => encode_callback(float()) , encode_list => encode_callback(list()) , encode_map => encode_callback(map()) , encode_tuple => encode_callback(tuple()) , encode_pid => encode_callback(pid()) , encode_port => encode_callback(port()) , encode_reference => encode_callback(reference()) , integer_to_binary => fun((integer()) -> binary()) , float_to_binary => fun((float()) -> binary()) }.
-type codec(Type) :: fun((Type) -> term()). -type array_finish_fun() :: fun((list(), list()) -> {term(), list()}). -type object_finish_fun() :: fun((proplist(), proplist()) -> {term(), proplist()}). -type proplist() :: proplists:proplist(). -type array_codec() :: codec(list()). -type object_codec() :: codec(map()). -type key_codec() :: datetime | timestamp | inet | ipv4 | ipv6 | pid | port | reference | copy | atom | existing_atom | integer | {integer, Base :: 2..36} | float | list | codec(binary()). -type value_codec() :: datetime | timestamp | inet | ipv4 | ipv6 | pid | port | reference | copy | atom | existing_atom | integer | {integer, Base :: 2..36} | float | list | codec(binary()). -type options() :: #{ null => term() , array => array_codec() | [array_codec()] , object => object_codec() | [object_codec()] , key => key_codec() | [key_codec()] , value => value_codec() | [value_codec()] , array_finish => ordered | reversed | array_finish_fun() , object_finish => map | proplist | reversed_proplist | object_finish_fun() , binary_to_integer => fun((binary()) -> integer()) , binary_to_float => fun((binary()) -> float()) }.
Closing in favor of https://github.com/williamthome/euneus/pull/53.
Closes #36
This PR prepares Euneus for a new major release using the new OTP-27
json
module.Basic Usage
Encode
Decode