Search documentation of jhn_stdlib

# jhn_msgpack (jhn_stdlib v5.10.3)

View Source

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

## Types

float_type/0
floats/0
integer_type/0
integers/0
msgpack/0
msgpack_array/0
msgpack_map/0
opt/0
raw/0

## Functions

decode(Binary)

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

decode(Binary, Opts)

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.

encode(Term)

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

encode(Term, Opts)

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

# float_type/0

    -type float_type() :: float | double.

# floats/0

    -type floats() :: float() | {float_type(), float()}.

# integer_type/0

    -type integer_type() ::
              pos_fixnum | neg_fixnum | uint8 | uint16 | uint32 | uint64 | int8 | int16 | int32 | int64.

# integers/0

    -type integers() :: integer() | {integer_type(), integer()}.

# msgpack/0

    -type msgpack() :: msgpack_map() | msgpack_array() | integers() | floats() | boolean() | raw().

# msgpack_array/0

    -type msgpack_array() :: [msgpack()].

# msgpack_map/0

    -type msgpack_map() :: #{msgpack() => msgpack()}.

# opt/0

    -type opt() :: {atom_strings, boolean()} | binary | iolist.

# raw/0

    -type raw() :: binary().

# Functions

# decode(Binary)

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

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

# decode(Binary, Opts)

    -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.

# encode(Term)

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

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

# encode(Term, Opts)

    -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