Skip to content
Drew Noakes edited this page Feb 17, 2015 · 4 revisions

MessagePack is interoperable binary encoding format. You can reduce the size of stream dramatically when you have a data of which contains many binary (for example, numeric) data.

Usage

It's simple. Create, do, done.

There are only 2 steps to serialize types.

  1. Invoke MessagePackSerializer.Create<T>() where T is the type of the root object you're serialising. This returns you a MessagePackSerializer<T> object.
  2. Invoke Pack() or Unpack() on the serialiser.

A small sample is here:

[C#]

var serializer = MessagePackSerializer.Create<Foo>();
serializer.Pack(foo, stream);
stream.Position = 0;
var value = serializer.Unpack(stream);

[Visual Basic]

Dim serializer = MessagePackSerializer.Create(Of Foo)()
serializer.Pack(foo, stream)
stream.Position = 0
Dim value = serializer.Unpack(stream)

Note: Of course, you must add assembly reference to MsgPack.dll to your project.

Note: For Silverlight and WindowsPhone, there are 2 assemblies, and both of them are required to build the above code. If you want to reduce assembly size, see Manual Packings -- it is the reason two assemblies exist.

Clone this wiki locally