SlideShare a Scribd company logo
MESSAGEPACK - AN EFFICIENT
BINARY SERIALIZATION FORMAT
Larry Nung
AGENDA
Introduction
Format
MsgPack.Cli
Messagepack VS Protobuf
Reference
Q & A
2
INTRODUCTION
3
INTRODUCTION
 An efficient binary serialization format
 Like JSON. but fast and small.
4
FORMAT
5
FORMAT
6
FORMAT
7
FORMAT
format name first byte (in binary) first byte (in hex)
positive fixint 0xxxxxxx 0x00 - 0x7f
fixmap 1000xxxx 0x80 - 0x8f
fixarray 1001xxxx 0x90 - 0x9f
fixstr 101xxxxx 0xa0 - 0xbf
nil 11000000 0xc0
(never used) 11000001 0xc1
false 11000010 0xc2
true 11000011 0xc3
bin 8 11000100 0xc4
bin 16 11000101 0xc5
bin 32 11000110 0xc6 8
FORMAT
format name first byte (in binary) first byte (in hex)
ext 8 11000111 0xc7
ext 16 11001000 0xc8
ext 32 11001001 0xc9
float 32 11001010 0xca
float 64 11001011 0xcb
uint 8 11001100 0xcc
uint 16 11001101 0xcd
uint 32 11001110 0xce
uint 64 11001111 0xcf
int 8 11010000 0xd0
int 16 11010001 0xd1 9
FORMAT
format name first byte (in binary) first byte (in hex)
int 32 11010010 0xd2
int 64 11010011 0xd3
fixext 1 11010100 0xd4
fixext 2 11010101 0xd5
fixext 4 11010110 0xd6
fixext 8 11010111 0xd7
fixext 16 11011000 0xd8
str 8 11011001 0xd9
str 16 11011010 0xda
str 32 11011011 0xdb
array 16 11011100 0xdc 10
FORMAT
format name first byte (in binary) first byte (in hex)
array 32 11011101 0xdd
map 16 11011110 0xde
map 32 11011111 0xdf
negative fixint 111xxxxx 0xe0 - 0xff
11
FORMAT
12
 Fixed length types
 Integer
 Floating point
 Boolean
 Nil
FORMAT
13
 Nil => 11000000 => 0xc0
 Boolean
 False => 11000010 => 0xc2
 True => 11000011 => 0xc3
 Positive fixint
 0 => 00000000 => 0x00
 1 => 00000001 => 0x01
FORMAT
14
 Variable length types
 Raw bytes
 Array
 Map
FORMAT
 Fixstr
 Compact => 10100007 01100011 01101111 01101101
01110000 01100001 01100011 01110100 => a7 63 6f 6d
70 61 63 74
15
MSGPACK.CLI
16
MSGPACK.CLI
 Install-Package MsgPack.Cli
