View Source euneus_encoder (euneus v1.2.1)

JSON generator.

Copyright 2023 William Fank Thomé

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Summary

Types

-type encoder(Input) :: fun((Input, parsed_options()) -> iolist()).
-type error_class() :: error | exit | throw.
-type error_handler() :: fun((error_class(), error_reason(), error_stacktrace()) -> error_stacktrace()).
-type error_reason() :: unsupported_type_error() | invalid_byte_error().
-type error_stacktrace() :: erlang:stacktrace().
-type escaper(Input) :: fun((Input, parsed_options()) -> iolist()).
-type input() :: term().
-type invalid_byte_error() :: {invalid_byte, Byte :: byte(), Input :: binary()}.
-type options() :: map().
-type parsed_options() :: #opts{}.
-type plugin() ::
    datetime | inet | pid | port | proplist | reference | timestamp | drop_nulls | module().
-type result() :: {ok, iolist()} | {error, error_reason()}.
Link to this type

unsupported_type_error/0

View Source
-type unsupported_type_error() :: {unsupported_type, Unsupported :: term()}.

Functions

-spec encode(input(), options()) -> result().
Generates a JSON from Erlang term.
Link to this function

encode_binary(Bin, Opts)

View Source
Link to this function

encode_float(Float, Opts)

View Source
Link to this function

encode_integer(Int, Opts)

View Source
Link to this function

encode_parsed(Term, Opts)

View Source
-spec encode_parsed(input(), parsed_options()) -> result().
Generates a JSON from Erlang term.

See also: euneus_encoder:parse_opts/1.

Link to this function

encode_unhandled(Term, Opts)

View Source
Link to this function

get_atom_encoder_option(Opts)

View Source
Link to this function

get_binary_encoder_option(Opts)

View Source
Link to this function

get_error_handler_option(Opts)

View Source
Link to this function

get_escaper_option(Opts)

View Source
Link to this function

get_float_encoder_option(Opts)

View Source
Link to this function

get_integer_encoder_option(Opts)

View Source
Link to this function

get_list_encoder_option(Opts)

View Source
Link to this function

get_map_encoder_option(Opts)

View Source
Link to this function

get_plugins_option(Opts)

View Source
Link to this function

get_unhandled_encoder_option(Opts)

View Source
Link to this function

handle_error(Class, Reason, Stacktrace)

View Source
-spec parse_opts(options()) -> parsed_options().

Parses euneus_encoder:options() to euneus_encoder:parsed_options().

The parsed map can be expanded in compile time or stored to be reused, avoiding parsing the options in every encoding.
Link to this function

throw_unsupported_type_error(Term)

View Source