Share

The MsgPack format

MsgPack is an interesting format, similar to JSON, but keeping types in their original binary format instead of converting them to text and parsing them again.

The great disadvantage of this is that a message is not human-readable. One cannot just view the contents in any text editor and debug a message by looking where some piece of data might be missing or otherwise erroneous.

For me, the format is still worthwhile since I want to send messages between a NetDuino, an iOS device, Apple Watch and a PC. The NetDuino in particular should benefit from just sending and receiving raw binary data without the need of a Json Parser.

One thing that could go wrong is endianness. I think that all the devices I want to use are little endian, but I hope all existing libs will handle that correctly for the devices I want to use.

Limitations

The format is optimized for easy implementation. The basic types are defined but it is not possible to explicitly define complex (compound) types or structures. Also arrays or key-value pairs (maps) cannot have their types defined up-front, but each value contained within them needs to specify its type separately.

One feature is that integers should be compacted by choosing the smallest type of integer they will fit in. I’m not convinced that the overhead of compacting and converting weighs up against the message size reduction, especially with the extra type byte needed for each entry in an array.

Plane crazy

One aspect of the format is simply useless. The format already specifies byte arrays that can hold absolutely anything. Then a new type called Ext (extension) has been added which is basically an byte array with a single preceding byte that should specify an application-specific type.

The Ext type adds absolutely nothing for cross-platform compatibility or abstraction. Why would we not use an integer and a byte array on application level instead of using an explicit compound Byte+ByteArry type?

Worthwhile nonetheless

Despite my criticism, I’m still going to give the format a shot, especially because there are libs out there for almost all the platforms I need.

Update:

I have overcome the black box problem by creating my own MsgPack Explorer tool.