View Source jhn_msgpack (jhn_stdlib v5.1.0)

A MessagePack to and from erlang terms library based on http://wiki.msgpack.org/display/MSGPACK/Format+specification.

MessagePack is represented as follows:

msgpack : map | array | integers | floats | boolean | raw map : #{msgpack => msgpack} array : [msgpack*] integers : integer | {pos_fixnum, integer} | {neg_fixnum, integer} | {uint8, integer} | {uint16, integer} | {uint32, integer} | {uint64, integer} | {int8, integer} | {int16, integer} | {int632, integer} | {int64, integer} floats : float | {'float', float} | {'double', float} nil : nil boolean : 'true' | 'false' raw : binary

Summary

Functions

Decodes the binary into a structured Erlang term. Equivalent of decode(MSGPACK, []) -> Term.

Decodes the binary into a structured Erlang. Decode will give an exception if the binary is not well formed MSGPACK. Options are: number_types -> decode into {Type, Value} for number types.

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> MSGPACK.

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned iolist -> a iolist is returned

Types

-type float_type() :: float | double.
-type floats() :: float() | {float_type(), float()}.
-type integer_type() ::
          pos_fixnum | neg_fixnum | uint8 | uint16 | uint32 | uint64 | int8 | int16 | int32 | int64.
-type integers() :: integer() | {integer_type(), integer()}.
-type msgpack() :: msgpack_map() | msgpack_array() | integers() | floats() | boolean() | raw().
-type msgpack_array() :: [msgpack()].
-type msgpack_map() :: #{msgpack() => msgpack()}.
-type opt() :: {atom_strings, boolean()} | binary | iolist.
-type raw() :: binary().

Functions

-spec decode(binary()) -> msgpack().

Decodes the binary into a structured Erlang term. Equivalent of decode(MSGPACK, []) -> Term.

-spec decode(binary(), [opt()] | #opts{return_type :: iolist | binary, number_types :: boolean()}) ->
                msgpack().

Decodes the binary into a structured Erlang. Decode will give an exception if the binary is not well formed MSGPACK. Options are: number_types -> decode into {Type, Value} for number types.

-spec encode(msgpack()) -> iolist().

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> MSGPACK.

-spec encode(msgpack(), [opt()] | #opts{return_type :: iolist | binary, number_types :: boolean()}) ->
                iolist() | binary().

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned iolist -> a iolist is returned