This repo is a MicroPython implementation of the MessagePack protocol. Of the
various options for serialising data,
ujson and MessagePack are arguably the easiest to use. While
ujson produces human-readable data, MessagePack produces binary
bytes data, achieving substantial packing in the process. It has the following features in common with
ujson:
- Ease of use: unlike Protocol Buffers no schema is required.
- The data structure can change dynamically (unlike many binary schemes).
These features go beyond
ujson:
- Data packing comparable to other binary schemes.
- Ease of extension. The repo includes a module which extends support to tuple, set and complex types. It can readily be extended to support other native and library types.
- A class decorator enables user classes to be written so that instances can packed and unpacked in exactly the same way as native types.
- The module has support for asynchronous decoding of data which arrives on a slow or sporadic interface such as a UART or a socket.
The principal drawback is that the module uses some RAM. I have gone to some lengths to minimise this. In the absence of any frozen bytecode, overhead in a typical application on a Pyboard is on the order of 12KiB.