It's like JSON.
but fast and small.

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.

Redis scripting has support for MessagePack because it is a fast and compact serialization format with a simple to implement specification. I liked it so much that I implemented a MessagePack C extension for Lua just to include it into Redis.

Salvatore Sanfilippo, creator of Redis

Fluentd uses MessagePack for all internal data representation. It's crazy fast because of zero-copy optimization of msgpack-ruby. Now MessagePack is an essential component of Fluentd to achieve high performance and flexibility at the same time.

Sadayuki Furuhashi, creator of Fluentd

Treasure Data built a multi-tenant database optimized for analytical queries using MessagePack. The schemaless database is growing by billions of records every month. We also use MessagePack as a glue between components. Actually we just wanted a fast replacement of JSON, and MessagePack is simply useful.

Kazuki Ohta, CTO

MessagePack has been simply invaluable to us. We use MessagePack + Memcache to cache many of our feeds on Pinterest. These feeds are compressed and very quick to unpack thanks to MessagePack while Memcache gives us fast atomic pushes.

Marty Weiner, Software Engineer

Also use MessagePack? Waiting for your testimonial!



List your implementation here!


MessagePack for Java

QuickStart for msgpack-java is available here.

How to install

You can install msgpack via maven:

Simple Serialization/Deserialization/Duck Typing using Value
// Create serialize objects.
List<String> src = new ArrayList<String>();

MessagePack msgpack = new MessagePack();
// Serialize
byte[] raw = msgpack.write(src);

// Deserialize directly using a template
List<String> dst1 =, Templates.tList(Templates.TString));

// Or, Deserialze to Value then convert type.
Value dynamic =;
List<String> dst2 = new Converter(dynamic)


Build Status

MessagePack for D

MessagePack is a binary-based JSON-like serialization library.

MessagePack for D is a pure D implementation of MessagePack.

  • Small size and High performance
  • Zero copy serialization / deserialization
  • Stream deserializer / Direct-conversion deserializer
  • Supports D features (Ranges, Tuples, real type)

Note: The real type is only supported in D. Don't use the real type when communicating with other programming languages. Note that Unpacker will raise an exception if a loss of precision occurs.

Current Limitations
  • No circular references support

msgpack-d is implemented as a single module. Either copy src/msgpack.d to your project or use dub to add it as a dependency:

% dub install msgpack-d

Example code can be found in the example directory.

The documentation can be found here

pack / unpack

msgpack-d is very simple to use. Use pack for serialization, and unpack for deserialization:

import std.file;
import msgpack;

struct S { int x; float y; string z; }

void main()
    S input = S(10, 25.5, "message");

    // serialize data
    ubyte[] inData = pack(input);

    // write data to a file
    write("file.dat", inData);

    // read data from a file
    ubyte[] outData = cast(ubyte[])read("file.dat");

    // unserialize the data
    S target = outData.unpack!S();

    // verify data is the same
    assert(target.x == input.x);
    assert(target.y == input.y);
    assert(target.z == input.z);
Feature: Skip serialization/deserialization of a specific field.

Use the @nonPacked attribute:

struct User
    string name;
    @nonPacked int level;  // pack / unpack will ignore the 'level' field
Feature: Use your own serialization/deserialization routines for custom class and struct types.

msgpack-d provides the functions registerPackHandler / registerUnpackHandler to allow you to use custom routines during the serialization or deserialization of user-defined class and struct types. This feature is especially useful when serializing a derived class object when that object is statically typed as a base class object.

For example:

class Document { }
class XmlDocument : Document
    this() { }
    this(string name) { = name; }
    string name;

void xmlPackHandler(ref Packer p, ref XmlDocument xml)

void xmlUnpackHandler(ref Unpacker u, ref XmlDocument xml)

void main()
    /// Register the 'xmlPackHandler' and 'xmlUnpackHandler' routines for
    /// XmlDocument object instances.
    registerPackHandler!(XmlDocument, xmlPackHandler);
    registerUnpackHandler!(XmlDocument, xmlUnpackHandler);

    /// Now we can serialize/deserialize XmlDocument object instances via a
    /// base class reference.
    Document doc = new XmlDocument("test.xml");
    auto data = pack(doc);
    XmlDocument xml = unpack!XmlDocument(data);
    assert( == "test.xml");  // is "test.xml"
The PackerImpl / Unpacker / StreamingUnpacker types

These types are used by the pack and unpack functions.

See the documentation of PackerImpl, Unpacker and StreamingUnpacker for more details.

Copyright (c) 2010- Masahiro Nakagawa

Distributed under the Boost Software License, Version 1.0.


MessagePack for Python
Author: INADA Naoki
Version: 0.4.6
Date: 2015-03-13 Latest Version
What's this

MessagePack is a fast, compact binary serialization format, suitable for similar data to JSON. This package provides CPython bindings for reading and writing MessagePack data.

$ pip install msgpack-python

msgpack-python provides pure python implementation. PyPy can use this.


When you can't use binary distribution, you need to install Visual Studio or Windows SDK on Windows. (NOTE: Visual C++ Express 2010 doesn't support amd64. Windows SDK is recommended way to build amd64 msgpack without any fee.)

Without extension, using pure python implementation on CPython runs slowly.

Note for msgpack 2.0 support

msgpack 2.0 adds two types: bin and ext.

raw was bytes or string type like Python 2's str. To distinguish string and bytes, msgpack 2.0 adds bin. It is non-string binary like Python 3's bytes.

To use bin type for packing bytes, pass use_bin_type=True to packer argument.

>>> import msgpack
>>> packed = msgpack.packb([b'spam', u'egg'], use_bin_type=True)
>>> msgpack.unpackb(packed, encoding='utf-8')
['spam', u'egg']

You shoud use it carefully. When you use use_bin_type=True, packed binary can be unpacked by unpackers supporting msgpack-2.0.

To use ext type, pass msgpack.ExtType object to packer.

>>> import msgpack
>>> packed = msgpack.packb(msgpack.ExtType(42, b'xyzzy'))
>>> msgpack.unpackb(packed)
ExtType(code=42, data='xyzzy')

You can use it with default and ext_hook. See below.

Note for msgpack 0.2.x users

The msgpack 0.3 have some incompatible changes.

The default value of use_list keyword argument is True from 0.3. You should pass the argument explicitly for backward compatibility.

Unpacker.unpack() and some unpack methods now raises OutOfData instead of StopIteration. StopIteration is used for iterator protocol only.

How to use
One-shot pack & unpack

Use packb for packing and unpackb for unpacking. msgpack provides dumps and loads as alias for compatibility with json and pickle.

pack and dump packs to file-like object. unpack and load unpacks from file-like object.

>>> import msgpack
>>> msgpack.packb([1, 2, 3])
>>> msgpack.unpackb(_)
[1, 2, 3]

unpack unpacks msgpack's array to Python's list, but can unpack to tuple:

>>> msgpack.unpackb(b'\x93\x01\x02\x03', use_list=False)
(1, 2, 3)

You should always pass the use_list keyword argument. See performance issues relating to use_list option below.

Read the docstring for other options.

Streaming unpacking

Unpacker is a "streaming unpacker". It unpacks multiple objects from one stream (or from bytes provided through its feed method).

import msgpack
from io import BytesIO

buf = BytesIO()
for i in range(100):

unpacker = msgpack.Unpacker(buf)
for unpacked in unpacker:
    print unpacked
Packing/unpacking of custom data type

It is also possible to pack/unpack custom data types. Here is an example for datetime.datetime.

import datetime

import msgpack

