View Source parthenon (parthenon v0.9.0)
Link to this section Summary
Functions
Parse the provided schema and register it in the list of available schemas as the specified name.
Parse the raw Athena structure with the specified schema.
Parse the raw Athena structure with the specified schema and apply the specified options.
Link to this section Functions
-spec add_schema(SchemaName :: atom(), RawSchema :: binary() | string()) -> ok | {error, term()}.
-spec decode(SchemaName :: atom(), Binary :: binary()) -> {ok, parthenon_decode:value()} | {error, term()}.
-spec decode(SchemaName :: atom(), Binary :: binary(), Options :: [parthenon_decode:option()]) -> {ok, parthenon_decode:value()} | {error, term()}.
Parse the raw Athena structure with the specified schema and apply the specified options.
The supported options are:
object_format
: Specify the format of the objects.maps
(default): return objects as mapsproplists
: return objects as propliststuple
will return objects in the{[{<key>, <value>}]}
format
key_format
: Specify the format of the keys.atom
: return the keys as atomsbinary
will return the keys as binary.existing_atom
(default): return the keys as atoms if they already exists or return them into binary if they do not
schema_options
: Specify options to be passed to the schema.null_as
: Specify what value to use fornull
values. Acceptatom()
orbinary()
Example usage:
%% Register the `point' schema into the registry
ok = parthenon:add_schema(point, <<"struct<x: int, y: int, z: int>">>).
%% Register the `coordinates' schema into the registry
ok = parthenon:add_schema(coordinates, <<"array<struct<x: int, y: int, z: int>>">>).
%% Decode the `point' structure into a map with binary keys
{ok, #{<<"x">> := 3, <<"y">> := 2, <<"z">> := 4}} = parthenon:decode(
point, <<"{x=3, y=2, z=4}">>, [{key_format, binary}, {object_format, maps}]
).
%% Decode the `coordinates' array into a list of maps with binary keys
{ok, [#{<<"x">> := 3, <<"y">> := 2, <<"z">> := 4}, #{<<"x">> := 5, <<"y">> := 6, <<"z">> := 7}]} = parthenon:decode(
coordinates, <<"[{x=3, y=2, z=4}, {x=5, y=6, z=7}]">>, [
{key_format, binary}, {object_format, maps}
]
).