Msgpack

What it is (blurb)

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.

msgpack

Well, personally, I don't like to have pre-processors in my code base that create serialization formats. Takatoshi Kondo has solved that problem by letting the compiler do, with some assistance from you.

I.e. you can serialize most data structures from STL as they are, including tuples:

void tuple() {
    std::tuple<bool, std::string, int> t(true, "ABC", 42);
    std::stringstream ss;
    msgpack::pack(ss, t);
 
    auto und = msgpack::unpack(ss.str().data(), ss.str().size());
    auto obj = und.get();
    assert(obj.as<decltype(t)>() == t);
}

If you have custom structs/classes, then you need to tell msgpack on how to serialize / deserialize.

The parser is written in a way that you can relatively easily stream in data from the network, and fetch unpacked entities from it. Also, it can greatly be used in conjunction with Niels Lohmann's json class, linked in here for reference.

What I like

What I don't like

Roman's Rating: 4.0/5

Information