5 ms·
Protobufs/nanopb would be my go-to for minimal message size. If you want small code size, CBOR seems like a good bet: > The Concise Binary Object Representati
by liamdiprose 7y ago
Protobufs/nanopb would be my go-to for minimal message size.
If you want small code size, CBOR seems like a good bet:
> The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. [1]
This [2] C-implementation fits in under 1KiB of ARM code.
[1]: https://cbor.io/ https://cbor.io/
[2]: https://github.com/cabo/cn-cbor https://github.com/cabo/cn-cbor
- RantyDave 7y agoI, too, love cbor. https://github.com/RantyDave/cppbor https://github.com/RantyDave/cppbor
- jopsen 7y agoCBOR is also used on WebAuthn, usage in a web spec means to me that someone smart considered it a sane choice -- and more importantly that the format is here to stay.
- SlowRobotAhead 7y agoCBOR’s RFC: https://tools.ietf.org/html/rfc7049 https://tools.ietf.org/html/rfc7049 And Amazon has picked it up as a first class citizen in some of their IoT Core features. It’s definitely here to stay.
- kbumsik 7y agoIt's great CBOR is accepted in wider area, but I am personally curious why WebAuthn choose CBOR instead of JSON. WebAuthn is a web browser feature, and why W3C would introduce a new data exchange format in their specs? Maybe WebAuthn needed a binary data type?
- jopsen 7y agoI'm guessing a binary format is nice when interacting with a device.. Anybody know if (and why) U2F uses CBOR?
- kbumsik 7y agoYes. CBOR is designed for IoT especially in mind.
- magicalhippo 7y agoAh yes I looked at CBOR too, but I dismissed it for reasons I can't recall right now. Will have to take another look.
- SlowRobotAhead 7y agoThat’s strange because CBOR is almost literally msgpack that got an RFC and has extensions. I cant remember what MsgPack does for online streaming and indefinite lengths. They’re extremely similar.
- magicalhippo 7y agoLooked at it again, seems memory management is a bit of an issue, it supports memory allocation callback but not just handing it a buffer to work with (though I guess allocation should be predictable). Also I don't know how they got "code sizes appreciably under 1 KiB". On my STM32F1 release mode with -Os it adds about 12kB. But yeah, maybe I should reevaluate CBOR.
- SlowRobotAhead 7y agoFor reference, I’m using TimyCBOR because it’s include with Amazon FreeRTOS. You’re on your own for malloc, which for me is great because FreeRTOS Heap4 management is quite good. So I malloc an object I’m decoding into and parse away. There are two options parsing arrays and strings/bytestrings and I just chose the option where I specify the pointer to use, vs them using normal malloc then free() later. I really like this setup. I made a deinit(bad_message) that works anywhere it failed (parse, validate, eval, etc), goes through and looks for pointers that I previously would have malloc’ed. There is another popular library but I forget what it’s called.
- kragen 7y agoCBOR was originally part of the MsgPack project, by the way, before its designer forked it and renamed it after himself.