JSON alternative with packed data: MessagePack

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

JSON alternative with packed data: MessagePack

Post by pythoncoder » Sun Aug 01, 2021 12:55 pm

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.
Peter Hinch
Index to my micropython libraries.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: JSON alternative with packed data: MessagePack

Post by jimmo » Wed Aug 04, 2021 4:42 am

Thanks Peter, this looks very useful!!

Post Reply