MessagePack for Elixir / Erlang
Add messagepack
to your list of dependencies in mix.exs
:
def deps do
[{:messagepack, "== x.y.z"}]
end
or rebar.config
:
{deps, [
{messagepack, "x.y.z"},
]}.
elixir:
iex(1)> defmodule Example do
...(1)> defstruct [:compact, :schema]
...(1)> end
{:module, Example, <<...>>, %Example{compact: nil, schema: nil}}
iex(2)> x = %Example{:compact => true, :schema => 0}
%Example{compact: true, schema: 0}
iex(3)> b = Messagepack.encode!(x)
<<...>>
iex(4)> byte_size(b)
44
iex(5)> x = Messagepack.decode!(b)
%Example{compact: true, schema: 0}
erlang:
1> X = #{compact => true, schema => 0}.
#{compact => true,schema => 0}
2> {ok, B} = messagepack:encode(X).
{ok,<<130,167,99,111,109,112,97,99,116,195,166,115,99,104,101,109,97,0>>}
3> byte_size(B).
18
4> {ok, X} = messagepack:decode(B).
{ok,#{compact => true,schema => 0}}
Apache-2.0