MessagePack
Encyclopedia
MessagePack is a computer
data interchange format. It is a binary form for representing simple data structure
like arrays and associative array
s. MessagePack aims to be as compact and simple as possible. The official implementation is available in a variety of languages such as C
, C++
, C#, D
, Erlang, Go
, Haskell
, Java
, JavaScript
, Lua, OCaml, Perl
, PHP
, Python
, Ruby
, and Scala.
format. They consist of the following element types:
, but imposes (reasonable) limitations on array and integer sizes. On the other hand, it allows binary data and non UTF-8 encoded strings.
Compared to BSON
, MessagePack is more space-efficient. For example, BSON requires zero-byte terminators at the end of all strings and inserts string indexes for list elements, while MessagePack doesn't. Also, MessagePack allows more compact representation of small integers and short lists and associative arrays.
Protocol buffers
format aims to be compact and is on par with MessagePack. However, while JSON and MessagePack aim to serialize arbitrary data structures, Protocol buffers is strongly typed and requires a schema which defines data types that compose the structure. Protocol buffers compiler creates boilerplate code in target language to facilitate integration of serialization into the application code; MessagePack returns only dynamically-typed data structure and provides no automatic structure checks.
Computer
A computer is a programmable machine designed to sequentially and automatically carry out a sequence of arithmetic or logical operations. The particular sequence of operations can be changed readily, allowing the computer to solve more than one kind of problem...
data interchange format. It is a binary form for representing simple data structure
Data structure
In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...
like arrays and associative array
Associative array
In computer science, an associative array is an abstract data type composed of a collection of pairs, such that each possible key appears at most once in the collection....
s. MessagePack aims to be as compact and simple as possible. The official implementation is available in a variety of languages such as C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, C#, D
D (programming language)
The D programming language is an object-oriented, imperative, multi-paradigm, system programming language created by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is mainly influenced by that language, it is not a variant of C++...
, Erlang, Go
Go (programming language)
Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being...
, Haskell
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...
, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
, Lua, OCaml, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
, PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
, Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...
, and Scala.
Data types and syntax
Data structures processed by MessagePack loosely correspond to those used in JSONJSON
JSON , or JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects...
format. They consist of the following element types:
- null
- booleanBoolean datatypeIn computer science, the Boolean or logical data type is a data type, having two values , intended to represent the truth values of logic and Boolean algebra...
(true
andfalse
) - integer (up to 64 bits signed or unsigned)
- floating point numbers (IEEE single/double precision)
- byte array (string or binary data)
- list ("array")
- associative array ("map")
Comparison to other formats
MessagePack is more compact than JSONChicken
The chicken is a domesticated fowl, a subspecies of the Red Junglefowl. As one of the most common and widespread domestic animals, and with a population of more than 24 billion in 2003, there are more chickens in the world than any other species of bird...
, but imposes (reasonable) limitations on array and integer sizes. On the other hand, it allows binary data and non UTF-8 encoded strings.
Compared to BSON
BSON
BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures and associative arrays...
, MessagePack is more space-efficient. For example, BSON requires zero-byte terminators at the end of all strings and inserts string indexes for list elements, while MessagePack doesn't. Also, MessagePack allows more compact representation of small integers and short lists and associative arrays.
Protocol buffers
Protocol Buffers
Protocol Buffers are a serialization format with an interface description language developed by Google. The original Google implementation for C++, Java and Python is available under a free software, open source license....
format aims to be compact and is on par with MessagePack. However, while JSON and MessagePack aim to serialize arbitrary data structures, Protocol buffers is strongly typed and requires a schema which defines data types that compose the structure. Protocol buffers compiler creates boilerplate code in target language to facilitate integration of serialization into the application code; MessagePack returns only dynamically-typed data structure and provides no automatic structure checks.