View Source euneus_decoder (euneus v1.0.1)

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

Functions

Parses JSON to Erlang term.
Parses JSON to Erlang term.
Handles decoding errors.

Resumes the decoding after a token error.

Resumes the decoding after a token error.

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, options()) -> term()).
-type options() ::
    #{null_term => term(),
      keys => copy | to_atom | to_existing_atom | to_integer | normalizer(Key :: binary()),
      values => copy | to_atom | to_existing_atom | to_integer | normalizer(Value :: binary()),
      arrays => normalizer(Array :: list()),
      objects => normalizer(Object :: map()),
      error_handler => error_handler(),
      plugins => [plugin()]}.
-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(), map()) -> result().
Parses JSON to Erlang term.
Link to this function

decode_parsed(JSON, Opts)

View Source
-spec decode_parsed(input(), options()) -> result().
Parses JSON to Erlang term.
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(map()) -> options().

Parses erlang:map() to euneus_encoder:options().

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

See also: euneus_encoder:encode_parsed/2, euneus_encoder:parse_opts/1.

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 :: 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 :: options(),
              Input :: binary(),
              Pos :: non_neg_integer(),
              Buffer :: list(),
              Result :: result().
Resumes the decoding after a token error.