SlideShare a Scribd company logo
1 of 27
Download to read offline
MessagePack(msgpack):
A Compact and Fast Serialization Library
Takatoshi Kondo
2015/5/14 1Copyright OGIS-RI 2015
• Taka (Takatoshi Kondo)
– from TOKYO, JAPAN
• OGIS-RI Co., Ltd.
– Developing Pub/Sub IoT Platform using MessagePack
• A committer on the msgpack-c OSS project
• Other experience: Wrote the “Boost.MSM Guide”
– http://redboltz.wikidot.com/boost-msm-guide
2015/5/14 Copyright OGIS-RI 2015 2
About me
What is MessagePack?
2015/5/14 Copyright OGIS-RI 2015 3
• Same as JSON
– Portable
– Contain basic type information
• For example, map, array, string, boolean...
– Composite data structure
• Different from JSON
– Smaller size
– Binary coded
– Can handle binary data without text encoding such as Base64
– Easier to parse, requires less computing power
2015/5/14 Copyright OGIS-RI 2015 4
MessagePack vs. JSON
• Same as JSON
– Portable
– Contain basic type information
• For example, map, array, string, boolean...
– Composite data structure
• Different from JSON
– Smaller size
– Binary coded
– Can handle binary data without text encoding such as Base64
– Easier to parse, requires less computing power
2015/5/14 Copyright OGIS-RI 2015 5
MessagePack vs. JSON
msgpack::object
nil boolean u64 i64 f64
str bin ext array map
*
*
double, float object_kv
key val
MessagePack/Boost.Serialization
2015/5/14 6Copyright OGIS-RI 2015
• The goals of the msgpack and the
Boost.Serialization are different.
– msgpack: Interexchange the data with
different programming languages.
– Boost.Serialization: Serialize every data and relations.
e.g.) shared_ptr
• msgpack can be used as a portable binary
archive of the Boost.Serialization.
– https://github.com/redboltz/rui/tree/support_boost_1_57_0
• Forked from Norihisa Fujita’s implementation
C++
msgpack
ruby
python
shared_ptr
shared_ptr
shared_ptr
42
42
Boost.Serialization
format
Supported Programming Languages
2015/5/14 Copyright OGIS-RI 2015 7
Pack/Unpack
2015/5/14 8
#include <tuple>
#include <string>
#include <sstream>
#include <msgpack.hpp>
int main() {
auto t1 = std::make_tuple("hello", true, 42, 12.3);
std::stringstream ss;
msgpack::pack(ss, t1);
msgpack::unpacked unpacked
= msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object obj = unpacked.get();
auto t2 = obj.as<std::tuple<std::string, bool, int, double>>();
assert(t1 == t2);
}
You can use any types that have
the member function
write(const char*, std::size_t);
Copyright OGIS-RI 2015
packing
unpacking
convering
Stream Deserialization
2015/5/14 9
class unpacker {
public:
// Constructor is omitted in this presentation
void reserve_buffer(std::size_t size);
char* buffer();
void buffer_consumed(std::size_t size);
bool next(unpacked& result);
};
Copyright OGIS-RI 2015
Stream Deserialization
2015/5/14 10Copyright OGIS-RI 2015
std::size_t const try_read_size = 100;
msgpack::unpacker unp;
while (/* block until input becomes readable */) {
unp.reserve_buffer(try_read_size);
std::size_t actual_read_size = input.readsome(
unp.buffer(), try_read_size);
unp.buffer_consumed(actual_read_size);
msgpack::unpacked result;
// MessagePack data loop
while(unp.next(result)) {
msgpack::object obj(result.get());
}
}
Stream Deserialization
2015/5/14 11Copyright OGIS-RI 2015
std::size_t const try_read_size = 100;
msgpack::unpacker unp;
while (/* block until input becomes readable */) {
unp.reserve_buffer(try_read_size);
std::size_t actual_read_size = input.readsome(
unp.buffer(), try_read_size);
unp.buffer_consumed(actual_read_size);
msgpack::unpacked result;
// MessagePack data loop
while(unp.next(result)) {
msgpack::object obj(result.get());
}
}
The size may decided by receive performance,
transmit layer's protocol and so on.
Stream Deserialization
2015/5/14 12Copyright OGIS-RI 2015
std::size_t const try_read_size = 100;
msgpack::unpacker unp;
while (/* block until input becomes readable */) {
unp.reserve_buffer(try_read_size);
std::size_t actual_read_size = input.readsome(
unp.buffer(), try_read_size);
unp.buffer_consumed(actual_read_size);
msgpack::unpacked result;
// MessagePack data loop
while(unp.next(result)) {
msgpack::object obj(result.get());
}
}
The size may decided by receive performance,
transmit layer's protocol and so on.
unp has at least try_read_size buffer on this point.
Stream Deserialization
2015/5/14 13Copyright OGIS-RI 2015
std::size_t const try_read_size = 100;
msgpack::unpacker unp;
while (/* block until input becomes readable */) {
unp.reserve_buffer(try_read_size);
std::size_t actual_read_size = input.readsome(
unp.buffer(), try_read_size);
unp.buffer_consumed(actual_read_size);
msgpack::unpacked result;
// MessagePack data loop
while(unp.next(result)) {
msgpack::object obj(result.get());
}
}
The size may decided by receive performance,
transmit layer's protocol and so on.
unp has at least try_read_size buffer on this point.
input is a kind of I/O library object.
read message to msgpack::unpacker's internal buffer directly.
Stream Deserialization
2015/5/14 14Copyright OGIS-RI 2015
std::size_t const try_read_size = 100;
msgpack::unpacker unp;
while (/* block until input becomes readable */) {
unp.reserve_buffer(try_read_size);
std::size_t actual_read_size = input.readsome(
unp.buffer(), try_read_size);
unp.buffer_consumed(actual_read_size);
msgpack::unpacked result;
// MessagePack data loop
while(unp.next(result)) {
msgpack::object obj(result.get());
}
}
The size may decided by receive performance,
transmit layer's protocol and so on.
unp has at least try_read_size buffer on this point.
input is a kind of I/O library object.
read message to msgpack::unpacker's internal buffer directly.
notify msgpack::unpacker actual consumed size.
Stream Deserialization
2015/5/14 15Copyright OGIS-RI 2015
std::size_t const try_read_size = 100;
msgpack::unpacker unp;
while (/* block until input becomes readable */) {
unp.reserve_buffer(try_read_size);
std::size_t actual_read_size = input.readsome(
unp.buffer(), try_read_size);
unp.buffer_consumed(actual_read_size);
msgpack::unpacked result;
// MessagePack data loop
while(unp.next(result)) {
msgpack::object obj(result.get());
}
}
The size may decided by receive performance,
transmit layer's protocol and so on.
unp has at least try_read_size buffer on this point.
input is a kind of I/O library object.
read message to msgpack::unpacker's internal buffer directly.
notify msgpack::unpacker actual consumed size.
Use obj. convert to C++ types
All complete msgpack message is processed at this point,
then continue to read addtional message.
Zero-Copy Deserialization
2015/5/14 16Copyright OGIS-RI 2015
unpacker buffer int string bin
header payload header payload
array
client memory
msgpack memory
Zero copy deserialization
2015/5/14 17Copyright OGIS-RI 2015
zone
chunk_list
finalizer_array
object
(array)
object
(int)
object
(string)
object
(bin)
via.array.ptr
chunk
unpacker buffer int string bin
header payload header payload
via.str.ptr via.bin.ptr
array
(msgpack format)
client memory
msgpack memory
managed using reference counter
unpacked
copy or reference is selectable
Zero copy deserialization
2015/5/14 18Copyright OGIS-RI 2015
zone
chunk_list
finalizer_array
object
(array)
object
(int)
object
(string)
object
(bin)
via.array.ptr
chunk
unpacker buffer int string bin
header payload header payload
via.str.ptr via.bin.ptr
array
(msgpack format)
client memory
msgpack memory
managed using reference counter
unpacked
convert
Convert to any types that adapts MessagePack
std::tuple<int, boost::string_ref, std::vector<char>>
copyref
copy or reference is selectable
MessagePack Adaptors
2015/5/14 19Copyright OGIS-RI 2015
https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_adaptor
C++ type msgpack::object type
bool bool
char* str
std::deque array
char positive/negative integer
signed ints *1 positive/negative integer
unsigned ints *2 positive integer
std::list array
std::map array
std::pair array
std::set array
std::string str
std::vector array
std::vector<char> bin
*1 signed ints signed char, signed short, signed int, signed long, signed long long
*2 unsigned ints unsigned char, unsigned short, unsigned int, signed long, signed long long
C++11 type
msgpack::
object type
std::array array
std::array<char> bin
std::forward_list array
std::tuple array
std::array array
std::unordered_map array
std::unordered_set array
boost type
msgpack::
object type
boost::optional<T> T
boost::string_ref str
MessagePack Adaptors
2015/5/14 20Copyright OGIS-RI 2015
https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_adaptor
#include <msgpack.hpp>
struct your_class : base1, base2 {
int a;
std::string b;
// You can choose any order.
// It is represented to the msgpack array elements order.
MSGPACK_DEFINE(a, b, MSGPACK_BASE(base1), MSGPACK_BASE(base2));
};
• If you have questions, feel free to contact me :)
• Takatoshi Kondo
– redboltz@gmail.com
– twitter: redboltz
• Resources
– MessagePack
• http://msgpack.org/
– msgpack-c
• https://github.com/msgpack/msgpack-c
– msgpack-c Documents
• https://github.com/msgpack/msgpack-c/wiki
– msgpack-c stream unpack algorithm
• A little old but concept is the same
• http://www.slideshare.net/taka111/msgpackc
2015/5/14 Copyright OGIS-RI 2015 21
Thank you
Extra Slides
2015/5/14 Copyright OGIS-RI 2015 22
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
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 0xcf2015/5/14 Copyright OGIS-RI 2015 23
MessagePack Formats
https://github.com/msgpack/msgpack/blob/master/spec.md
Format
name
first byte (in binary) first byte (in hex)
int 8 11010000 0xd0
int 16 11010001 0xd1
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
array 32 11011101 0xdd
map 16 11011110 0xde
map 32 11011111 0xdf
negative
fixint
111xxxxx 0xe0 - 0xff
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
2015/5/14 Copyright OGIS-RI 2015 24
MessagePack Formats
https://github.com/msgpack/msgpack/blob/master/spec.md
2015/5/14 Copyright OGIS-RI 2015 25
MessagePack Format
https://github.com/msgpack/msgpack/blob/master/spec.md#int-format-family
2015/5/14 Copyright OGIS-RI 2015 26
MessagepPack format
What is MessagePack?
2015/5/14 Copyright OGIS-RI 2015 27

