Page 1 of 1

JSON alternative with packed data: MessagePack

Posted: Sun Aug 01, 2021 12:55 pm
by pythoncoder
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.

Re: JSON alternative with packed data: MessagePack

Posted: Wed Aug 04, 2021 4:42 am
by jimmo
Thanks Peter, this looks very useful!!