Module euneus_decoder

Data Types

codec()

codec() = copy | timestamp | datetime | ipv4 | ipv6 | pid | port | reference | codec_callback()

codec_callback()

codec_callback() = fun((binary()) -> next | {halt, term()})

options()

options() = #{codecs => [codec()], null => term(), binary_to_float => json:from_binary_fun(), binary_to_integer => json:from_binary_fun(), array_start => json:array_start_fun(), array_push => json:array_push_fun(), array_finish => ordered | reversed | json:array_finish_fun(), object_start => json:object_start_fun(), object_keys => binary | copy | atom | existing_atom | json:from_binary_fun(), object_push => json:object_push_fun(), object_finish => map | proplist | reversed_proplist | json:object_finish_fun()}

stream_result()

stream_result() = {continue, stream_state()} | {end_of_input, term()}

stream_state()

stream_state() = json:continuation_state() | tuple()

Function Index

decode/2Decodes a binary JSON into a term.
stream_continue/2Continue parsing a stream of bytes of a JSON value.
stream_start/2Begin parsing a stream of bytes of a JSON value.

Function Details

decode/2

decode(JSON, Options) -> term()

Decodes a binary JSON into a term.

Example:

  1> euneus_decoder:decode(<<"\"foo\"">>, #{}).
  <<"foo">>

Option details:

stream_continue/2

stream_continue(JSON, State) -> stream_result()

Continue parsing a stream of bytes of a JSON value.

Similar to stream_start/2, if the function returns {continue, State} and there is no more data, use end_of_input instead of a binary.

Example:

  1> begin
  .. {continue, State} = euneus_decoder:stream_start(<<"{\"foo\":">>, #{}),
  .. euneus_decoder:stream_continue(<<"1}">>, State)
  .. end.
  {end_of_input,#{<<"foo">> => 1}}

stream_start/2

stream_start(JSON, Options) -> stream_result()

Begin parsing a stream of bytes of a JSON value.

Similar to decode/2 but returns {end_of_input, Term} when a complete JSON value is parsed or returns {continue, State} for incomplete data.

The State can be fed to the stream_continue/2 function when more data is available.


Generated by EDoc