More Related Content

What's hot

게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...
게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...
게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...Amazon Web Services Korea
 
〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3
〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3
〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3Heungsub Lee
 
External to DA, the OS X Way
External to DA, the OS X WayExternal to DA, the OS X Way
External to DA, the OS X WayStephan Borosh
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]MongoDB
 
Fluentd Overview, Now and Then
Fluentd Overview, Now and ThenFluentd Overview, Now and Then
Fluentd Overview, Now and ThenSATOSHI TAGOMORI
 
Thick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxAnurag Srivastava
 
맛만 보자 액터 모델이란
맛만 보자 액터 모델이란 맛만 보자 액터 모델이란
맛만 보자 액터 모델이란 jbugkorea
 
GA로 게임 로그 분석하기
GA로 게임 로그 분석하기GA로 게임 로그 분석하기
GA로 게임 로그 분석하기Alan Kang
 
Introductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformIntroductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformMichael Heyns
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
анонимность в сети от Hackyourmom
анонимность в сети от Hackyourmomанонимность в сети от Hackyourmom
анонимность в сети от Hackyourmomssuser1d98e3
 
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?Juhong Park
 
Server monitoring using grafana and prometheus
Server monitoring using grafana and prometheusServer monitoring using grafana and prometheus
Server monitoring using grafana and prometheusCeline George
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration TestingCheah Eng Soon
 
