View Source VelocyPack (VelocyPack v0.1.7)

An Elixir parser and generator for VelocyPack v1.

The implementation is heavily inspired by Jason and borrows some code (specifically the Codegen module).

Examples

iex> {:ok, vpack} = VelocyPack.encode(10.2312514)
{:ok, <<27, 245, 78, 96, 149, 102, 118, 36, 64>>}
iex> VelocyPack.decode(vpack)
{:ok, 10.2312514}

iex> vpack = VelocyPack.encode!(%{a: "a", b: %{bool: true, float: 10.2312514}})
<<11, 37, 2, 65, 97, 65, 97, 65, 98, 11, 26, 2, 68, 98, 111, 111, 108, 26, 69, 102, 108, 111, 97, 116, 27, 245, 78, 96, 149, 102, 118, 36, 64, 3, 9, 3, 7>>
iex> VelocyPack.decode!(vpack)
%{"a" => "a", "b" => %{"bool" => true, "float" => 10.2312514}}

iex> VelocyPack.decode(<<11>>)
{:error, %VelocyPack.Error{message: "unexpected sequence", dump: nil}}

iex> VelocyPack.decode!(<<11>>)
** (VelocyPack.Error) unexpected sequence

iex> VelocyPack.decode(<<11, 823891328731>>)
{:error, %VelocyPack.Error{message: "unexpected byte", dump: "<<0xDB>>"}}

iex> VelocyPack.decode!(<<11, 823891328731>>)
** (VelocyPack.Error) unexpected byte: <<0xDB>>

Summary

Functions

Parses the the first VelocyPack value from a binary or iodata.

Parses the the first VelocyPack value from a binary or iodata.

Generates a VelocyPack value as a binary corresponding to term.

Generates a VelocyPack value as a binary corresponding to term.

Types

@type vpack() :: binary() | iodata()

Functions

Link to this function

decode(vpack, opts \\ [])

View Source

Parses the the first VelocyPack value from a binary or iodata.

The options parameter is reserved for future use and not used at the moment.

Link to this function

decode!(vpack, opts \\ [])

View Source

Parses the the first VelocyPack value from a binary or iodata.

Same as decode/2 except it will unwrap the tuple and raise in case of errors.

Link to this function

encode(term, opts \\ [])

View Source

Generates a VelocyPack value as a binary corresponding to term.

The generation is controlled by the Velocy.Encoder protocol, please refer to the module to read more on how to define the protocol for custom data types.

The options parameter is reserved for future use and not used at the moment.

Link to this function

encode!(term, opts \\ [])

View Source

Generates a VelocyPack value as a binary corresponding to term.

Same as encode/2 except it will unwrap the tuple and raise in case of errors.