- Notifications
You must be signed in to change notification settings - Fork80
MessagePack (de)serializer implementation for Erlang / msgpack.org[Erlang]
msgpack/msgpack-erlang
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Erlang/OTP, >= 22.0 Also based onthe new msgpack spec 0b8f5a.
{deps, [ {msgpack,".*", {git,"git://github.com/msgpack/msgpack-erlang.git", {branch,"master"}}}]}.Or as it isnow published at hex.pm, just
{deps, [msgpack]}.might work.
Ham=msgpack:pack(Spam),{ok,Spam}=msgpack:unpack(Ham).
{Term0,Rest0}=msgpack:unpack_stream(Binary),{Term1,Rest1}=msgpack:unpack_stream(Rest0),...Both for packing and unpacking. Default isnew. Major differencebetween old and new spec is:
- raw family (
0xa0~0xbf,0xda,0xdb) becomes new str family 0xd9is new as str8- new bin space (
0xc4, 0xc5, 0xc6as bin8, bin16, bin32) - new ext space (
0xc7, 0xc8, 0xc9as ext8, ext16, ext32) - new fixext space (
0xd4, 0xd5, 0xd6, 0xd7, 0xd8as fixext1, fixext2, fixext4, fixext8, fixext16),
The default is new spec. Old spec mode does not handle these new types butreturns error. To useold specmode, this option is explicitly added.
OldHam=msgpack:pack(Spam, [{spec,old}]),{ok,Spam}=msgpack:unpack(OldHam, [{spec,old}]).
Only in packing. Atoms are packed as binaries. Default value ispack.Otherwise, any term including atoms throws badarg.
Both in packing and unpacking. In packing, if an atom is in this lista binary is encoded as a binary. In unpacking, msgpacked binaries aredecoded as atoms witherlang:binary_to_existing_atom/2 with encodingutf8. Default value is an empty list.
Even ifallow_atom isnone, known atoms are packed.
A switch to choose decoded term style ofstr type whenunpacking.Only available at new spec. Default isas_list.
mode as_binary as_list-----------+------------+-------bin binary() binary()str binary() string()Handles Elixirnil asnull Erlang atom. Default value isfalse.
Only in unpacking, UTF-8 validation at unpacking fromstr type willbe enabled. Default value isfalse.
A switch to choose packing ofstring() when packing. Only availableat new spec. Default isfrom_list for symmetry withunpack_stroption.
mode from_list from_binary none-----------+------------+--------------+-----------------binary() bin str*/bin binstring() str*/array array of int array of intlist() array array arrayBut the default option pays the cost of performance for symmetry. Ifthe overhead of UTF-8 validation is unacceptable, choosingnone asthe option would be the best.
- * Tries to pack as
strif it is a validstring().
Both at packing and unpacking. Default value ismap.
msgpack:pack(#{ <<"key">>=> <<"value">> }, []).msgpack:pack(#{ <<"key">>=> <<"value">> }, [{map_format,map}]).msgpack:pack({[{<<"key">>, <<"value">>}]}, [{map_format,jiffy}]),msgpack:pack([{<<"key">>, <<"value">>}], [{map_format,jsx}]).
At both. The default behaviour in case of facing ext data at decodingis to ignore them as its length is known.
Now msgpack-erlang supports ext type. Now you can serialize everythingwith your original (de)serializer. That will enable us to handleerlang- native types likepid(),ref() contained intuple(). Seetest/msgpack_ext_example_tests.erl for example code.
Packer=fun({ref,Ref},Opt)whenis_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).
The Float type of Message Pack represents IEEE 754 floating point number, so it includes Nan and Infinity.In unpacking, msgpack-erlang returnsnan,positive_infinity andnegative_infinity.
Apache License 2.0
- Support
nan,positive_infinityandnegative_infinity
- Support OTP 19.0
- Renewed optional arguments to pack/unpack interface. This isincompatible change from 0.4 series.
- Deprecate
nil - Moved to rebar3
- Promote default map unpacker as default format when OTP is >= 17
- Added QuickCheck tests
- Since this version OTP older than R16B03-1 are no more supported
- 0.3 series will be the last versions that supports R16B or olderversions of OTP.
- OTP 18.0 support
- Promote default map unpacker as default format when OTP is >= 18
- Add OTP 17 series to Travis-CI tests
- Fix wrong numbering for ext types
- Allow packing maps even when {format,map} is not set
- Fix Dialyzer invalid contract warning
- Proper use of null for jiffy-style encoding/decoding
- set back default style as jiffy
- fix bugs around nil/null handling
- supports map new in 17.0
- jiffy-style maps will be deprecated in near future
- set default style as map
0.2 series works with OTP 17.0, R16, R15, and with MessagePack's newand old format. But does not supportmap type introduced inOTP 17.0.
It also supports JSX-compatible mode.
About
MessagePack (de)serializer implementation for Erlang / msgpack.org[Erlang]
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors14
Uh oh!
There was an error while loading.Please reload this page.