[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유
[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유
[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유Hyojun Jeon
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMFrans Rosén
 
Little Big Data #1. 바닥부터 시작하는 데이터 인프라
Little Big Data #1. 바닥부터 시작하는 데이터 인프라Little Big Data #1. 바닥부터 시작하는 데이터 인프라
Little Big Data #1. 바닥부터 시작하는 데이터 인프라Seongyun Byeon
 
devon2013: 사내Git저장소개발사례
devon2013: 사내Git저장소개발사례devon2013: 사내Git저장소개발사례
devon2013: 사내Git저장소개발사례Daehyun Kim
 
Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB InfluxData
 

What's hot (20)

게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...
게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...
게임 데이터 분석을 위한 Data Lake 구축과 Machine Learning 을 활용한 분석 Hands on Lab (안효빈 솔루션즈 ...
 
〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3
〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3
〈야생의 땅: 듀랑고〉 서버 아키텍처 Vol. 3
 
External to DA, the OS X Way
External to DA, the OS X WayExternal to DA, the OS X Way
External to DA, the OS X Way
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
 
Fluentd 101
Fluentd 101Fluentd 101
Fluentd 101
 
Fluentd Overview, Now and Then
Fluentd Overview, Now and ThenFluentd Overview, Now and Then
Fluentd Overview, Now and Then
 
Thick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptx
 
맛만 보자 액터 모델이란
맛만 보자 액터 모델이란 맛만 보자 액터 모델이란
맛만 보자 액터 모델이란
 
GA로 게임 로그 분석하기
GA로 게임 로그 분석하기GA로 게임 로그 분석하기
GA로 게임 로그 분석하기
 
Introductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformIntroductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with Terraform
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
анонимность в сети от Hackyourmom
анонимность в сети от Hackyourmomанонимность в сети от Hackyourmom
анонимность в сети от Hackyourmom
 
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
 
Server monitoring using grafana and prometheus
Server monitoring using grafana and prometheusServer monitoring using grafana and prometheus
Server monitoring using grafana and prometheus
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration Testing
 
[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유
[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유
[NDC18] 야생의 땅 듀랑고의 데이터 엔지니어링 이야기: 로그 시스템 구축 경험 공유
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 
Little Big Data #1. 바닥부터 시작하는 데이터 인프라
Little Big Data #1. 바닥부터 시작하는 데이터 인프라Little Big Data #1. 바닥부터 시작하는 데이터 인프라
Little Big Data #1. 바닥부터 시작하는 데이터 인프라
 
devon2013: 사내Git저장소개발사례
devon2013: 사내Git저장소개발사례devon2013: 사내Git저장소개발사례
devon2013: 사내Git저장소개발사례
 
Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB
 

Similar to MessagePack(msgpack): Compact and Fast Serialization Library

BUMP implementation in Java.docxThe project is to implemen.docx
BUMP implementation in Java.docxThe project is to implemen.docxBUMP implementation in Java.docxThe project is to implemen.docx
BUMP implementation in Java.docxThe project is to implemen.docxhartrobert670
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11Russell Childs
 
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxFinal Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxvoversbyobersby
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenPostgresOpen
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstackThierry Gayet
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Max Kleiner
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...apidays
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...Mr. Vengineer
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeYung-Yu Chen
 
OSA Con 2022: Streaming Data Made Easy
OSA Con 2022:  Streaming Data Made EasyOSA Con 2022:  Streaming Data Made Easy
OSA Con 2022: Streaming Data Made EasyTimothy Spann
 
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...Altinity Ltd
 

Similar to MessagePack(msgpack): Compact and Fast Serialization Library (20)

BUMP implementation in Java.docxThe project is to implemen.docx
BUMP implementation in Java.docxThe project is to implemen.docxBUMP implementation in Java.docxThe project is to implemen.docx
BUMP implementation in Java.docxThe project is to implemen.docx
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11
 
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxFinal Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
 
Why learn Internals?
Why learn Internals?Why learn Internals?
Why learn Internals?
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
OSA Con 2022: Streaming Data Made Easy
OSA Con 2022:  Streaming Data Made EasyOSA Con 2022:  Streaming Data Made Easy
OSA Con 2022: Streaming Data Made Easy
 
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
 
Golang
GolangGolang
Golang
 

More from Takatoshi Kondo

CppCon2016 report and Boost.SML
CppCon2016 report and Boost.SMLCppCon2016 report and Boost.SML
CppCon2016 report and Boost.SMLTakatoshi Kondo
 
Pub/Sub model, msm, and asio
Pub/Sub model, msm, and asioPub/Sub model, msm, and asio
Pub/Sub model, msm, and asioTakatoshi Kondo
 
Effective Modern C++ study group Item39
Effective Modern C++ study group Item39Effective Modern C++ study group Item39
Effective Modern C++ study group Item39Takatoshi Kondo
 
Boostsapporomsmpost 111106070819-phpapp02
Boostsapporomsmpost 111106070819-phpapp02Boostsapporomsmpost 111106070819-phpapp02
Boostsapporomsmpost 111106070819-phpapp02Takatoshi Kondo
 
Boostsapporomsmpre 111030054504-phpapp02
Boostsapporomsmpre 111030054504-phpapp02Boostsapporomsmpre 111030054504-phpapp02
Boostsapporomsmpre 111030054504-phpapp02Takatoshi Kondo
 
Aho-Corasick string matching algorithm
Aho-Corasick string matching algorithmAho-Corasick string matching algorithm
Aho-Corasick string matching algorithmTakatoshi Kondo
 

More from Takatoshi Kondo (10)

CppCon2016 report and Boost.SML
CppCon2016 report and Boost.SMLCppCon2016 report and Boost.SML
CppCon2016 report and Boost.SML
 
Pub/Sub model, msm, and asio
Pub/Sub model, msm, and asioPub/Sub model, msm, and asio
Pub/Sub model, msm, and asio
 
Effective Modern C++ study group Item39
Effective Modern C++ study group Item39Effective Modern C++ study group Item39
Effective Modern C++ study group Item39
 
Boost sg msgpack
Boost sg msgpackBoost sg msgpack
Boost sg msgpack
 
Emcpp0506
Emcpp0506Emcpp0506
Emcpp0506
 
Boostsapporomsmpost 111106070819-phpapp02
Boostsapporomsmpost 111106070819-phpapp02Boostsapporomsmpost 111106070819-phpapp02
Boostsapporomsmpost 111106070819-phpapp02
 
Boostsapporomsmpre 111030054504-phpapp02
Boostsapporomsmpre 111030054504-phpapp02Boostsapporomsmpre 111030054504-phpapp02
Boostsapporomsmpre 111030054504-phpapp02
 
N3495 inplace realloc
N3495 inplace reallocN3495 inplace realloc
N3495 inplace realloc
 
N3701 concept lite
N3701 concept liteN3701 concept lite
N3701 concept lite
 
Aho-Corasick string matching algorithm
Aho-Corasick string matching algorithmAho-Corasick string matching algorithm
Aho-Corasick string matching algorithm
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 

MessagePack(msgpack): Compact and Fast Serialization Library

  • 1. MessagePack(msgpack): A Compact and Fast Serialization Library Takatoshi Kondo 2015/5/14 1Copyright OGIS-RI 2015
  • 2. • Taka (Takatoshi Kondo) – from TOKYO, JAPAN • OGIS-RI Co., Ltd. – Developing Pub/Sub IoT Platform using MessagePack • A committer on the msgpack-c OSS project • Other experience: Wrote the “Boost.MSM Guide” – http://redboltz.wikidot.com/boost-msm-guide 2015/5/14 Copyright OGIS-RI 2015 2 About me
  • 3. What is MessagePack? 2015/5/14 Copyright OGIS-RI 2015 3
  • 4. • Same as JSON – Portable – Contain basic type information • For example, map, array, string, boolean... – Composite data structure • Different from JSON – Smaller size – Binary coded – Can handle binary data without text encoding such as Base64 – Easier to parse, requires less computing power 2015/5/14 Copyright OGIS-RI 2015 4 MessagePack vs. JSON
  • 5. • Same as JSON – Portable – Contain basic type information • For example, map, array, string, boolean... – Composite data structure • Different from JSON – Smaller size – Binary coded – Can handle binary data without text encoding such as Base64 – Easier to parse, requires less computing power 2015/5/14 Copyright OGIS-RI 2015 5 MessagePack vs. JSON msgpack::object nil boolean u64 i64 f64 str bin ext array map * * double, float object_kv key val
  • 6. MessagePack/Boost.Serialization 2015/5/14 6Copyright OGIS-RI 2015 • The goals of the msgpack and the Boost.Serialization are different. – msgpack: Interexchange the data with different programming languages. – Boost.Serialization: Serialize every data and relations. e.g.) shared_ptr • msgpack can be used as a portable binary archive of the Boost.Serialization. – https://github.com/redboltz/rui/tree/support_boost_1_57_0 • Forked from Norihisa Fujita’s implementation C++ msgpack ruby python shared_ptr shared_ptr shared_ptr 42 42 Boost.Serialization format
  • 7. Supported Programming Languages 2015/5/14 Copyright OGIS-RI 2015 7
  • 8. Pack/Unpack 2015/5/14 8 #include <tuple> #include <string> #include <sstream> #include <msgpack.hpp> int main() { auto t1 = std::make_tuple("hello", true, 42, 12.3); std::stringstream ss; msgpack::pack(ss, t1); msgpack::unpacked unpacked = msgpack::unpack(ss.str().data(), ss.str().size()); msgpack::object obj = unpacked.get(); auto t2 = obj.as<std::tuple<std::string, bool, int, double>>(); assert(t1 == t2); } You can use any types that have the member function write(const char*, std::size_t); Copyright OGIS-RI 2015 packing unpacking convering
  • 9. Stream Deserialization 2015/5/14 9 class unpacker { public: // Constructor is omitted in this presentation void reserve_buffer(std::size_t size); char* buffer(); void buffer_consumed(std::size_t size); bool next(unpacked& result); }; Copyright OGIS-RI 2015
  • 10. Stream Deserialization 2015/5/14 10Copyright OGIS-RI 2015 std::size_t const try_read_size = 100; msgpack::unpacker unp; while (/* block until input becomes readable */) { unp.reserve_buffer(try_read_size); std::size_t actual_read_size = input.readsome( unp.buffer(), try_read_size); unp.buffer_consumed(actual_read_size); msgpack::unpacked result; // MessagePack data loop while(unp.next(result)) { msgpack::object obj(result.get()); } }
  • 11. Stream Deserialization 2015/5/14 11Copyright OGIS-RI 2015 std::size_t const try_read_size = 100; msgpack::unpacker unp; while (/* block until input becomes readable */) { unp.reserve_buffer(try_read_size); std::size_t actual_read_size = input.readsome( unp.buffer(), try_read_size); unp.buffer_consumed(actual_read_size); msgpack::unpacked result; // MessagePack data loop while(unp.next(result)) { msgpack::object obj(result.get()); } } The size may decided by receive performance, transmit layer's protocol and so on.
  • 12. Stream Deserialization 2015/5/14 12Copyright OGIS-RI 2015 std::size_t const try_read_size = 100; msgpack::unpacker unp; while (/* block until input becomes readable */) { unp.reserve_buffer(try_read_size); std::size_t actual_read_size = input.readsome( unp.buffer(), try_read_size); unp.buffer_consumed(actual_read_size); msgpack::unpacked result; // MessagePack data loop while(unp.next(result)) { msgpack::object obj(result.get()); } } The size may decided by receive performance, transmit layer's protocol and so on. unp has at least try_read_size buffer on this point.
  • 13. Stream Deserialization 2015/5/14 13Copyright OGIS-RI 2015 std::size_t const try_read_size = 100; msgpack::unpacker unp; while (/* block until input becomes readable */) { unp.reserve_buffer(try_read_size); std::size_t actual_read_size = input.readsome( unp.buffer(), try_read_size); unp.buffer_consumed(actual_read_size); msgpack::unpacked result; // MessagePack data loop while(unp.next(result)) { msgpack::object obj(result.get()); } } The size may decided by receive performance, transmit layer's protocol and so on. unp has at least try_read_size buffer on this point. input is a kind of I/O library object. read message to msgpack::unpacker's internal buffer directly.
  • 14. Stream Deserialization 2015/5/14 14Copyright OGIS-RI 2015 std::size_t const try_read_size = 100; msgpack::unpacker unp; while (/* block until input becomes readable */) { unp.reserve_buffer(try_read_size); std::size_t actual_read_size = input.readsome( unp.buffer(), try_read_size); unp.buffer_consumed(actual_read_size); msgpack::unpacked result; // MessagePack data loop while(unp.next(result)) { msgpack::object obj(result.get()); } } The size may decided by receive performance, transmit layer's protocol and so on. unp has at least try_read_size buffer on this point. input is a kind of I/O library object. read message to msgpack::unpacker's internal buffer directly. notify msgpack::unpacker actual consumed size.
  • 15. Stream Deserialization 2015/5/14 15Copyright OGIS-RI 2015 std::size_t const try_read_size = 100; msgpack::unpacker unp; while (/* block until input becomes readable */) { unp.reserve_buffer(try_read_size); std::size_t actual_read_size = input.readsome( unp.buffer(), try_read_size); unp.buffer_consumed(actual_read_size); msgpack::unpacked result; // MessagePack data loop while(unp.next(result)) { msgpack::object obj(result.get()); } } The size may decided by receive performance, transmit layer's protocol and so on. unp has at least try_read_size buffer on this point. input is a kind of I/O library object. read message to msgpack::unpacker's internal buffer directly. notify msgpack::unpacker actual consumed size. Use obj. convert to C++ types All complete msgpack message is processed at this point, then continue to read addtional message.
  • 16. Zero-Copy Deserialization 2015/5/14 16Copyright OGIS-RI 2015 unpacker buffer int string bin header payload header payload array client memory msgpack memory
  • 17. Zero copy deserialization 2015/5/14 17Copyright OGIS-RI 2015 zone chunk_list finalizer_array object (array) object (int) object (string) object (bin) via.array.ptr chunk unpacker buffer int string bin header payload header payload via.str.ptr via.bin.ptr array (msgpack format) client memory msgpack memory managed using reference counter unpacked copy or reference is selectable
  • 18. Zero copy deserialization 2015/5/14 18Copyright OGIS-RI 2015 zone chunk_list finalizer_array object (array) object (int) object (string) object (bin) via.array.ptr chunk unpacker buffer int string bin header payload header payload via.str.ptr via.bin.ptr array (msgpack format) client memory msgpack memory managed using reference counter unpacked convert Convert to any types that adapts MessagePack std::tuple<int, boost::string_ref, std::vector<char>> copyref copy or reference is selectable
  • 19. MessagePack Adaptors 2015/5/14 19Copyright OGIS-RI 2015 https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_adaptor C++ type msgpack::object type bool bool char* str std::deque array char positive/negative integer signed ints *1 positive/negative integer unsigned ints *2 positive integer std::list array std::map array std::pair array std::set array std::string str std::vector array std::vector<char> bin *1 signed ints signed char, signed short, signed int, signed long, signed long long *2 unsigned ints unsigned char, unsigned short, unsigned int, signed long, signed long long C++11 type msgpack:: object type std::array array std::array<char> bin std::forward_list array std::tuple array std::array array std::unordered_map array std::unordered_set array boost type msgpack:: object type boost::optional<T> T boost::string_ref str
  • 20. MessagePack Adaptors 2015/5/14 20Copyright OGIS-RI 2015 https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_adaptor #include <msgpack.hpp> struct your_class : base1, base2 { int a; std::string b; // You can choose any order. // It is represented to the msgpack array elements order. MSGPACK_DEFINE(a, b, MSGPACK_BASE(base1), MSGPACK_BASE(base2)); };
  • 21. • If you have questions, feel free to contact me :) • Takatoshi Kondo – redboltz@gmail.com – twitter: redboltz • Resources – MessagePack • http://msgpack.org/ – msgpack-c • https://github.com/msgpack/msgpack-c – msgpack-c Documents • https://github.com/msgpack/msgpack-c/wiki – msgpack-c stream unpack algorithm • A little old but concept is the same • http://www.slideshare.net/taka111/msgpackc 2015/5/14 Copyright OGIS-RI 2015 21 Thank you
  • 23. 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 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 0xcf2015/5/14 Copyright OGIS-RI 2015 23 MessagePack Formats https://github.com/msgpack/msgpack/blob/master/spec.md Format name first byte (in binary) first byte (in hex) int 8 11010000 0xd0 int 16 11010001 0xd1 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 array 32 11011101 0xdd map 16 11011110 0xde map 32 11011111 0xdf negative fixint 111xxxxx 0xe0 - 0xff
  • 24. 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 2015/5/14 Copyright OGIS-RI 2015 24 MessagePack Formats https://github.com/msgpack/msgpack/blob/master/spec.md
  • 25. 2015/5/14 Copyright OGIS-RI 2015 25 MessagePack Format https://github.com/msgpack/msgpack/blob/master/spec.md#int-format-family
  • 26. 2015/5/14 Copyright OGIS-RI 2015 26 MessagepPack format
  • 27. What is MessagePack? 2015/5/14 Copyright OGIS-RI 2015 27