MessagePack (de)serializer implementation for Erlang / msgpack.org[Erlang]
Go to file
2014-04-11 08:18:47 +09:00
include fix some on type for dialyzer 2014-04-11 00:25:27 +09:00
src fix bug: 'null' atom ignored when using 17.0' 2014-04-11 08:18:47 +09:00
test add some tests 2014-04-11 08:18:11 +09:00
.gitignore update .gitignore 2013-02-18 05:07:51 +09:00
.travis.yml add newer OTP version at travis 2013-12-14 13:47:06 +09:00
dialyzer.ignore-warnings fix some dialyzing 2014-01-18 01:14:53 +09:00
LICENSE-2.0.txt add license terms and a bit cosme 2011-05-02 17:29:00 +09:00
Makefile fix some dialyzing 2014-01-18 01:14:53 +09:00
README.md added 17.0 map. next: compatibility code with rebar.config.script 2014-04-10 02:57:44 +09:00
rebar update rebar 2013-02-02 21:00:35 +09:00
rebar.config deprecate R14 because of -callback for behaviour and added 17.0 2014-04-10 01:11:00 +09:00
rebar.config.script R16 or earlier with compile option 2014-04-10 22:35:31 +09:00

MessagePack Erlang

Travis

Drone.io

prequisites for runtime

Erlang/OTP, >= R15B -- for older version, rebar won't work. Also based on the new msgpack spec 232a0d.

edit rebar.config to use in your application

{deps, [
  {msgpack, ".*",
    {git, "git://github.com/msgpack/msgpack-erlang.git", "master"}}
]}.

Simple deserialization

Ham = msgpack:pack(Spam),
{ok, Spam} = msgpack:unpack(Ham).

Stream deserialization

{Term0, Rest0} = msgpack:unpack_stream(Binary),
{Term1, Rest1} = msgpack:unpack_stream(Rest0),
...

String type

Now this supports string type!

Opt = [{enable_str, true}]
{ok, "埼玉"} = msgpack:unpack(msgpack:pack("埼玉", Opt), Opt).
 => {ok,[22524,29577]}

There are several options for msgpack:pack/2 and msgpack:unpack/2 . See msgpack:options() in msgpack.hrl.

Map Style

Since Erlang/OTP 17.0

msgpack:pack(#{ <<"key">> => <<"value">> }, [{format, map}]).

Or use old jiffy/jsx style

msgpack:pack({[{<<"key">>, <<"value">>}]}, [{format, jiffy}]),
msgpack:pack([{<<"key">>, <<"value">>}], [{format, jsx}]).

Ext type

Now msgpack-erlang supports ext type. Now you can serialize everything with your original (de)serializer. That will enable us to handle erlang- native types like pid(), ref() contained in tuple(). See test/msgpack_ext_example_tests.erl for example code.

Packer = fun({ref, Ref}, Opt) when is_reference(Ref) -> {ok, {12, term_to_binary(Ref)}} end,
Unpacker = fun(12, Bin) -> {ok, {ref, binary_to_term(Bin)}} end,
Ref = make_ref(),
Opt = [{ext,{Packer,Unpacker}}],
{ok, {ref, Ref}} = msgpack:unpack(msgpack:pack({ref, Ref}, Opt), Opt).

This is still experimental feature, so I'm waiting for your feedback.

Compatibility mode

To use as same with old spec:

OldHam = msgpack:pack(Spam, [{enable_str,false}]),
{ok, Spam} = msgpack:unpack(OldHam, [{enable_str,false}]).

Since 0.2.3 now it's false by default.

Further tests

See msgpack-erlang-tests for further tests

License

Apache License 2.0