17
MSGPACK.CLI
using MsgPack.Serialization;
...
public static byte[] Serialize<T>(T thisObj) {
var serializer = SerializationContext.Default.GetSerializer<T>();
using (var ms = new MemoryStream()) {
serializer.Pack(ms, thisObj);
return ms.ToArray();
}
}
public static T Deserialize<T>(byte[] bytes) {
var serializer = SerializationContext.Default.GetSerializer<T>();
using (var byteStream = new MemoryStream(bytes)) {
return serializer.Unpack(byteStream);
}
} 18
MSGPACK.CLI
public class OldPerson {
[MessagePackMember(0)]
public String Name { get; set; }
[MessagePackMember(1)]
public String NickName { get; set; }
[MessagePackIgnore]
public Object Tag { get; set; }
}
public class NewPerson {
[MessagePackMember(2)]
public String ID { get; set; }
[MessagePackMember(0)]
public String Name { get; set; }
[MessagePackMember(1)]
public String NickName { get; set; }
}
19
MSGPACK.CLI
…
var larry = new OldPerson {
Name = "Larry Nung",
NickName = "Larry"
};
var bytes = Serialize(larry);
var person = Deserialize<NewPerson>(bytes);
Console.WriteLine("{0} ({1})", person.NickName,
person.Name);
…
20
MESSAGEPACK VS PROTOBUF
21
MESSAGEPACK VS PROTOBUF
private static void SerializeToStream<T>(Stream stream, T obj) {
stream.Seek(0, SeekOrigin.Begin);
Serializer.Serialize(stream, obj);
}
private static T DeSerializeFromStream<T>(Stream stream) {
stream.Seek(0, SeekOrigin.Begin);
return Serializer.Deserialize<T>(stream);
}
public static void Serialize<T>(Stream stream, T thisObj) {
stream.Seek(0, SeekOrigin.Begin);
var serializer = SerializationContext.Default.GetSerializer<T>();
serializer.Pack(stream, thisObj);
}
public static T Deserialize<T>(Stream stream) {
stream.Seek(0, SeekOrigin.Begin);
var serializer = SerializationContext.Default.GetSerializer<T>();
return serializer.Unpack(stream);
}
22
MESSAGEPACK VS PROTOBUF
var counts = new int[] { 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
...
Serialize(ms, larry);
Console.WriteLine("MsgPack Size: {0}", ms.Length);
SerializeToStream(ms, larry);
Console.WriteLine("ProtoBuf Size: {0}", ms.Length);
...
foreach (var count in counts)
{
…
Console.WriteLine("MsgPack Serialize: {0} ms", DoTest(count, () => { Serialize(ms,
larry); }));
Console.WriteLine("ProtoBuf Serialize: {0} ms", DoTest(count, () =>
{ SerializeToStream(ms, larry); }));
Console.WriteLine("MsgPack DeSerialize: {0} ms", DoTest(count, () =>
{ Deserialize<Person>(ms); }));
Console.WriteLine("ProtoBuf DeSerialize: {0} ms", DoTest(count, () =>
{ DeSerializeFromStream<Person>(ms); }));
}
23
MESSAGEPACK VS PROTOBUF
24
MESSAGEPACK VS PROTOBUF
Serialize
25
0
5000
10000
15000
20000
25000
30000
35000
40000
45000
100 1000 10000 100000 1000000 10000000 100000000
MsgPack
Protobuf
MESSAGEPACK VS PROTOBUF
Deserialize
26
0
10000
20000
30000
40000
50000
60000
70000
80000
100 1000 10000 100000 1000000 10000000 100000000
MsgPack
Protobuf
REFERENCE
27
REFERENCE
 MessagePack: It's like JSON. but fast and small.
 http://msgpack.org/
28
Q&A
29
QUESTION & ANSWER
30

More Related Content

PDF
Understanding the Disruptor
PPTX
Why learn Internals?
PDF
Fast indexes with roaring #gomtl-10
KEY
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
PDF
Yevhen Tatarynov "From POC to High-Performance .NET applications"
PPTX
Disruptor
PDF
Protostar VM - Heap3
KEY
Rubyスクリプト
Understanding the Disruptor
Why learn Internals?
Fast indexes with roaring #gomtl-10
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Disruptor
Protostar VM - Heap3
Rubyスクリプト

What's hot (20)

PDF
The What, Why And How of ClojureScript
PDF
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
PDF
PyCon KR 2019 sprint - RustPython by example
PPTX
LiteDB - A .NET NoSQL Document Store in a single data file
PPSX
LMAX Disruptor as real-life example
PPTX
Hebrew Windows Cluster 2012 in a one slide diagram
 
PDF
EROSについて
PDF
Concurrency: Rubies, plural
PDF
Concurrency: Rubies, Plural
PDF
Datafying Bitcoins
PDF
MessagePack-CSharpってシャープなの?@激突! Aiming x CloverLab [クライアント対決]部門
PPTX
#2 (UDP)
PPTX
Barcamp presentation
PDF
The Ring programming language version 1.6 book - Part 25 of 189
PDF
Linux-Permission
ODP
Clojure made really really simple
PDF
tokyotalk
PDF
Coding in GO - GDG SL - NSBM
PDF
Clojure+ClojureScript Webapps
PDF
multi-line record grep
The What, Why And How of ClojureScript
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
PyCon KR 2019 sprint - RustPython by example
LiteDB - A .NET NoSQL Document Store in a single data file
LMAX Disruptor as real-life example
Hebrew Windows Cluster 2012 in a one slide diagram
 
EROSについて
Concurrency: Rubies, plural
Concurrency: Rubies, Plural
Datafying Bitcoins
MessagePack-CSharpってシャープなの?@激突! Aiming x CloverLab [クライアント対決]部門
#2 (UDP)
Barcamp presentation
The Ring programming language version 1.6 book - Part 25 of 189
Linux-Permission
Clojure made really really simple
tokyotalk
Coding in GO - GDG SL - NSBM
Clojure+ClojureScript Webapps
multi-line record grep
Ad

Similar to MessagePack - An efficient binary serialization format (20)

PDF
MessagePack(msgpack): Compact and Fast Serialization Library
PPTX
Protocol Buffer.ppt
PPTX
Golang proto buff_ixxo
PDF
Architecture of MessagePack
PPTX
Protocol Buffers
PDF
Performance Optimization Techniques of MessagePack-Ruby - RubyKaigi 2019
PPTX
Thrift vs Protocol Buffers vs Avro - Biased Comparison
PPT
Udp Programming
PPT
Udp Programming
PDF
Data Serialization Using Google Protocol Buffers
PPTX
Google Protocol Buffers
PDF
Rest style web services (google protocol buffers) prasad nirantar
PDF
Breaking .net through serialization
PPTX
Data Encoding in Remote Procedure calls.
PDF
l-rubysocks-a4
PDF
l-rubysocks-a4
PDF
Socket++
PPTX
protobuf-net - Protocol Buffers library for idiomatic .NET
PPTX
Protocol buffers
PDF
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
MessagePack(msgpack): Compact and Fast Serialization Library
Protocol Buffer.ppt
Golang proto buff_ixxo
Architecture of MessagePack
Protocol Buffers
Performance Optimization Techniques of MessagePack-Ruby - RubyKaigi 2019
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Udp Programming
Udp Programming
Data Serialization Using Google Protocol Buffers
Google Protocol Buffers
Rest style web services (google protocol buffers) prasad nirantar
Breaking .net through serialization
Data Encoding in Remote Procedure calls.
l-rubysocks-a4
l-rubysocks-a4
Socket++
protobuf-net - Protocol Buffers library for idiomatic .NET
Protocol buffers
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Ad

More from Larry Nung (20)

PPTX
Ansible - simple it automation
PPTX
sonarwhal - a linting tool for the web
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 8
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 7
PPTX
BenchmarkDotNet - Powerful .NET library for benchmarking
PPTX
PLSQL Coding Guidelines - Part 6
PPTX
SonarQube - The leading platform for Continuous Code Quality
PPTX
Visual studio 2017
PPTX
Web deploy command line
PPTX
Web deploy
PPTX
SikuliX
PPTX
Topshelf - An easy service hosting framework for building Windows services us...
PPTX
Common.logging
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 5
PPTX
Regular expression
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 4
PPTX
Fx.configuration
PPTX
StackExchange.redis
PPTX
GRUNT - The JavaScript Task Runner
PPTX
Bower - A package manager for the web
Ansible - simple it automation
sonarwhal - a linting tool for the web
PL/SQL & SQL CODING GUIDELINES – Part 8
PL/SQL & SQL CODING GUIDELINES – Part 7
BenchmarkDotNet - Powerful .NET library for benchmarking
PLSQL Coding Guidelines - Part 6
SonarQube - The leading platform for Continuous Code Quality
Visual studio 2017
Web deploy command line
Web deploy
SikuliX
Topshelf - An easy service hosting framework for building Windows services us...
Common.logging
PL/SQL & SQL CODING GUIDELINES – Part 5
Regular expression
PL/SQL & SQL CODING GUIDELINES – Part 4
Fx.configuration
StackExchange.redis
GRUNT - The JavaScript Task Runner
Bower - A package manager for the web

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
A Presentation on Artificial Intelligence
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A Presentation on Artificial Intelligence
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction

MessagePack - An efficient binary serialization format

  • 1. MESSAGEPACK - AN EFFICIENT BINARY SERIALIZATION FORMAT Larry Nung
  • 4. INTRODUCTION  An efficient binary serialization format  Like JSON. but fast and small. 4
  • 8. FORMAT format name first byte (in binary) first byte (in hex) positive fixint 0xxxxxxx 0x00 - 0x7f fixmap 1000xxxx 0x80 - 0x8f fixarray 1001xxxx 0x90 - 0x9f fixstr 101xxxxx 0xa0 - 0xbf nil 11000000 0xc0 (never used) 11000001 0xc1 false 11000010 0xc2 true 11000011 0xc3 bin 8 11000100 0xc4 bin 16 11000101 0xc5 bin 32 11000110 0xc6 8
  • 9. FORMAT format name first byte (in binary) first byte (in hex) ext 8 11000111 0xc7 ext 16 11001000 0xc8 ext 32 11001001 0xc9 float 32 11001010 0xca float 64 11001011 0xcb uint 8 11001100 0xcc uint 16 11001101 0xcd uint 32 11001110 0xce uint 64 11001111 0xcf int 8 11010000 0xd0 int 16 11010001 0xd1 9
  • 10. FORMAT format name first byte (in binary) first byte (in hex) int 32 11010010 0xd2 int 64 11010011 0xd3 fixext 1 11010100 0xd4 fixext 2 11010101 0xd5 fixext 4 11010110 0xd6 fixext 8 11010111 0xd7 fixext 16 11011000 0xd8 str 8 11011001 0xd9 str 16 11011010 0xda str 32 11011011 0xdb array 16 11011100 0xdc 10
  • 11. FORMAT format name first byte (in binary) first byte (in hex) array 32 11011101 0xdd map 16 11011110 0xde map 32 11011111 0xdf negative fixint 111xxxxx 0xe0 - 0xff 11
  • 12. FORMAT 12  Fixed length types  Integer  Floating point  Boolean  Nil
  • 13. FORMAT 13  Nil => 11000000 => 0xc0  Boolean  False => 11000010 => 0xc2  True => 11000011 => 0xc3  Positive fixint  0 => 00000000 => 0x00  1 => 00000001 => 0x01
  • 14. FORMAT 14  Variable length types  Raw bytes  Array  Map
  • 15. FORMAT  Fixstr  Compact => 10100007 01100011 01101111 01101101 01110000 01100001 01100011 01110100 => a7 63 6f 6d 70 61 63 74 15
  • 18. MSGPACK.CLI using MsgPack.Serialization; ... public static byte[] Serialize<T>(T thisObj) { var serializer = SerializationContext.Default.GetSerializer<T>(); using (var ms = new MemoryStream()) { serializer.Pack(ms, thisObj); return ms.ToArray(); } } public static T Deserialize<T>(byte[] bytes) { var serializer = SerializationContext.Default.GetSerializer<T>(); using (var byteStream = new MemoryStream(bytes)) { return serializer.Unpack(byteStream); } } 18
  • 19. MSGPACK.CLI public class OldPerson { [MessagePackMember(0)] public String Name { get; set; } [MessagePackMember(1)] public String NickName { get; set; } [MessagePackIgnore] public Object Tag { get; set; } } public class NewPerson { [MessagePackMember(2)] public String ID { get; set; } [MessagePackMember(0)] public String Name { get; set; } [MessagePackMember(1)] public String NickName { get; set; } } 19
  • 20. MSGPACK.CLI … var larry = new OldPerson { Name = "Larry Nung", NickName = "Larry" }; var bytes = Serialize(larry); var person = Deserialize<NewPerson>(bytes); Console.WriteLine("{0} ({1})", person.NickName, person.Name); … 20
  • 22. MESSAGEPACK VS PROTOBUF private static void SerializeToStream<T>(Stream stream, T obj) { stream.Seek(0, SeekOrigin.Begin); Serializer.Serialize(stream, obj); } private static T DeSerializeFromStream<T>(Stream stream) { stream.Seek(0, SeekOrigin.Begin); return Serializer.Deserialize<T>(stream); } public static void Serialize<T>(Stream stream, T thisObj) { stream.Seek(0, SeekOrigin.Begin); var serializer = SerializationContext.Default.GetSerializer<T>(); serializer.Pack(stream, thisObj); } public static T Deserialize<T>(Stream stream) { stream.Seek(0, SeekOrigin.Begin); var serializer = SerializationContext.Default.GetSerializer<T>(); return serializer.Unpack(stream); } 22
  • 23. MESSAGEPACK VS PROTOBUF var counts = new int[] { 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 }; ... Serialize(ms, larry); Console.WriteLine("MsgPack Size: {0}", ms.Length); SerializeToStream(ms, larry); Console.WriteLine("ProtoBuf Size: {0}", ms.Length); ... foreach (var count in counts) { … Console.WriteLine("MsgPack Serialize: {0} ms", DoTest(count, () => { Serialize(ms, larry); })); Console.WriteLine("ProtoBuf Serialize: {0} ms", DoTest(count, () => { SerializeToStream(ms, larry); })); Console.WriteLine("MsgPack DeSerialize: {0} ms", DoTest(count, () => { Deserialize<Person>(ms); })); Console.WriteLine("ProtoBuf DeSerialize: {0} ms", DoTest(count, () => { DeSerializeFromStream<Person>(ms); })); } 23
  • 25. MESSAGEPACK VS PROTOBUF Serialize 25 0 5000 10000 15000 20000 25000 30000 35000 40000 45000 100 1000 10000 100000 1000000 10000000 100000000 MsgPack Protobuf
  • 26. MESSAGEPACK VS PROTOBUF Deserialize 26 0 10000 20000 30000 40000 50000 60000 70000 80000 100 1000 10000 100000 1000000 10000000 100000000 MsgPack Protobuf
  • 28. REFERENCE  MessagePack: It's like JSON. but fast and small.  http://msgpack.org/ 28