useful_dict = {
    "id": 1,

def decode_datetime(obj):
    if b'__datetime__' in obj:
        obj = datetime.datetime.strptime(obj["as_str"], "%Y%m%dT%H:%M:%S.%f")
    return obj

def encode_datetime(obj):
    if isinstance(obj, datetime.datetime):
        return {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f")}
    return obj

packed_dict = msgpack.packb(useful_dict, default=encode_datetime)
this_dict_again = msgpack.unpackb(packed_dict, object_hook=decode_datetime)

Unpacker's object_hook callback receives a dict; the object_pairs_hook callback may instead be used to receive a list of key-value pairs.

Extended types

It is also possible to pack/unpack custom data types using the msgpack 2.0 feature.

>>> import msgpack
>>> import array
>>> def default(obj):
...     if isinstance(obj, array.array) and obj.typecode == 'd':
...         return msgpack.ExtType(42, obj.tostring())
...     raise TypeError("Unknown type: %r" % (obj,))
>>> def ext_hook(code, data):
...     if code == 42:
...         a = array.array('d')
...         a.fromstring(data)
...         return a
...     return ExtType(code, data)
>>> data = array.array('d', [1.2, 3.4])
>>> packed = msgpack.packb(data, default=default)
>>> unpacked = msgpack.unpackb(packed, ext_hook=ext_hook)
>>> data == unpacked
Advanced unpacking control

As an alternative to iteration, Unpacker objects provide unpack, skip, read_array_header and read_map_header methods. The former two read an entire message from the stream, respectively deserialising and returning the result, or ignoring it. The latter two methods return the number of elements in the upcoming container, so that each element in an array, or key-value pair in a map, can be unpacked or skipped individually.

Each of these methods may optionally write the packed data it reads to a callback function:

from io import BytesIO

def distribute(unpacker, get_worker):
    nelems = unpacker.read_map_header()
    for i in range(nelems):
        # Select a worker for the given key
        key = unpacker.unpack()
        worker = get_worker(key)

        # Send the value as a packed message to worker
        bytestream = BytesIO()
Note about performance

CPython's GC starts when growing allocated object. This means unpacking may cause useless GC. You can use gc.disable() when unpacking large message.

use_list option

List is the default sequence type of Python. But tuple is lighter than list. You can use use_list=False while unpacking when performance is important.

Python's dict can't use list as key and MessagePack allows array for key of mapping. use_list=False allows unpacking such message. Another way to unpacking such object is using object_pairs_hook.


MessagePack uses pytest for testing. Run test with following command:

$ py.test


MessagePack Erlang


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://", "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


Apache License 2.0

Release Notes
  • 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 new and old format. But does not support map type introduced in OTP 17.0.

It also supports JSX-compatible mode.


MessagePack for Ruby
require 'msgpack'
msg = [1,2,3].to_msgpack  #=> "\x93\x01\x02\x03"
MessagePack.unpack(msg)   #=> [1,2,3]
gem install msgpack
Use cases
  • Create REST API returing MessagePack using Rails + RABL
  • Store objects efficiently in memcached or Redis
  • Upload data in efficient format from mobile devices. See also MessagePack for Objective-C and Java
Streaming API
# serialize a 2-element array [e1, e2]
pk =
# deserialize objects from an IO
u =
u.each { |obj| ... }
# event-driven deserialization
def on_read(data)
  @u ||=
  @u.feed_each(data) { |obj| ... }


MessagePack for Scala

An implementation of MessagePack for Scala.

  • sbt 0.13.5 or later

Add dependency.

libraryDependencies += "org.msgpack" %% "msgpack-scala" % "0.6.11"
For developer
Make intellij project

Please type the following command.Then intellij project will be generated.

$ sbt gen-idea
Quick Start
Serialize/Deserialize class
import org.msgpack.annotation.Message
import org.msgpack.ScalaMessagePack

@Message // Don't forget to add Message annotation.
class YourClass{
  var name : String = ""
  var age : Int = 2

val obj = new YourClass() = "hoge"
obj.age = 22
val serialized : Array[Byte] = ScalaMessagePack.write(obj)

val deserialized : YourClass =[YourClass](serialized)
  • Sorry, case classes are not supported now.




An alternative implementation for Ruby and C++


MIT License Haxelib Version


MessagePack ( serialization library for HaXe

How to install:

Simply use haxelib git to use this github repo or haxelib install msgpack-haxe to use the one in the haxelib repository.

Supported Type:
  • Null
  • Bool
  • Int
  • Float
  • Object
  • Bytes
  • String
  • Array
  • IntMap/StringMap
Example code:
import org.msgpack.MsgPack;

class Example {
    public static function main() {
        var i = { a: 1, b: 2, c: "Hello World!" };
        var m = MsgPack.encode(i);
        var o = MsgPack.decode(m);



MessagePack for CLI
What is it?

This is MessagePack serialization/deserialization for CLI (Common Language Infrastructure) implementations such as .NET Framework, Silverlight, Mono (including Moonlight.) This library can be used from ALL CLS compliant languages such as C#, F#, Visual Basic, Iron Pyhton, Iron Ruby, PowerShell, C++/CLI or so.


You can serialize/deserialize objects as following: 1. Create serializer via MessagePackSerializer.Create generic method. This method creates dependent types serializers as well. 1. Invoke serializer as following: ** Pack method with destination Stream and target object for serialization. ** Unpack method with source Stream.

// Creates serializer.
var serializer = SerializationContext.Default.GetSerializer<T>();
// Pack obj to stream.
serializer.Pack(stream, obj);
// Unpack from stream.
var unpackedObject = serializer.Unpack(stream);
' Creates serializer.
Dim serializer = SerializationContext.Default.GetSerializer(Of T)()
' Pack obj to stream.
serializer.Pack(stream, obj)
' Unpack from stream.
Dim unpackedObject = serializer.Unpack(stream)
  • Fast and interoperable binary format serialization with simple API.
  • Generating pre-compiled assembly for rapid start up.
  • Flexible MessagePackObject which represents MessagePack type system naturally.

See wiki

  • Binary files distributed via the NuGet package MsgPack.Cli.
  • You can extract binary (DLL) file as following:
    1. Download *.zip file from GitHub Release page.
    2. Extract it.
    3. Under the bin directory, binaries are there!
      • For mono, you can use net45 or net35 drops as you run with.
      • For Unity, unity3d drop is suitable.
How to build
For .NET Framework
  1. Install recent Windows SDK (at least, .NET Framework 4 Client Profile and MSBuild is needed.)
    Or install Visual Studio or Visual Studio Express.
    1. If you want to build unit test assemblies, install NuGet and then restore NUnit packages.
  2. Run:

    msbuild MsgPack.sln

    Or (for .NET 3.5 drops, Silverlight 4 drops, and Silverlight 5 drops):

    msbuild MsgPack.compats.sln

Or open one of above solution files in your IDE and run build command in it.

For Mono

Open MsgPack.mono.sln with MonoDevelop and then click Build menu item. (Of cource, you can build via xbuild.)

See also


msgpack for C/C++

Version 1.0.1 Build Status

It's like JSON but small and fast.


MessagePack is an efficient binary serialization format, which lets you exchange data among multiple languages like JSON, except that it's faster and smaller. Small integers are encoded into a single byte while typical short strings require only one extra byte in addition to the strings themselves.


In C:

#include <msgpack.h>
#include <stdio.h>

int main(void)
    /* msgpack::sbuffer is a simple buffer implementation. */
    msgpack_sbuffer sbuf;

    /* serialize values into the buffer using msgpack_sbuffer_write callback function. */
    msgpack_packer pk;
    msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);

    msgpack_pack_array(&pk, 3);
    msgpack_pack_int(&pk, 1);
    msgpack_pack_str(&pk, 7);
    msgpack_pack_str_body(&pk, "example", 7);

    /* deserialize the buffer into msgpack_object instance. */
    /* deserialized object is valid during the msgpack_zone instance alive. */
    msgpack_zone mempool;
    msgpack_zone_init(&mempool, 2048);

    msgpack_object deserialized;
    msgpack_unpack(, sbuf.size, NULL, &mempool, &deserialized);

    /* print the deserialized object. */
    msgpack_object_print(stdout, deserialized);


    return 0;

See for more details.

In C++:

#include <msgpack.hpp>
#include <string>
#include <iostream>
#include <sstream>

int main(void)
    msgpack::type::tuple<int, bool, std::string> src(1, true, "example");

    // serialize the object into the buffer.
    // any classes that implements write(const char*,size_t) can be a buffer.
    std::stringstream buffer;
    msgpack::pack(buffer, src);

    // send the buffer ...

    // deserialize the buffer into msgpack::object instance.
    std::string str(buffer.str());

    msgpack::unpacked result;

    msgpack::unpack(result,, str.size());

    // deserialized object is valid during the msgpack::unpacked instance alive.
    msgpack::object deserialized = result.get();

    // msgpack::object supports ostream.
    std::cout << deserialized << std::endl;

    // convert msgpack::object instance into the original type.
    // if the type is mismatched, it throws msgpack::type_error exception.
    msgpack::type::tuple<int, bool, std::string> dst;

    return 0;

See for more details.

C++ Header Only Library

When you use msgpack on C++03 and C++11, you can just add msgpack-c/include to your include path:

g++ -I msgpack-c/include your_source_file.cpp

If you want to use C version of msgpack, you need to build it. You can also install the C and C++ versions of msgpack.

Building and Installing Install from git repository
Using autotools

You will need:

  • gcc >= 4.1.0 or clang >= 3.3.0
  • autoconf >= 2.60
  • automake >= 1.10
  • libtool >= 2.2.4

The build steps below are for C and C++03. If compiling for C++11, add -std=c++11 to the environmental variable CXXFLAGS with export CXXFLAGS="$CXXFLAGS -std=c++11" prior to following the directions below.

$ git clone
$ cd msgpack-c
$ ./bootstrap
$ ./configure
$ make

You can install the resulting library like this:

$ sudo make install
Using cmake
Using the Terminal (CLI)

You will need:

  • gcc >= 4.1.0
  • cmake >= 2.8.0

C and C++03:

$ git clone
$ cd msgpack-c
$ cmake .
$ make
$ sudo make install

If you want to setup C++11 version of msgpack instead, execute the following commands:

$ git clone
$ cd msgpack-c
$ cmake -DMSGPACK_CXX11=ON .
$ sudo make install
GUI on Windows

Clone msgpack-c git repository.

$ git clone

or using GUI git client.

e.g.) tortoise git

  1. Launch cmake GUI client.

  2. Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.

  3. Click 'Configure' button.

  4. Choose your Visual Studio version.

  5. Click 'Generate' button.

  6. Open the created msgpack.sln on Visual Studio.

  7. Build all.


You can get addtional information on the wiki.


msgpack-c is developed on GitHub at msgpack/msgpack-c. To report an issue or send a pull request, use the issue tracker.

Here's the list of great contributors.


msgpack-c is licensed under the Apache License Version 2.0. See the LICENSE file for details.


MsgPack for OCaml
$ make
$ sudo make install
Serialize/Deserialize for Msgpack Object
(* serialize *)
let bytes = 
  Msgpack.Serialize.serialize_string (`FixArray [`PFixnum 1; `PFixnum 2; `PFixnum 3])

(* deserialize *)
let obj =
  Msgpack.Serialize.deserialize_string bytes
Serialize/Deserialize for OCaml types (with meta_conv)
open Msgpack_conv

type t = {
  int : int;
  str : string;
} with conv(msgpack)

(* serialize *)
let bytes = 
  Msgpack.Serialize.serialize_string (msgpack_of_t { int = 42; str = "ans" })

(* deserialize *)
let obj =
  t_of_msgpack (Msgpack.Serialize.deserialize_string bytes)

See also, examlpe/

$ ocaml -configure --enable-tests
$ make test

If you want to use msgpack at OCaml, you need not do this section. This section for user intrested in formal verification.

You need Coq 8.4 and omake.

$ cd proof
$ make
$ cp *.ml ../lib



MessagePack serialization library for various Smalltalk dialects.

  • Squeak
  • Pharo
  • VisualWorks
  • VA Smalltalk
  • Dolphin Smalltalk
  • GNU Smalltalk (Beta)
  • Cuis

Sources are put as Cypress for the neutral accesses from various Smalltalk dialects.

How to use
MpMessagePack pack: <your object>


<your object> messagePacked
MpMessagePack unpack: msgpackBytes


Object fromMessagePack: msgBytes
map := Dictionary new.
map at: 'someArray' asByteArray put: #(1 2.2 #[3 4 5]).
packed := map messagePacked.
(Object fromMessagePack: packed) inspect.
writeStream := WriteStream on: ByteArray new.
encoder := MpEncoder on: writeStream.
encoder nextPut: 1.
encoder nextPut: #(2 3).
dic := Dictionary new.
dic at: 4 put: 5.
encoder nextPut: dic.
encoder nextPut: 'four' asByteArray.
bytes := encoder contents.
readStream := ReadStream on: bytes.
decoder := MpDecoder on: readStream.
[decoder atEnd] whileFalse: [
        Transcript cr; show: decoder next printString

We are moving from Google Code site. Old contents including installation guide are still there.


MessagePack for Actionscript3 (Flash, Flex and AIR).

as3-msgpack was designed to work with the interfaces IDataInput and IDataOutput, thus the API might be easily connected with the native classes that handle binary data (such as ByteArray, Socket, FileStream and URLStream).
Moreover, as3-msgpack is capable of decoding data from binary streams.
Get started:

Basic usage (encoding/decoding):

// create messagepack object
var msgpack:MsgPack = new MsgPack();

// encode an array
var bytes:ByteArray = msgpack.write([1, 2, 3, 4, 5]);

// rewind the buffer
bytes.position = 0;

// print the decoded object

For downloads, source code and further information, check the project repository:


Msgpack for PHP

Build Status

This extension provide API for communicating with MessagePack serialization.

MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.

  • PHP 5.0 +
Install from PECL

Msgpack is an PECL extension, thus you can simply install it by:

pecl install msgpack
Compile Msgpack from source
$make && make install
$data = array(0=>1,1=>2,2=>3);
$msg = msgpack_pack($data);
$data = msgpack_unpack($msg);


MessagePack for Lua (spec v5)

Build Status Coverage Status Licence Dependencies

local mp = require 'MessagePack'
mpac = mp.pack(data)
data = mp.unpack(mpac)

You can use LuaRocks to install lua-MessagePack:

$ luarocks install lua-messagepack

or from the source, with:

$ make install

It is a pure Lua implementation, without any dependency.

Copyright and License

Copyright (c) 2012-2015 Francois Perrad rank

This library is licensed under the terms of the MIT/X11 license, like Lua itself.


rust-msgpack Build Status

Msgpack implementation for Rust language.


Simply include the rust-msgpack in your Cargo dependencies.


git = ""
extern crate msgpack;

fn main() {
  let arr = vec!["str1".to_string(), "str2".to_string()];
  let str = msgpack::Encoder::to_msgpack(&arr).ok().unwrap();
  println!("Encoded: {}", str);

  let dec: Vec<String> = msgpack::from_msgpack(str).ok().unwrap();
  println!("Decoded: {}", dec);

To enable your own data structures to be automatically serialized from and to msgpack, derive from Encodable and Decodable as shown in the following example:

extern crate serialize;

struct MyStruct {
  a: Vec<u32>,
  s: String
cargo test

This code licensed under the same terms as Rust itself: dual MIT/Apache2 license options.


MessagePack for Elixir

Build Status


Add :message_pack as a dependency in your mix.exs file.

defp deps do
  [{:message_pack, "~> 0.1.4"}]
# pack
MessagePack.pack([1,2,3]) #=> { :ok, <<147,1,2,3>> }
MessagePack.pack!([1,2,3]) #=> <<147,1,2,3>>

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

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

Support string type. This options is false by default.

iex(1)> { :ok, bin } = MessagePack.pack(<<255>>)
{:ok, <<161, 255>>}
iex(3)> MessagePack.unpack(<<161, 255>>)
{:ok, <<255>>}
iex(4)> MessagePack.unpack(<<161, 255>>, enable_string: true)
{:error, {:invalid_string, <<255>>}}
  • ext

Support extention type.

See test/message_pack_ext_test.exs.




MessagePack for R6RS Scheme

This is an implementation of MessagePack for R6RS Scheme.

API references

Function (pack! bv message)
Function (pack! bv message offset)

Pack message to message pack format bytevector and put it into the bv destructively. Given bv must have enough length to hold the message.

Optional argument offset indicates where to start with, default is 0.

Function (pack message)

The same as pack! but this one creates a new bytevector.

Function (pack-size message)

Calculate the converted message size.

Function (unpack bv)
Function (unpack bv offset)

Unpack the given message format bytevector to Scheme object.

Optional argument offset indicates where to start with, default is 0.

Function (get-unpack in)

Unpack the given binary input port to Scheme object.

Conversion rules

As you already know, Scheme doesn't have static types so the conversion of Scheme objects to message pack data might cause unexpected results. To avoid it, I will describe how conversion works.

Scheme to message pack Integer conversion

The library automatically decides proper size. More specifically, if it can fit to message pack's fixnum then library uses it, so are uint8-64. If the number is too big, then an error is raised. Users must know it tries to use uint as much as possible. If the given number was negative then sint will be used.

Floating point conversion

Unfortunately R6RS doesn't have difference between float and double. So when flonum is given then it always converts to double number.

Collection conversion

Message pack has collections which are map and array. And these are associated with alist (association list) and vector respectively. When you want to convert alist to message pack data, then you need to make sure the cdr part will be the data and if you put (("key" "value))_ then it will be converted to nested map.

The collection size calculation is done automatically. It tries to use the smallest size.

Message pack to Scheme

The other way around is easy, it can simply restore the byte data to Scheme object. Following describes the conversion rules;

Positive fixnum -> integer
Negative fixnum -> integer
uint8, uint16, uint32, uint64 -> integer
sint8, sint16, sint32, sint64 -> integer
Map -> alist
Array -> vector
fixstr, str8, str16, str32 -> string bit8, bit16, bit32 -> bytevector

Tested Scheme implementations

Sagittarius Scheme

Mosh Scheme


Your contributions are always welcome.

  • More testing
  • Extended type handling


MessagePack and Binc Codec for Go Language.

A High Performance, Feature-Rich, Idiomatic encode/decode and rpc library.

To install:

go get

Source: []
Online documentation: []

Typical usage:

    // create and use decoder/encoder
    var (
        v interface{} // value to decode/encode into
        r io.Reader
        w io.Writer
        b []byte
        mh codec.MsgpackHandle

    dec = codec.NewDecoder(r, &mh)
    dec = codec.NewDecoderBytes(b, &mh)
    err = dec.Decode(&v) 

    enc = codec.NewEncoder(w, &mh)
    enc = codec.NewEncoderBytes(&b, &mh)
    err = enc.Encode(v)

    //RPC Server
    go func() {
        for {
            conn, err := listener.Accept()
            rpcCodec := codec.GoRpc.ServerCodec(conn, h)
            //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h)

    //RPC Communication (client side)
    conn, err = net.Dial("tcp", "localhost:5555")
    rpcCodec := codec.GoRpc.ClientCodec(conn, h)
    //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h)
    client := rpc.NewClientWithCodec(rpcCodec)

suzukaze/mruby-msgpack MessagePack for mruby

mruby-msgpack Build Status
Welcome to MessagePack for mruby

MessagePack for mruby is MessagePack implimented in mruby language.

msg = [1, 2, 3].to_msgpack  #=> "\x93\x01\x02\x03"
MessagePack.unpack(msg)     #=> [1, 2, 3]

This is early vesion. Please check the methods that work in test foloder.


I test MessagePack for mruby in mac OSX 10.8.4. In the future it will work in Windows and Linux OS.

Getting Started
  1. Download MessagePack for mruby at the command prompt:

    git clone
  2. Add config.gem line to build_config.rb do |conf|

  # ...(snip)...
  conf.gem :git => ''
  1. Test at the command prompt:

    rake test
  2. Build at the command prompt:

msgpack-ruby commit

mruby-msgpack is based on msgpack-ruby(a7c2dc34ef69c9132167e38009baa8420c460c9b)


I encourage you to contribute to MessagePack for mruby!


Author : Jun Hiroe

Copyrigh : Copyright (c) 2013 Jun Hiroe

License : MIT License


Msgpax Build Status

This library provides an API for serializing and de-serializing Elixir terms using the MessagePack format.


Add Msgpax as a dependency in your mix.exs file:

def deps do
  [{:msgpax, "~> 0.5"}]

After you are done, run mix deps.get in your shell to fetch the dependencies.

{:ok, iodata} = Msgpax.pack([300, "Spartans"])
# => {:ok, [<<146>>, [<<205, 1, 44>>, [<<168>>, "Spartans"]]]}
iodata = Msgpax.pack!([300, "Spartans"])
# ...
{:ok, term} = Msgpax.unpack(iodata)
# => {:ok, [300, "Spartans"]}
term = Msgpax.unpack!(iodata)
# => [300, "Spartans"]
Stream-oriented deserialization
{term1, rest} = Msgpax.unpack_slice!(buffer)
# => {[1,2,3], <<4>>}
{:ok, term2, rest} = Msgpax.unpack_slice(rest)
# => {:ok, 4, ""}
Binary format
msgbin = Msgpax.binary(<<3, 18, 122, 27, 115>>)
# => %Msgpax.Binary{data: <<3, 18, 122, 27, 115>>}
iodata = Msgpax.pack!(msgbin)
# => [<<196, 5>>, <<3, 18, 122, 27, 115>>]
# ...
code = Msgpax.unpack!(iodata, %{binary: true})
# => %Msgpax.Binary{data: <<3, 18, 122, 27, 115>>}
Packer protocol deriving
defmodule User do
  @derive [Msgpax.Packer]
  defstruct [:name]

Msgpax.pack!(%User{name: "Lex"})
# => [<<129>>, [[[<<164>>, "name"], [<<163>>, "Lex"]]]]
Data conversion
Elixir MessagePack Elixir
nil nil nil
true boolean true
false boolean false
-1 integer -1
1.25 float 1.25
:ok string "ok"
Atom string "Elixir.Atom"
"str" string "str"
"\xFF\xFF" string "\xFF\xFF"
%Msgpax.Binary{data: "\xFF"} binary "\xFF"
%{foo: "bar"} map %{"foo" => "bar"}
[foo: "bar"] map %{"foo" => "bar"}
[1, true] array [1, true]

This software is licensed under the ISC license.


MessagePack for Rails Build Status

The Rails way to serialize/deserialize objects with Message Pack. It implements the ActiveSupport encoder & decoder and the ActiveModel serializer for Message Pack.


Add this line to your application's Gemfile:

gem 'msgpack_rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install msgpack_rails

msgpack_rails converts data type using as_json before feeding it into msgpack. Here are a few examples:

$ ActiveSupport::MessagePack.encode(:a => :b)
=> "\x81\xA1a\xA1b"

$ ActiveSupport::MessagePack.encode(
=> "\xB92013-09-11T10:40:39-07:00"

=> "2013-09-11T10:48:13-07:00"

=> "\xB92013-09-11T10:40:39-07:00"

$ ActiveSupport::MessagePack.decode
=> "2013-09-11T11:23:07-07:00"

# After setting ActiveSupport.parse_msgpack_times to true
$ ActiveSupport::MessagePack.decode
=> Wed, 11 Sep 2013 11:25:18 -0700

You can also use it as part of ActiveModel, similar to to_json:

class Contact
  include ActiveModel::Serializers::MessagePack


@contact = = 'Owen Ou'
@contact.age = 28
@contact.created_at = Time.utc(2006, 8, 1)
@contact.awesome = true
@contact.preferences = { 'shows' => 'anime' }

@contact.to_msgpack                # => msgpack output
@contact.to_msgpack(:root => true) # => include root in msgpack output
  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


u-msgpack-python v2.0

u-msgpack-python is a lightweight MessagePack serializer and deserializer module written in pure Python, compatible with both Python 2 and 3, as well CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest MessagePack specification.

u-msgpack-python is currently distributed on PyPI: and as a single file:


With pip:

$ pip install u-msgpack-python

With easy_install:

$ easy_install u-msgpack-python

or simply drop into your project!

$ wget

Basic Example:

>>> import umsgpack
>>> umsgpack.packb({u"compact": True, u"schema": 0})
>>> umsgpack.unpackb(_)
{u'compact': True, u'schema': 0}

A more complicated example:

>>> umsgpack.packb(
        [1, True, False, 0xffffffff, {u"foo": b"\x80\x01\x02",
         u"bar": [1,2,3, {u"a": [1,2,3,{}]}]}, -1, 2.12345] )
>>> umsgpack.unpackb(_)
[1, True, False, 4294967295, {u'foo': '\x80\x01\x02',
 u'bar': [1, 2, 3, {u'a': [1, 2, 3, {}]}]}, -1, 2.12345]

Streaming serialization with file-like objects:

>>> f = open('test.bin', 'w')
>>> umsgpack.pack({u"compact": True, u"schema": 0}, f)
>>> umsgpack.pack([1,2,3], f)
>>> f.close()
>>> f = open('test.bin')
>>> umsgpack.unpack(f)
{u'compact': True, u'schema': 0}
>>> umsgpack.unpack(f)
[1, 2, 3]
>>> f.close()

Encoding and decoding an application-defined ext type:

>>> # Create an Ext object with type 0x05 and data b"\x01\x02\x03"
... foo = umsgpack.Ext(0x05, b"\x01\x02\x03")
>>> umsgpack.packb({u"special stuff": foo, u"awesome": True})
b'\x82\xadspecial stuff\xc7\x03\x05\x01\x02\x03\xa7awesome\xc3'
>>> bar = umsgpack.unpackb(_)
>>> print(bar["special stuff"])
Ext Object (Type: 0x05, Data: 01 02 03)
>>> bar["special stuff"].type
>>> bar["special stuff"].data

Python standard library style names dump, dumps, load, loads are also available:

>>> import umsgpack
>>> umsgpack.dumps({u"compact": True, u"schema": 0})
>>> umsgpack.loads(_)
{u'compact': True, u'schema': 0}
>>> f = open('test.bin', 'w')
>>> umsgpack.dump({u"compact": True, u"schema": 0}, f)
>>> f.close()
>>> f = open('test.bin')
>>> umsgpack.load(f)
{u'compact': True, u'schema': 0}
More Information

See the project page for more information on old specification compatibility mode, exceptions, behavior, and testing.


u-msgpack-python is MIT licensed. See the included LICENSE file for more details.



Build Status

Provides basic support for the msgpack format.

julia> import MsgPack

julia> MsgPack.pack("hi")
3-element Array{Uint8,1}:

julia> a = MsgPack.pack([1,2,"hi"])
6-element Array{Uint8,1}:

julia> MsgPack.unpack(MsgPack.pack(4.5))

julia> f = open("")
julia> MsgPack.unpack(f)

julia> f2 = open("", "w")
julia> MsgPack.pack(f2, [1,2,"hi"])

NOTE: The standard method for encoding integers in msgpack is to use the most compact representation possible, and to encode negative integers as signed ints and non-negative numbers as unsigned ints.

For compatibility with other implementations, I'm following this convention. On the unpacking side, every integer type becomes an Int64 in Julia, unless it doesn't fit (ie. values greater than 2^63 are unpacked as Uint64).

I might change this at some point, and/or provide a way to control the unpacked types.

The Extension Type

The MsgPack spec defines the extension type to be a tuple of (typecode, bytearray) where typecode is an application-specific identifier for the data in bytearray. MsgPack.jl provides support for the extension type through the Ext immutable.

It is defined like so

immutable Ext

and used like this

julia> a = [0x34, 0xff, 0x76, 0x22, 0xd3, 0xab]
6-element Array{UInt8,1}:

julia> b = Ext(22, a)

julia> p = pack(b)
9-element Array{UInt8,1}:

julia> c = unpack(p)

julia> c == b

MsgPack reserves typecodes in the range [-128, -1] for future types specified by the MsgPack spec. MsgPack.jl enforces this when creating an Ext but if you are packing an implementation defined extension type (currently there are none) you can pass impltype=true.

julia> Ext(-43, Uint8[1, 5, 3, 9])
ERROR: MsgPack Ext typecode -128 through -1 reserved by implementation
 in call at /Users/sean/.julia/v0.4/MsgPack/src/MsgPack.jl:48 

julia> Ext(-43, Uint8[1, 5, 3, 9], impltype=true)

MsgPack.jl also defines the extserialize and extdeserialize convenience functions. These functions can turn an arbitrary object into an Ext and vice-versa.

julia> type Point{T}

julia> r = Point(2.5, 7.8)

julia> e = MsgPack.extserialize(123, r)

julia> s = MsgPack.extdeserialize(e)

julia> s[2]

julia> r

Since these functions use serialize under the hood they are subject to the following caveat.

In general, this process will not work if the reading and writing are done by different versions of Julia, or an instance of Julia with a different system image.



clojure-msgpack is a lightweight and simple library for converting between native Clojure data structures and MessagePack byte formats. clojure-msgpack only depends on Clojure itself; it has zero third-party dependencies.


Get it from clojars: Clojars Project

  • pack: Serialize object as a sequence of java.lang.Bytes.
  • unpack Deserialize bytes as a Clojure object.
user=> (require '[msgpack.core :refer :all])

user=> (pack {:compact true :schema 0})
(-126 -90 115 99 104 101 109 97 0 -89 99 111 109 112 97 99 116 -61)

user=> (unpack (pack {:compact true :schema 0}))
{"schema" 0, "compact" true}
user=> (use '

user=> (import '( '(

user=> (with-open [o (output-stream "test.dat")]
  (let [data-output (DataOutputStream. o)]
    (pack-stream {:compact true :schema 0} data-output)))

user=> (with-open [i (input-stream "test.dat")]
  (let [data-input (DataInputStream. i)]
    (unpack-stream data-input)))
{"schema" 0, "compact" true}
User-defined extensions:

A macro defext is provided to allow serialization of application-specific types. Currently this only works one-way; data serialized this way will always deserialize as a raw Extended type.

user=> (require '[msgpack.macros :refer [defext]])

user=> (defrecord Employee [name])

user=> (defext Employee 1 #(.getBytes (:name %)))

user=> (let [bob (Employee. "Bob")
             bytes (pack bob)]
         (map #(format "0x%x" %) bytes))
("0xc7" "0x3" "0x1" "0x42" "0x6f" "0x62")
  • Symbols and Keywords are treated as MessagePack strings.
  • Sets are treated as MessagePack arrays.
  • Error checking
  • Compatibility mode
  • Benchmarks

clojure-msgpack is MIT licensed. See the included LICENSE file for more details.



MessagePack implementation for Standard ML (SML)

  • Portable: Depends only on the required components of the SML Basis Library specification.
  • Composable: Composable combinators for encoding and decoding.
MLton and MLKit

Include in your MLB file.


From the interactive shell, use .sml files in the following order.

  • mlmsgpack-aux.sml
  • realprinter-default.sml
  • mlmsgpack.sml


Moscow ML

From the interactive shell, use .sml files in the following order.

  • large.sml
  • mlmsgpack-aux.sml
  • realprinter-fail.sml
  • mlmsgpack.sml

Makefile.mosml is also provided.


From the interactive shell, use .sml files in the following order.

  • mlmsgpack-aux.sml
  • realprinter-fail.sml
  • mlmsgpack.sml
Alice ML

From the interactive shell, use .sml files in the following order.

  • mlmsgpack-aux.sml
  • realprinter-fail.sml
  • mlmsgpack.sml

For separate compilation, .smi files are provided. Require mlmsgpack.smi from your .smi file.

From the interactive shell, use .sml files in the following order.

  • mlmsgpack-aux.sml
  • realprinter-default.sml
  • mlmsgpack.sml


Known Problems

Our recommendation is MLton, MLKit, Poly/ML and SML#(>=2.0.0) as all tests passed on them. SML/NJ and Moscow ML are fine if you don't use real values.


Packing real values fail or produces imprecise results in some cases.

Moscow ML

Packing real values is not supported, since some components of the SML Basis Library are not provided.


Packing real values is not supported, since some components of the SML Basis Library are not provided. Some functions are very slow, although they work properly. (We tested HaMLet compiled with MLton.)

Alice ML

Packing real values is not supported, since some components of the SML Basis Library are not provided. Also, some unit tests fail.


Most functions do not work properly because of bugs of SML# prior to version 2.0.0.


Ext is not supported yet.

See Also

There already exists another MessagePack implemenatation for SML, called MsgPack-SML, which is targeted for MLton.

ML-MessagePack is written from scratch and not a fork of MsgPack-SML.

For information on MessagePack, see:



CMP is a C implementation of the MessagePack serialization format. It currently implements version 5 of the MessagePack Spec.

CMP's goal is to be lightweight and straightforward, forcing nothing on the programmer.


While I'm a big believer in the GPL, I license CMP under the MIT license.

Example Usage

The following examples use a file as the backend, and are modeled after the examples included with the msgpack-c project.

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "cmp.h"

static bool read_bytes(void *data, size_t sz, FILE *fh) {
    return fread(data, sizeof(uint8_t), sz, fh) == (sz * sizeof(uint8_t));

static bool file_reader(cmp_ctx_t *ctx, void *data, size_t limit) {
    return read_bytes(data, limit, (FILE *)ctx->buf);

static size_t file_writer(cmp_ctx_t *ctx, const void *data, size_t count) {
    return fwrite(data, sizeof(uint8_t), count, (FILE *)ctx->buf);

void error_and_exit(const char *msg) {
    fprintf(stderr, "%s\n\n", msg);

int main(void) {
    FILE *fh = NULL;
    cmp_ctx_t cmp;
    uint32_t array_size = 0;
    uint32_t str_size = 0;
    char hello[6] = {0, 0, 0, 0, 0, 0};
    char message_pack[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    fh = fopen("cmp_data.dat", "w+b");

    if (fh == NULL)
        error_and_exit("Error opening data.dat");

    cmp_init(&cmp, fh, file_reader, file_writer);

    if (!cmp_write_array(&cmp, 2))

    if (!cmp_write_str(&cmp, "Hello", 5))

    if (!cmp_write_str(&cmp, "MessagePack", 11))


    if (!cmp_read_array(&cmp, &array_size))

    /* You can read the str byte size and then read str bytes... */

    if (!cmp_read_str_size(&cmp, &str_size))

    if (str_size > (sizeof(hello) - 1))
        error_and_exit("Packed 'hello' length too long\n");

    if (!read_bytes(hello, str_size, fh))

     * ...or you can set the maximum number of bytes to read and do it all in
     * one call

    str_size = sizeof(message_pack);
    if (!cmp_read_str(&cmp, message_pack, &str_size))

    printf("Array Length: %zu.\n", array_size);
    printf("[\"%s\", \"%s\"]\n", hello, message_pack);


    return EXIT_SUCCESS;
Advanced Usage

See the examples folder.

Fast, Lightweight, Flexible, and Robust

CMP uses no internal buffers; conversions, encoding and decoding are done on the fly.

CMP's source and header file together are ~3,100 LOC.

CMP makes no heap allocations.

CMP uses standardized types rather than declaring its own, and it depends only on stdbool.h, stdint.h and string.h. It has no link-time dependencies, not even the C Standard Library.

CMP is written using C89 (ANSI C), aside, of course, from its use of fixed-width integer types and bool.

On the other hand, CMP's test suite depends upon the C Standard Library and requires C99.

CMP only requires the programmer supply a read function and a write function. In this way, the programmer can use CMP on memory, files, sockets, etc.

CMP is portable. It uses fixed-width integer types, and checks the endianness of the machine at runtime before swapping bytes (MessagePack is big-endian).

CMP provides a fairly comprehensive error reporting mechanism modeled after errno and strerror.

CMP is threadsafe; while contexts cannot be shared between threads, each thread may use its own context freely.

CMP is tested using the MessagePack test suite as well as a large set of custom test cases. Its small test program is compiled with clang using -Wall -Werror -Wextra ... along with several other flags, and generates no compilation errors.

CMP's source is written as readably as possible, using explicit, descriptive variable names and a consistent, clear style.

CMP's source is written to be as secure as possible. Its testing suite checks for invalid values, and data is always treated as suspect before it passes validation.

CMP's API is designed to be clear, convenient and unsurprising. Strings are null-terminated, binary data is not, error codes are clear, and so on.


There is no build system for CMP. The programmer can drop cmp.c and cmp.h in their source tree and modify as necessary. No special compiler settings are required to build it, and it generates no compilation errors in either clang or gcc.



This is a very early release of my MessagePack library for Dart. Currently, message classes must be written by hand. For example:

class NotificationFrame extends Message {
    String kind;
    Map<String, Object> data;


    static NotificationFrame fromList(List f) => new NotificationFrame(f[0], f[1]);
    List toList() => [kind, data];

For each class you need to define the fromList and toList methods, which convert from and to a list of fields respectively.

For example usage, see the unit tests.



Build Status: Build Status

Msgpack for HHVM, It is a msgpack binding for HHVM

  • msgpack_pack(mixed $input) : string; pack a input to msgpack, object and resource are not supported, array and other types supported, false on failure.
  • msgpack_unpack(string $pac) : mixed; unpack a msgpack.
$ git clone
$ cd msgpack-hhvm
$ hphpize && cmake . && make
$ cp /path/to/your/hhvm/ext/dir

If you don't have hphpize program, please intall package hhvm-dev

$ sudo apt-get install hhvm-dev
Contribution and Issues

Feel free to send Pull Requests for bug report at:



MessagePack for F#
Build status
What is this?

MessagePack is a fast and compact binary serialization library.

MessagePack for F# is a MessagePack implementation of F#, by F#, for F#.

open MsgPack

[| 1uy; 2uy; 3uy |]
|> (Value.UInt8)
|> Value.Array
|> Packer.packOne
//=> val it : byte [] = [|147uy; 1uy; 2uy; 3uy|]

Unpacker.unpack [|147uy; 1uy; 2uy; 3uy|]
//=> [|Value.Array [|Value.UInt8 1uy; Value.UInt8 2uy; Value.UInt8 3uy|]|]

Copyright (c) 2014- Kazuhiro Matsushima


Distributed under the Apache License, Version 2.0 .



Build Status

This Jackson extension library handles reading and writing of data encoded in MessagePack data format. It extends standard Jackson streaming API (JsonFactory, JsonParser, JsonGenerator), and as such works seamlessly with all the higher level data abstractions (data binding, tree model, and pluggable extensions).

Maven dependency

To use this module on Maven-based projects, use following dependency:


Only thing you need to do is to instantiate MessagePackFactory and pass it to the constructor of ObjectMapper.

  ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
  ExamplePojo orig = new ExamplePojo("komamitsu");
  byte[] bytes = objectMapper.writeValueAsBytes(orig);
  ExamplePojo value = objectMapper.readValue(bytes, ExamplePojo.class);
  System.out.println(value.getName()); // => komamitsu

Also, you can exchange data among multiple languages.


  // Serialize
  Map<String, Object> obj = new HashMap<String, Object>();
  obj.put("foo", "hello");
  obj.put("bar", "world");
  byte[] bs = objectMapper.writeValueAsBytes(obj);
  // bs => [-126, -93, 102, 111, 111, -91, 104, 101, 108, 108, 111,
  //        -93, 98, 97, 114, -91, 119, 111, 114, 108, 100]


  require 'msgpack'

  # Deserialize
  xs = [-126, -93, 102, 111, 111, -91, 104, 101, 108, 108, 111,
        -93, 98, 97, 114, -91, 119, 111, 114, 108, 100]
  # => {"foo"=>"hello", "bar"=>"world"}

  # Serialize
  ["zero", 1, 2.0, nil].to_msgpack.unpack('C*')
  # => [148, 164, 122, 101, 114, 111, 1, 203, 64, 0, 0, 0, 0, 0, 0, 0, 192]


  // Deserialize
  bs = new byte[] {(byte) 148, (byte) 164, 122, 101, 114, 111, 1,
                   (byte) 203, 64, 0, 0, 0, 0, 0, 0, 0, (byte) 192};
  TypeReference<List<Object>> typeReference = new TypeReference<List<Object>>(){};
  List<Object> xs = objectMapper.readValue(bs, typeReference);
  // xs => [zero, 1, 2.0, null]


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

 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}')
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



SwiftPack is MessagePack packer and unpacker written almost entirely in Swift.

  • There are few Objective-C dependencies, mostly NSData. I hope to remove these dependencies as Swift matures.
  • Maps currently only support String types for keys.
Copyright and License

Copyright (c) 2014 Brian Williams

This software is licensed under the terms of the MIT license.


pod "MPMessagePack"
#import <MPMessagePack/MPMessagePack.h>

NSDictionary *dict =
@"n": @(32134123),
@"bool": @(YES),
@"array": @[@(1.1f), @(2.1)],
@"body": [NSData data],

NSData *data = [dict mp_messagePack];

Or via MPMessagePackWriter.

NSError *error = nil;
NSData *data = [MPMessagePackWriter writeObject:dict error:&error];

If you need to use an ordered dictionary.

MPOrderedDictionary *dict = [[MPOrderedDictionary alloc] init];
[dict addEntriesFromDictionary:@{@"c": @(1), @"b": @(2), @"a": @(3)}];
[dict sortKeysUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
[dict mp_messagePack];
id obj = [MPMessagePackReader readData:data error:&error];
MPMessagePackReader *reader = [[MPMessagePackReader alloc] initWithData:data];
id obj1 = [reader read:&error]; // Read an object
id obj2 = [reader read:&error]; // Read another object


msgpack5  Build Status

A msgpack v5 implementation for node.js and the browser, with extension point support.

npm install msgpack5 --save
var msgpack = require('msgpack5')() // namespace our extensions
  , a       = new MyType(2, 'a')
  , encode  = msgpack.encode
  , decode  = msgpack.decode

msgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)

console.log(encode({ 'hello': 'world' }).toString('hex'))
// 81a568656c6c6fa5776f726c64
console.log(decode(encode({ 'hello': 'world' })))
// { hello: 'world' }
// d5426161
console.log(decode(encode(a)) instanceof MyType)
// true
// { value: 'a', size: 2 }

function MyType(size, value) {
  this.value = value
  this.size  = size

function mytipeEncode(obj) {
  var buf = new Buffer(obj.size)
  return buf

function mytipeDecode(data) {
  var result = new MyType(data.length, data.toString('utf8', 0, 1))
    , i

  for (i = 0; i < data.length; i++) {
    if (data.readUInt8(0) != data.readUInt8(i)) {
      throw new Error('should all be the same')

  return result
In the Browser

This library is compatible with Browserify.

If you want to use standalone, grab the file in the dist folder of this repo, and use in your own HTML page, the module will expose a msgpack5 global.

<script type="text/javascript"
To build
    npm run build



Creates a new instance on which you can register new types for being encoded.


Encodes object in msgpack, returns a bl.


Decodes buf from in msgpack. buf can be a Buffer or a bl instance.

In order to support a stream interface, a user must pass in a bl instance.

registerEncoder(check(obj), encode(obj))

Register a new custom object type for being automatically encoded. The arguments are:

  • check, a function that will be called to check if the passed object should be encoded with the encode function
  • encode, a function that will be called to encode an object in binary form; this function must return a Buffer which include the same type for registerDecoder.

registerDecoder(type, decode(buf))

Register a new custom objet type for being automatically decoded. The arguments are:

  • type, is a greater than zero integer identificating the type once serialized
  • decode, a function that will be called to decode the object from the passed Buffer

register(type, constructor, encode(obj), decode(buf))

Register a new custom objet type for being automatically encoded and decoded. The arguments are:

  • type, is a greater than zero integer identificating the type once serialized
  • constructor, the function that will be used to match the objects with instanceof
  • encode, a function that will be called to encode an object in binary form; this function must return a Buffer that can be deserialized by the decode function
  • decode, a function that will be called to decode the object from the passed Buffer

This is just a commodity that calls registerEncoder and registerDecoder internally.


Builds a stream in object mode that encodes msgpack.


Builds a stream in object mode that decodes msgpack.

LevelUp Support

msgpack5 can be used as a LevelUp valueEncoding straight away:

var level = require('level')
  , pack  = msgpack()
  , db    = level('foo', {
      valueEncoding: pack
  , obj   = { my: 'obj' }

db.put('hello', obj, function(err) {
  db.get('hello', function(err, result) {

This library is built fully on JS and on bl to simplify the code. Every improvement that keeps the same API is welcome.


This project was kindly sponsored by nearForm.

This library was originally built as the data format for JSChan.




MessagePack for Haskell

This implementation defines an messagepack Object type, which is an instance of Serialize (from cereal ):

data Object = ObjectNil
            | ObjectInt    Int64
            | ObjectBool   Bool
            | ObjectFloat  Float
            | ObjectDouble Double
            | ObjectString Text
            | ObjectBinary ByteString
            | ObjectArray  [Object]
            | ObjectMap    (M.Map Object Object )
            | ObjectExt    !Int8 BS.ByteString
    deriving (Eq, Ord, Show)

instance Serialize Object where
    -- ...

Thus, you can use cereal's encode and decode to pack and unpack objects.


Msgpack for Delphi

It's like JSON but small and fast.

unit Owner: D10.Mofen, qdac.swish
welcome to report bug
Works with
  • Delphi 7 (tested)
  • Delphi 2007 (tested)
  • XE5, XE6, XE7, FMX (tested)
  • fixed int32, int64 parse bug< integer, int64 parse zero> 2014-11-09 22:35:27

  • add EncodeToFile/DecodeFromFile 2014-11-13 12:30:58

  • fix asVariant = null (thanks for cyw(26890954)) 2014-11-14 09:05:52

  • fix AsInteger = -1 bug (thanks for cyw(26890954)) 2014-11-14 12:15:52

  • fix AsInteger = -127 bug check int64/integer/cardinal/word/shortint/smallint/byte assign, encode,decode, read 2014-11-14 12:30:38

Code Example
  lvMsg, lvMsg2:TSimpleMsgPack;
  lvMsg := TSimpleMsgPack.Create;
  lvMsg.S['key.obj'] := '汉字,ascii';
  if dlgOpen.Execute then
    lvMsg.S[''] := ExtractFileName(dlgOpen.FileName);

    // file binary data

  lvBytes := lvMsg.EncodeToBytes;

  lvMsg2 := TSimpleMsgPack.Create;
  if lvMsg2.S[''] <> '' then
    s := ExtractFilePath(ParamStr(0)) + lvMsg2.S[''];
    Memo1.Lines.Add('file saved');


QMsgPack-Messagepack for Delphi/C++ Builder

QMsgPack is a simple and powerful Delphi & C++ Builder implementation for messagepack protocol. QMsgPack is a part of QDAC 3.0,Source code hosted in Sourceforge(


· Full types support,include messagepack extension type

· Full open source,free for used in ANY PURPOSE

· Quick and simple interface

· RTTI support include


QMsgPack is not a desgin time package.So just place QMsgPack files into search path and add to your project.


· Topic in Website ( ,CHINESE only

· Mail to author (

· Post in forum (

· QQ Group No:250530692 (

Source check out

· HTTP (

· SVN (svn://

  lvMsg, lvMsg2:TQMsgPack;
  lvMsg := TQMsgPack.Create;
  lvMsg.ForcePath('key.obj').AsString := '汉字,ascii';

  lvBytes := lvMsg.Encode;

  lvMsg2 := TQMsgPack.Create;


MessagePack Code Generator Build Status

forthebadge forthebadge

This is a code generation tool and serialization library for MesssagePack. It is targeted at the go generate tool. You can read more about MessagePack in the wiki, or at

Why? Quickstart

Note: you need at least go 1.3 to compile this package, and at least go 1.4 to use go generate.

In a source file, include the following directive:

//go:generate msgp

The msgp command will generate serialization methods for all exported type declarations in the file.

You can read more about the code generation options here.


Field names can be set in much the same way as the encoding/json package. For example:

type Person struct {
    Name       string `msg:"name"`
    Address    string `msg:"address"`
    Age        int    `msg:"age"`
    Hidden     string `msg:"-"` // this field is ignored
    unexported bool             // this field is also ignored

By default, the code generator will satisfy msgp.Sizer, msgp.Encodable, msgp.Decodable, msgp.Marshaler, and msgp.Unmarshaler. Carefully-designed applications can use these methods to do marshalling/unmarshalling with zero allocations.

While msgp.Marshaler and msgp.Unmarshaler are quite similar to the standard library's json.Marshaler and json.Unmarshaler, msgp.Encodable and msgp.Decodable are useful for stream serialization. (*msgp.Writer and *msgp.Reader are essentially protocol-aware versions of *bufio.Writer and *bufio.Reader, respectively.)

  • Extremely fast generated code
  • Test and benchmark generation
  • JSON interoperability (see msgp.CopyToJSON() and msgp.UnmarshalAsJSON())
  • Support for complex type declarations
  • Native support for Go's time.Time, complex64, and complex128 types
  • Generation of both []byte-oriented and io.Reader/io.Writer-oriented methods
  • Support for arbitrary type system extensions
  • Preprocessor directives

Consider the following:

const Eight = 8
type MyInt int
type Data []byte

type Struct struct {
    Which  map[string]*MyInt `msg:"which"`
    Other  Data              `msg:"other"`
    Nums   [Eight]float64    `msg:"nums"`

As long as the declarations of MyInt and Data are in the same file as Struct, the parser will determine that the type information for MyInt and Data can be passed into the definition of Struct before its methods are generated.


MessagePack supports defining your own types through "extensions," which are just a tuple of the data "type" (int8) and the raw binary. You can see a worked example in the wiki.


Alpha. I will break stuff. There is an open milestone for Beta stability (targeted for January.) Only the /msgp sub-directory will have a stability guarantee.

You can read more about how msgp maps MessagePack types onto Go types in the wiki.

Here some of the known limitations/restrictions:

  • Identifiers from outside the processed source file are assumed (optimistically) to satisfy the generator's interfaces. If this isn't the case, your code will fail to compile.
  • Like most serializers, chan and func fields are ignored, as well as non-exported fields.
  • Encoding of interface{} is limited to built-ins or types that have explicit encoding methods.
  • Maps must have string keys. This is intentional (as it preserves JSON interop.) Although non-string map keys are not forbidden by the MessagePack standard, many serializers impose this restriction. (It also means any well-formed struct can be de-serialized into a map[string]interface{}.) The only exception to this rule is that the deserializers will allow you to read map keys encoded as bin types, due to the fact that some legacy encodings permitted this. (However, those values will still be cast to Go strings, and they will be converted to str types when re-encoded. It is the responsibility of the user to ensure that map keys are UTF-8 safe in this case.) The same rules hold true for JSON translation.

If the output compiles, then there's a pretty good chance things are fine. (Plus, we generate tests for you.) Please, please, please file an issue if you think the generator is writing broken code.


If you like benchmarks, see here.

As one might expect, the generated methods that deal with []byte are faster, but the io.Reader/Writer methods are generally more memory-efficient for large (> 2KB) objects.



msgpack-cli is command line tool that converts data from JSON to Msgpack and vice versa. Also allows calling RPC methods via msgpack-rpc.

% go get

Debian packages and Windows binaries are available on project's Releases page.


    msgpack-cli encode <input-file> [--out=<output-file>] [--disable-int64-conv]
    msgpack-cli decode <input-file> [--out=<output-file>] [--pp]
    msgpack-cli rpc <host> <port> <method> [<params>|--file=<input-file>] [--pp]
    msgpack-cli -h | --help
    msgpack-cli --version

    encode                Encode data from input file to STDOUT
    decode                Decode data from input file to STDOUT
    rpc                   Call RPC method and write result to STDOUT

    -h --help             Show this help message and exit
    --version             Show version
    --out=<output-file>   Write output data to file instead of STDOUT
    --file=<input-file>   File where parameters or RPC method are read from
    --pp                  Pretty-print - indent output JSON data
    --timeout=<timeout>   Timeout of RPC call [default: 30]
    --disable-int64-conv  Disable the default behaviour such that JSON numbers
                          are converted to float64 or int64 numbers by their
                          meaning, all result numbers will have float64 type

    <input-file>          File where data are read from
    <host>                Server hostname
    <port>                Server port
    <method>              Name of RPC method
    <params>              Parameters of RPC method in JSON format


$ cat test.json
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "height_cm": 167.6,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  "phoneNumbers": [
      "type": "home",
      "number": "212 555-1234"
      "type": "office",
      "number": "646 555-4567"
  "children": [],
  "spouse": null
$ msgpack-cli encode test.json --out test.bin
$ ls -l test.* | awk '{print $9, $5}'
test.bin 242
test.json 429
$ msgpack-cli decode test.bin --pp  # pretty-print
  "address": {
    "city": "New York",
    "postalCode": "10021-3100",
    "state": "NY",
    "streetAddress": "21 2nd Street"
  "age": 25,
  "children": [],
  "firstName": "John",
  "height_cm": 167.6,
  "isAlive": true,
  "lastName": "Smith",
  "phoneNumbers": [
      "number": "212 555-1234",
      "type": "home"
      "number": "646 555-4567",
      "type": "office"
  "spouse": null

RPC calling:

$ # zero params
$ msgpack-cli rpc localhost 8000 echo
$ # single param
$ msgpack-cli rpc localhost 8000 echo 3.14159
$ # multiple params (as json array)
$ msgpack-cli rpc localhost 8000 echo '["abc", "def", "ghi", {"A": 65, "B": 66, "C": 67}]'



MessagePack implementation for C# /[C#]

Binary files distributed via the NuGet package SimpleMsgPack.

It's like JSON but small and fast.

unit Owner: D10.Mofen
if you find any bug, please contact me!
Works with

.NET Framework 4.x

Code Example
    MsgPack msgpack = new MsgPack();
    msgpack.ForcePathObject("").AsString = "张三";
    msgpack.ForcePathObject("p.age").AsInteger = 25;

    // pack file

    // pack msgPack binary
    byte[] packData = msgpack.Encode2Bytes();

    MsgPack unpack_msgpack = new MsgPack();

    // unpack msgpack

    System.Console.WriteLine("name:{0}, age:{1}",

    System.Console.WriteLine("use index property, Length{0}:{1}",

    Console.WriteLine("use foreach statement:");
    foreach (MsgPack item in unpack_msgpack.ForcePathObject("p.datas"))

    // unpack filedata 




For the latest source code, see

txmsgpackrpc is a library for writing asynchronous msgpack-rpc servers and clients in Python, using Twisted framework. Library is based on txMsgpack, but some improvements and fixes were made.

  • user friendly API
  • modular object model
  • working timeouts and reconnecting
  • connection pool support
  • TCP, SSL, UDP and UNIX sockets
Python 3 note

Twisted (actually 15.0) doesn't support twisted.internet.unix module for Python 3, therefore UNIX sockets are not supported.

% pip install txmsgpackrpc

Debian packages are available on project's Releases page.

TCP example

Computation of PI using Chudnovsky algorithm in subprocess. For details, see

Computation of PI with 5 places finished in 0.022390 seconds

Computation of PI with 100 places finished in 0.037856 seconds

Computation of PI with 1000 places finished in 0.038070 seconds

Computation of PI with 10000 places finished in 0.073907 seconds

Computation of PI with 100000 places finished in 6.741683 seconds

Computation of PI with 5 places finished in 0.001142 seconds

Computation of PI with 100 places finished in 0.001182 seconds

Computation of PI with 1000 places finished in 0.001206 seconds

Computation of PI with 10000 places finished in 0.001230 seconds

Computation of PI with 100000 places finished in 0.001255 seconds

Computation of PI with 1000000 places finished in 432.574457 seconds

Computation of PI with 1000000 places finished in 402.551226 seconds

from __future__ import print_function

from collections import defaultdict
from twisted.internet import defer, reactor, utils
from twisted.python import failure
from txmsgpackrpc.server import MsgpackRPCServer

pi_chudovsky_bs = '''
Python3 program to calculate Pi using python long integers, binary
splitting and the Chudnovsky algorithm

See: for more

Nick Craig-Wood <>

import math
from time import time

def sqrt(n, one):
    Return the square root of n as a fixed point number with the one
    passed in.  It uses a second order Newton-Raphson convgence.  This
    doubles the number of significant figures on each iteration.
    # Use floating point arithmetic to make an initial guess
    floating_point_precision = 10**16
    n_float = float((n * floating_point_precision) // one) / floating_point_precision
    x = (int(floating_point_precision * math.sqrt(n_float)) * one) // floating_point_precision
    n_one = n * one
    while 1:
        x_old = x
        x = (x + n_one // x) // 2
        if x == x_old:
    return x

def pi_chudnovsky_bs(digits):
    Compute int(pi * 10**digits)

    This is done using Chudnovsky's series with binary splitting
    C = 640320
    C3_OVER_24 = C**3 // 24
    def bs(a, b):
        Computes the terms for binary splitting the Chudnovsky infinite series

        a(a) = +/- (13591409 + 545140134*a)
        p(a) = (6*a-5)*(2*a-1)*(6*a-1)
        b(a) = 1
        q(a) = a*a*a*C3_OVER_24

        returns P(a,b), Q(a,b) and T(a,b)
        if b - a == 1:
            # Directly compute P(a,a+1), Q(a,a+1) and T(a,a+1)
            if a == 0:
                Pab = Qab = 1
                Pab = (6*a-5)*(2*a-1)*(6*a-1)
                Qab = a*a*a*C3_OVER_24
            Tab = Pab * (13591409 + 545140134*a) # a(a) * p(a)
            if a & 1:
                Tab = -Tab
            # Recursively compute P(a,b), Q(a,b) and T(a,b)
            # m is the midpoint of a and b
            m = (a + b) // 2
            # Recursively calculate P(a,m), Q(a,m) and T(a,m)
            Pam, Qam, Tam = bs(a, m)
            # Recursively calculate P(m,b), Q(m,b) and T(m,b)
            Pmb, Qmb, Tmb = bs(m, b)
            # Now combine
            Pab = Pam * Pmb
            Qab = Qam * Qmb
            Tab = Qmb * Tam + Pam * Tmb
        return Pab, Qab, Tab
    # how many terms to compute
    DIGITS_PER_TERM = math.log10(C3_OVER_24/6/2/6)
    N = int(digits/DIGITS_PER_TERM + 1)
    # Calclate P(0,N) and Q(0,N)
    P, Q, T = bs(0, N)
    one = 10**digits
    sqrtC = sqrt(10005*one, one)
    return (Q*426880*sqrtC) // T

if __name__ == "__main__":
    import sys
    digits = int(sys.argv[1])
    pi = pi_chudnovsky_bs(digits)

def set_timeout(deferred, timeout=30):
    def callback(value):
        if not watchdog.called:
        return value


    watchdog = reactor.callLater(timeout, defer.timeout, deferred)

class ComputePI(MsgpackRPCServer):

    def __init__(self):
        self.waiting = defaultdict(list)
        self.results = {}

    def remote_PI(self, digits, timeout=None):
        if digits in self.results:
            return defer.succeed(self.results[digits])

        d = defer.Deferred()

        if digits not in self.waiting:
            subprocessDeferred = self.computePI(digits, timeout)

            def callWaiting(res):
                waiting = self.waiting[digits]
                del self.waiting[digits]

                if isinstance(res, failure.Failure):
                    func = lambda d: d.errback(res)
                    func = lambda d: d.callback(res)

                for d in waiting:



        return d

    def computePI(self, digits, timeout):
        d = utils.getProcessOutputAndValue('/usr/bin/python', args=('-c', pi_chudovsky_bs, str(digits)))

        def callback((out, err, code)):
            if code == 0:
                pi = int(out)
                self.results[digits] = pi
                return pi
                return failure.Failure(RuntimeError('Computation failed: ' + err))

        if timeout is not None:
            set_timeout(d, timeout)


        return d

def main():
    server = ComputePI()
    reactor.listenTCP(8000, server.getStreamFactory())

if __name__ == '__main__':
from __future__ import print_function

import sys
import time
from twisted.internet import defer, reactor, task
from twisted.python import failure

def main():

        from txmsgpackrpc.client import connect

        c = yield connect('localhost', 8000, waitTimeout=900)

        def callback(res, digits, start_time):
            if isinstance(res, failure.Failure):
                print('Computation of PI with %d places failed: %s' %
                      (digits, res.getErrorMessage()), end='\n\n')
                print('Computation of PI with %d places finished in %f seconds' %
                      (digits, time.time() - start_time), end='\n\n')

        defers = []
        for _ in range(2):
            for digits in (5, 100, 1000, 10000, 100000, 1000000):
                d = c.createRequest('PI', digits, 600)
                d.addBoth(callback, digits, time.time())
            # wait for 30 seconds
            yield task.deferLater(reactor, 30, lambda: None)

        yield defer.DeferredList(defers)


    except Exception:
        import traceback

if __name__ == '__main__':
Multicast UDP example

Example servers join to group and listen on port 8000. Their only method echo returns its parameter.

Client joins group to, sends multicast request to group on port 8000 and waits for 5 seconds for responses. If some responses are received, protocol callbacks with tuple of results and individual parts are checked for errors. If no responses are received, protocol errbacks with TimeoutError.

Because there is no common way to determine number of peers in group, MsgpackMulticastDatagramProtocol always wait for responses until waitTimeout expires.

$ # setup multicast routing
$ ip route add dev eth0
$ echo 1 > /proc/sys/net/ipv4/ip_forward
$ # start servers listening on port 8000
$ python examples/ &
[1] 3584
$ python examples/ &
[2] 3585
$ python examples/ &
[3] 3586
$ python examples/ &
[4] 3587
$ python examples/ &
[5] 3588
$ # execute client
$ python examples/
Received results from 5 peers
from twisted.internet import defer, reactor, task
from txmsgpackrpc.server import MsgpackRPCServer

class EchoRPC(MsgpackRPCServer):

    def remote_echo(self, value, delay=None, msgid=None):
        if delay is not None:
            yield task.deferLater(reactor, delay, lambda: None)

def main():
    server = EchoRPC()
    reactor.listenMulticast(8000, server.getMulticastProtocol('', ttl=5),

if __name__ == '__main__':
from __future__ import print_function

from twisted.internet import defer, reactor

def main():

        from txmsgpackrpc.client import connect_multicast

        c = yield connect_multicast('', 8000, ttl=5, waitTimeout=5)

        data = {
                    'firstName': 'John',
                    'lastName': 'Smith',
                    'isAlive': True,
                    'age': 25,
                    'height_cm': 167.6,
                    'address': {
                      'streetAddress': "21 2nd Street",
                      "city": 'New York',
                      "state": 'NY',
                      'postalCode': '10021-3100'
                    'phoneNumbers': [
                        'type': 'home',
                        'number': '212 555-1234'
                        'type': 'office',
                        'number': '646 555-4567'
                    'children': [],
                    'spouse': None

        results = yield c.createRequest('echo', data)

        assert isinstance(results, tuple)

        print('Received results from %d peers' % len(results))

        for i, result in enumerate(results):
            if result != data:
                print('Result %d mismatch' % i)

    except Exception:
        import traceback

if __name__ == '__main__':



MessagePack.swift is released under the MIT license, which is reproduced below in its entirety:

Copyright (c) 2015 Alexsander Akers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.



MessagePack.swift is intended for Swift 1.2. For compatibility with Swift 1.1, see the swift-1.1 branch. Compatibility with future versions is not guaranteed.



A MessagePack binding for Nim

Build Status


msgpack-nim currently provides only the basic functionality. Please see what's listed in Todo section. Compared to other language bindings, it's well-tested by 1000 auto-generated test cases by Haskell QuickCheck, which always runs on every commit to Github repository. Please try make quickcheck on your local machine to see what happens (It will take a bit while. Be patient). Have a nice packing!


$ nimble update
$ nimble install msgpack
import msgpack
import streams

# You can use any stream subclasses to serialize/deserialize
# messages. e.g. FileStream
let st: Stream = newStringStream()

assert(st.getPosition == 0)

# Type checking protects you from making trivial mistakes.
# Now we pack {"a":[5,-3], "b":[1,2,3]} but more complex
# combination of any Msg types is allowed.
# In xs we can mix specific conversion (PFixNum) and generic
# conversion (unwrap).
let xs: Msg = wrap(@[PFixNum(5), (-3).wrap])
let ys: Msg = wrap(@[("a".wrap, xs.wrap), ("b".wrap, @[1, 2, 3].wrap)])
st.pack(ys.wrap) # Serialize!

# We need to reset the cursor to the beginning of the target
# byte sequence.

let msg = st.unpack # Deserialize!

# output:
# a
# 5
# -3
# b
# 1
# 2
# 3
for e in msg.unwrapMap:
  echo e.key.unwrapStr
  for e in e.val.unwrapArray:
    echo e.unwrapInt
  • Implement unwrapInto to convert Msg object to Nim object handily
  • Evaluate performance and scalability
  • Talk with offical Ruby implementation
  • Don't repeat yourself: The code now has too much duplications. Using templates?

Akira Hayakawa (



MPack is a C implementation of an encoder and decoder for the MessagePack serialization format. It is intended to be:

  • Simple and easy to use
  • Secure against untrusted data
  • Lightweight, suitable for embedded
  • Helpful for debugging
  • Extensively documented

The core of MPack contains a buffered reader and writer with a custom callback to fill or flush the buffer. Helper functions can be enabled to read values of expected type, to work with files, to allocate strings automatically, to check UTF-8 encoding, and more. The MPack featureset can be configured at compile-time to set which features, components and debug checks are compiled, and what dependencies are available.

The MPack code is small enough to be embedded directly into your codebase. The easiest way to use it is to download the amalgamation package and insert the source files directly into your project. Copy mpack.h and mpack.c into to your codebase, and copy mpack-config.h.sample as mpack-config.h. You can use the defaults or edit it if you'd like to customize the MPack featureset.

MPack is written in the portable intersection of C99 and C++. In other words, it's written in C99, but if you are stuck using a certain popular compiler from a certain unpopular vendor that refuses to support C99, you can compile it as C++ instead. (The headers should also be C89-clean, provided compatible definitions of bool, inline, stdint.h and friends are available, and const is defined away.)

NOTE: MPack is beta software under development. There are still some TODOs in the codebase, some security issues to fix, some MessagePack 1.0/1.1 compatibility and interoperability issues to sort out, some test suite portability issues to fix, and there is only around 45% unit test coverage.

The Node Reader API

The Node API parses a chunk of MessagePack data into an immutable tree of dynamically-typed nodes. A series of helper functions can be used to extract data of specific types from each node.

// parse a file into a node tree
mpack_tree_t tree;
mpack_tree_init_file(&tree, "", 0);
mpack_node_t* root = mpack_tree_root(&tree);

// extract the example data on the msgpack homepage
bool compact = mpack_node_bool(mpack_node_map_cstr(root, "compact"));
int schema = mpack_node_i32(mpack_node_map_cstr(root, "schema"));

// clean up and check for errors
if (mpack_tree_destroy(tree) != mpack_ok) {
    fprintf(stderr, "An error occurred decoding the data!\n");

Note that no additional error handling is needed in the above code. If the file is missing or corrupt, if map keys are missing or if nodes are not in the expected types, special "nil" nodes and false/zero values are returned and the tree is placed in an error state. An error check is only needed before using the data. Alternatively, the tree can be configured to longjmp in such cases if a handler is set.

The Static Write API

The MPack Write API encodes structured data of a fixed (hardcoded) schema to MessagePack.

// encode to memory buffer
char buffer[256];
mpack_writer_t writer;
mpack_writer_init(&writer, buffer, sizeof(buffer));

// write the example on the msgpack homepage
mpack_start_map(&writer, 2);
mpack_write_cstr(&writer, "compact");
mpack_write_bool(&writer, true);
mpack_write_cstr(&writer, "schema");
mpack_write_uint(&writer, 0);

// clean up
size_t count = mpack_writer_buffer_used(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
    fprintf(stderr, "An error occurred encoding the data!\n");

In the above example, we encode only to an in-memory buffer. The writer can optionally be provided with a flush function (such as a file or socket write function) to call when the buffer is full or when writing is done.

If any error occurs, the writer is placed in an error state and can optionally longjmp if a handler is set. The writer will flag an error if too much data is written, if the wrong number of elements are written, if the data could not be flushed, etc.

The MPack writer API is imperative in nature. Since it's easy to incorrectly compose structured data with an imperative API, MPack provides a debug mode which tracks reads and writes of compound types to ensure that the correct number of elements and bytes were read and written. This allows for rapid development of high-performance applications that use MessagePack. In release mode, these checks are eliminated for maximum performance.

Why Not Just Use JSON?

Conceptually, MessagePack stores data similarly to JSON: they are both composed of simple values such as numbers and strings, stored hierarchically in maps and arrays. So why not just use JSON instead? The main reason is that JSON is designed to be human-readable, so it is not as efficient as a binary serialization format:

  • Compound types such as strings, maps and arrays are delimited, so appropriate storage cannot be allocated upfront. The whole object must be parsed to determine its size.

  • Strings are not stored in their native encoding. They cannot contain quotes or special characters, so they must be escaped when written and converted back when read.

  • Numbers are particularly inefficient (especially when parsing back floats), making JSON inappropriate as a base format for structured data that contains lots of numbers.

The above issues greatly increase the complexity of the decoder. Full-featured JSON decoders are quite large, and minimal decoders tend to leave out such features as string unescaping and float parsing, instead leaving these up to the user or platform. This can lead to hard-to-find and/or platform-specific bugs. This also significantly decreases performance, making JSON unattractive for use in applications such as mobile games.

While the space inefficiencies of JSON can be partially mitigated through minification and compression, the performance inefficiencies cannot. More importantly, if you are minifying and compressing the data, then why use a human-readable format in the first place?

Running the Unit Tests

The MPack build process does not build MPack into a library; it is used to build and run the unit tests. You do not need to build MPack or the unit testing suite to use MPack. The test suite currently only supports Linux.

The test suite uses SCons and requires Valgrind, and can be run in the repository or in the amalgamation package. SCons will build and run the library and unit testing suite in both debug and release for both 32-bit and 64-bit architectures (if available), so it will take a minute or two to build and run. If you are on 64-bit, you will also need support for running 32-bit binaries with 64-bit Valgrind (libc6-dbg:i386 on Ubuntu or valgrind-multilib on Arch.) Just run scons to build and run all tests.


MessagePack (hex)