Skip to content

Elixir implementation of MsgPack / msgpack.org[Elixir]

Notifications You must be signed in to change notification settings

ymofen/thealchemist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Alchemist

Build Status

Elixir implementation bundle for MessagePack

The Alchemist

Elixir implementation relies on mururu/msgpack-elixir GitHub version

Pure erlang implementation used with msgpack/msgpack-erlang GitHub version

Usage

### In pure elixir:

# pack
TheAlchemist.pack([1,2,3]) #=> { :ok, <<147,1,2,3>> }
TheAlchemist.pack!([1,2,3]) #=> <<147,1,2,3>>

# unpack
TheAlchemist.unpack(<<147,1,2,3>>) #=> { :ok, [1,2,3] }
TheAlchemist.unpack!(<<147,1,2,3>>) #=> [1,2,3]

# unpack_once
TheAlchemist.unpack_once(<<147,1,2,3,4>>) #=> {:ok, {[1, 2, 3], <<4>>}}
TheAlchemist.unpack_once!(<<147,1,2,3,4>>) #=> {[1, 2, 3], <<4>>}

### With underlying erlang:

Deserialization

msgpacked = TheAlchemistErl.pack('{"test":false}')
TheAlchemistErl.unpack(msgpacked)

Stream deserialization

mat = TheAlchemistErl.unpack_stream(data)
TheAlchemistErl.unpack_stream(elem(mat, 1)),

String type

Now this supports string type!

opt = [{:enable_str, true}]
TheAlchemistErl.unpack(TheAlchemistErl.pack("埼玉kanji", opt), opt)
 => {:ok, "埼玉kanji"}

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}]).

Running interactively

Firstly make all to ensure all source files are compiled after that you can bring the ERL shell with

make run

If you want to bring the IEX you can type

make runex

About

Elixir implementation of MsgPack / msgpack.org[Elixir]

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages