Change the API due to consistency principle #37
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #36
This PR intends to improve the Euneus API by changing some weird things about the v1. That means many code changes, so a new major version (v2) must be released.
Warning
This is a draft PR and is under development.
Plugins
Plugins are now called codecs:
So, renaming the
plugins
option tocodecs
and theeuneus_plugin
behavior toeuneus_codec
makes much sense to me.The codecs (AKA plugins) now accept arguments that need to be parsed before the encoding and decoding. Arguments are any term and are defined by passing a tuple of two elements to the codecs list, where the first element is the name of a built-in codec or the module name of a custom one, and the second is the arguments, e.g.:
To remove the need to always normalize these arguments, a new callback
init/0
is introduced ineuneus_codec
(AKA euneus_plugin) and must return{ok, term()}
.So, the
euneus_codec
behavior have now these callbacks:Encode
Encode options
The
nulls
option is now callednull_values
and its default is now[null, undefined]
instead of just[undefined]
, e.g.:This is more concise with the Javascript result:
Elixir uses
:nil
to represent null, so you must override the default to get the same result:The
drop_nulls
plugin does not exist anymore in Euneus. We now have askip_values
option for maps that drop keys that values are on this list and its default is[undefined]
, e.g.:In Javascript:
To disable this behavior, the
skip_values
option must be overridden:Encode term types
tuple
,pid
,port
, andreference
are now encoded by default via:In
v1
, these types are encoded via codecs (AKA plugins).Encode options spec
Note
This is not the end of the description of this PR. More explanation coming soon.
Suggestions welcome.
TODO: