View Source euneus_decoder (euneus v1.2.0)

JSON parser.

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 error_class() :: error | exit | throw.
-type error_handler() :: fun((error_class(), error_reason(), error_stacktrace()) -> error_stacktrace()).
-type error_stacktrace() :: erlang:stacktrace().
-type input() :: binary() | iolist().
Link to this type

invalid_option_error/0

View Source
-type invalid_option_error() :: {invalid_option, term()}.
-type normalizer(Term) :: fun((Term, parsed_options()) -> term()).
-type options() :: map().
-type parsed_options() :: #opts{}.
-type plugin() :: datetime | inet | pid | port | reference | timestamp | module().
-type position() :: non_neg_integer().
-type result() :: {ok, term()} | {error, error_reason()}.
Link to this type

unexpected_byte_error/0

View Source
-type unexpected_byte_error() :: {unexpected_byte, binary(), position()}.
Link to this type

unexpected_end_of_input_error/0

View Source
-type unexpected_end_of_input_error() :: unexpected_end_of_input.
Link to this type

unexpected_sequence_error/0

View Source
-type unexpected_sequence_error() :: {unexpected_sequence, binary(), position()}.

Functions

-spec decode(input(), options()) -> result().
Parses JSON to Erlang term.
Link to this function

decode_parsed(JSON, Opts)

View Source
-spec decode_parsed(input(), parsed_options()) -> result().
Parses JSON to Erlang term.
Link to this function

get_error_handler_option(Opts)

View Source
Link to this function

get_null_term_option(Opts)

View Source
Link to this function

get_objects_option(Opts)

View Source
Link to this function

get_plugins_option(Opts)

View Source
Link to this function

handle_error(Class, Reason, Stacktrace)

View Source
-spec handle_error(Class, Reason, Stacktrace) -> Result
                when
                    Class :: error | exit | throw,
                    Reason :: term(),
                    Stacktrace :: erlang:stacktrace(),
                    Result :: {error, term()} | no_return().
Handles decoding errors.
-spec parse_opts(options()) -> parsed_options().

Parses euneus_decoder:options() to euneus_decoder: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

resume(Token, Rest, Opts, Input, Pos, Buffer)

View Source
-spec resume(Token, Rest, Opts, Input, Pos, Buffer) -> Result
          when
              Token :: binary(),
              Rest :: bitstring(),
              Opts :: parsed_options(),
              Input :: binary(),
              Pos :: non_neg_integer(),
              Buffer :: list(),
              Result :: result().

Resumes the decoding after a token error.

Passes the null_term option as the Replacement argument of euneus_decoder:resume/7.
Link to this function

resume(Token, Replacement, Rest, Opts, Input, Pos, Buffer)

View Source
-spec resume(Token, Replacement, Rest, Opts, Input, Pos, Buffer) -> Result
          when
              Token :: binary(),
              Replacement :: term(),
              Rest :: bitstring(),
              Opts :: parsed_options(),
              Input :: binary(),
              Pos :: non_neg_integer(),
              Buffer :: list(),
              Result :: result().
Resumes the decoding after a token error.