williamthome / euneus

An incredibly flexible and performant JSON parser, generator and formatter in pure Erlang.
https://hex.pm/packages/euneus
Apache License 2.0
22 stars 2 forks source link

Implement plugins mechanism #26

Closed williamthome closed 9 months ago

williamthome commented 9 months ago

Closes #25

This PR adds plugins to the encode and decode options.

The idea to add this mechanism is to plug more types into Euneus without decreasing the performance if some types are not needed.

How it works

There is now a behavior called euneus_plugin. Modules that implement it can be used in encode and decode options. The plugins option receives a list of modules, for example:

1> {ok, JSON} = euneus:encode_to_binary({127,0,0,1}, #{plugins => [inet]}).
{ok,<<"\"127.0.0.1\"">>}

2> euneus:decode(JSON, #{plugins => [inet]}).
{ok,{127,0,0,1}}

Built-in plugins

[!IMPORTANT] This PR deprecates the datetime_encoder and the timestamp_encoder in favor of the datetime and timestamp plugins.