6 ms·
CBOR – Concise Binary Object Representation
- mantap 7y agoI tried CBOR but honestly the JS libraries available are not yet of production quality and I had to abandon it and go back to messagepack.
- schoen 7y agoI'm curious how this compares to * Cap'n Proto * ASN.1 * gzip-compressed JSON in various ways. (I don't know much about progress in serialization methods.)
- mantap 7y agoThe primary advantage of a schemaless binary encoding such as CBOR is that it lets you encode binary data directly instead of using a double encoding of base64 in JSON.
- thayne 7y agoCap'n'proto and ASN.1 require a schema. Gzip compression means the content has to be decrypted into json and then parsed into a native representation, which probably requires more memory and cpu than cbor deserialization.
- edoceo 7y agoNot decrypted. Decoded or decompressed.
- thayne 7y agoOops, I meant decompressed.
- Matthias247 7y agoThat’s right. In addition: CBOR can’t automatically compress field names, since those are strings which need to get fully serialized. gzip can compress them too, so it has a chance to trim the size of data further down in exchange for the additional cost of a 2nd encoding. Cap‘N‘Proto, protobuf and co can replace field names by IDs as indicated through Schemas and will thereby most space efficient in general.
- userbinator 7y agoTechnically, you can use ASN.1 in a "schemaless" mode, but it's not very common.
- ehsankia 7y agoFor what it's worth, I tested it on this gigantic json file I have in this app (yes I should probably not be using JSON here). Raw json is 90mb, cbor was 80mb. json+gzip takes it to 30mb and cbor+gzip was 31mb. That being said, the schema has a lot of repeated keys, so that's why gzip helps a lot.
- clhodapp 7y agoIt seems like repeated keys would be super-easy to make more efficient in a binary format: You could write each key in stringish form once (the first time it was seen) and then refer to it with a numeric seen-key reference from there on.
- Matthias247 7y agoIf you want it to be infinitely streaming compatible (which CBOR is) it raises another question: For how long are identifiers valid, and do they get invalidated or updates at some point of time. The header compression in HTTP2 solves such a problem, but also introduces quite a bit of additional complexity
- clhodapp 7y agoRight. There is definitely a tradeoff between requiring retention of the identifiers, which requires keeping more state, and re-specifying them, which requires sending more data. There are definitely more sophisticated ways to handle this (see: your HTTP2 header example, which I think even includes value caching), but an easy way to chose a point on that tradeoff spectrum is to simply keep a fixed-sized ringbuffer and retain, say, the last 256 keys.
- ehsankia 7y agoAs mentioned above, for something like to work, you need pre-defined schema, such as protobuf, which yes I know is what I should be using :)
- clhodapp 7y ago
- kbumsik 7y ago> gzip-compressed JSON CBOR is not about compression to make it smaller, but for machine readability. For example for integers CBOR uses binary representation so that machines can read it directly without converting from string to integer in JSON.
- rocqua 7y agoExcept that CBOR uses network order, so you cannot just interpret the bytes as an integer.
- StreamBright 7y agoParsing JSON is probably an order of magnitude more inefficient than working with any binary message formats in terms of speed and energy.
- garmaine 7y ago...why? That's not at all obvious.
- StreamBright 7y agoBecause accessing fields in a binary format is a seek() while in a text format it is much more complicated. Try to build a mental model what is required to parse text based formats. You can have a look to results of performance testing involving these binary message formats vs json. http://zderadicka.eu/comparison-of-json-like-serializations-json-vs-ubjson-vs-messagepack-vs-cbor/ http://zderadicka.eu/comparison-of-json-like-serializations-... https://github.com/ludocode/schemaless-benchmarks#speed---desktop-pc https://github.com/ludocode/schemaless-benchmarks#speed---de... https://eng.uber.com/trip-data-squeeze/ https://eng.uber.com/trip-data-squeeze/ http://ugorji.net/blog/benchmarking-serialization-in-go http://ugorji.net/blog/benchmarking-serialization-in-go
- garmaine 7y agoSorry, I read "order of magnitude more efficient" and was confused.
- StreamBright 7y agoIf you take into consideration the sum of energy it takes to process an average daily dataset, then yes I think it will be an order of magnitude more efficient (in terms of energy use).
- signa11 7y agotry parsing a tcp/udp header encoded in json vs as it ‘normally’ is. see if you can do it at line rate :o)
- stock_toaster 7y agoI've always enjoyed the bencode[1] and netstring/tnetstring[2] formats too. [1]: https://en.wikipedia.org/wiki/Bencode https://en.wikipedia.org/wiki/Bencode [2]: http://web.archive.org/web/20140701085126/http://tnetstrings.org/ http://web.archive.org/web/20140701085126/http://tnetstrings...
- Zamicol 7y agoCOSE, which uses CBOR, is the JOSE (commonly known by its subset JWT) of small binary messaging. https://tools.ietf.org/html/rfc8152 https://tools.ietf.org/html/rfc8152
- nmadden 7y agoIt is, although COSE is significantly different to JOSE in many ways.
- nlohmann 7y agoShameless self-plug: JSON for Modern C++ (https://github.com/nlohmann/json https://github.com/nlohmann/json) supports CBOR along MessagePack, UBJSON, and BSON, see https://github.com/nlohmann/json#binary-formats-bson-cbor-messagepack-and-ubjson https://github.com/nlohmann/json#binary-formats-bson-cbor-me....
- nneonneo 7y agoNeat. One little thing I gotta wonder about: was this name perchance a backronym for the author’s name Carsten Bormann (CBor)? Not that I’m complaining, but that does seem like an odd coincidence. Also, how does this compare to JSON binary serialization, such as BSON?
- starbugs 7y agoRegarding your first question, yes. Source: I have been a student at University of Bremen and attended some of his lectures (I remember at least one titled "Physikalisch-technische Grundlagen Digitaler Medien").
- throwaway3627 7y agoBINC, MsgPack, ...
- camgunz 7y agoCBOR is MessagePack. At least cbor-ruby started with the MessagePack sources. The story is that Carsten took MessagePack, wrote a standard and added some things he wanted, and called it something else. I wrote [1] a pretty comprehensive (and admittedly biased) critique of the CBOR standard years ago. [1] https://news.ycombinator.com/item?id=14072598 https://news.ycombinator.com/item?id=14072598 Disclaimer: I wrote and maintain a MessagePack implementation.
- PopeDotNinja 7y agoIn your opinion, what's the value of MessagePack? I worked with it when writing some Fluentd tools, and it was neat, but I didn't love it enough to switch from JSON on other projects. Maybe there's a killer feature I didn't know I need?
- alexchamberlain 7y agoIn recent benchmarks I ran for a project, the performance of MessagePack blew JSON out the water. Obviously, it may differ in your case, but generally, MessagePack is designed to be machine readable and easy to parse, so performance with generally be better. Message sizes are generally better too.
- Mordak 7y agoAt my work we recently went through a large exercise to decide on a common data storage format. The contenders were JSON, MessagePack, and Avro. MessagePack won because: - Msgpack serialization and deserialization is very fast in many languages - often 100x faster then JSON - Msgpack natively supports encoding binary data - Msgpack has type extensions, making it trivial to represent common types in an efficient way (eg. IPv4 address, timestamps) - Msgpack has good libraries available in many languages If you do not care about those things (no binary data, no need for extended types, not performance critical) then JSON is just fine.
- pdimitar 7y agoI'm curious why didn't you consider FlatBuffers as well.
- userbinator 7y agoIt is odd to read in the RFC section 1.1 this sentence, The format should use contemporary machine representations of data ...and then see in section 1.2, All multi-byte values are encoded in network byte order (that is, most significant byte first, also known as "big-endian") I know it's largely a choice of tradition, but it seems almost anachronistic to specify any new protocols as BE when LE is the overwhelming majority of machines today, and probably has been for at least the past two decades.
- kbumsik 7y agoIt it also weird that "network byte order" is considered as BE. Is there any advantage of BE when it is transferred over the network?
- garmaine 7y agoNo. In this context it simply means "network-standard." And the standard has always been big endian for network applications. Not because of any advantage, but simply because that was the standard.
- rhn_mk1 7y agoIf I remember correctly, BE helps in switching networks for routing packets. A packet would start with the big-endian destination address. If that address was hierarchical, i.e. most significant bytes signify the network (interface) it was in (like IP), then only a few of the first bits need to be processed in order to find which interface to direct the packet to. The transmission out therefore begins just after the few first bits are received. E.g. for a switch connected to networks A: 0xa, B: 0x1, C: 0x3, a only the first byte 0x1 of the packet destined to 0x1234 needs to be processed before forwarding, saving some time compared to LE, where the entire address 0x4321 would have to be processed to find out that it's at the 0x1 network.
- baybal2 7y agoRegisters on anything today will be way wider than few bytes, moreover on network hardware. The gate savings on doing endiannes specific circuits are close to zero in comparison to many many other things a typical logic block comes with today.
- kbumsik 7y agoFor someone saw CBOR, CBOR is kinda binary version of JSON, like MsgPack. CBOR is already mature as it is used in web browsers internally by a web standard [1] (and yes, Signed HTTP is in a controversy though...) Because it is pretty much optimized for machine readability and lightness, one of usage is microcontrollers for IoT, with CBOR + CoAP(kinda HTTP for IoT), although I wouldn't say it is common yet, since CoAP needs IPv6. [1]: https://wicg.github.io/webpackage/draft-yasskin-http-origin-signed-responses.html#cbor-representation https://wicg.github.io/webpackage/draft-yasskin-http-origin-...
- unmole 7y agoYou would probably reach for CoAP when your nodes are speaking 6LoWPAN but, there's nothing about CoAP that requires IPv6.
- magicalhippo 7y agoI recently wanted to use something JSON-RPC'ish for communication between host PC and my microcontroller. I looked into CBOR/MessagePack as well as UBJSON. I didn't find a CBOR/MessagePack nor UBJSON implementation that was microcontroller-friendly and easy to use. In the end I ended up just using plain JSON. Easy to debug as you can easily see what's on the wire, easy to implement, relatively small code size.
- kbumsik 7y agoMost CBOR implementations for MCUs tend to be a part of RTOSs, integrated and optimized for their own memory allocation libraries. But many of them are based on Intel's TinyCBOR: https://github.com/intel/tinycbor https://github.com/intel/tinycbor
- Rafert 7y agoI'd point towards WebAuthn[0] as a reason why browsers implement CBOR, since that's much more widely supported. [0]: https://www.w3.org/TR/webauthn-1/#dependencies https://www.w3.org/TR/webauthn-1/#dependencies
- dang 7y agoThread from 2016: https://news.ycombinator.com/item?id=10995726 https://news.ycombinator.com/item?id=10995726 2015: https://news.ycombinator.com/item?id=9597198 https://news.ycombinator.com/item?id=9597198 2013: https://news.ycombinator.com/item?id=6932089 https://news.ycombinator.com/item?id=6932089 2013: https://news.ycombinator.com/item?id=6632576 https://news.ycombinator.com/item?id=6632576 (the largest)
- eadan 7y agoA recent discussion here on Latacora's "How (not) to sign a JSON object" [0], had me thinking of CBOR. Unlike JSON, MsgPack, protobufs, BSON, or any other commonly used data interchange format that I'm aware of; CBOR has a canonical representation (although, with seeming ambiguity in float representation) [1]. Anyone have any thoughts on using canonical CBOR for object signing? Currently, I'm building a system with a content-addressable data store, and I'm particularly interested in data formats with a canonical form for this use-case. [0] https://news.ycombinator.com/item?id=20516489 https://news.ycombinator.com/item?id=20516489 [1] https://tools.ietf.org/html/rfc7049#section-3.9 https://tools.ietf.org/html/rfc7049#section-3.9
- dwaite 7y agoGenerally, there isn't an efficient object model for CBOR (three really troublesome features are the use of arbitrary CBOR structures as map keys, 64 bit unsigned negative numbers, and semantic tagging resulting in data being represented in an alternative form e.g. a BigDecimal type rather than a binary array). As a result, round-tripping through a CBOR implementation still may result in data structure changes. Depending on the type of change and any exploits in say the hashing algorithm, this could be a security issue. On the flip side, you can just tag a byte array as CBOR data, and sign it. Unlike JSON, you don't need to perform an encoding/escaping to make one document safe to embed into another document.
- blattimwind 7y agoYou generally don't need canonical representation.
- kstenerud 7y agoI've been working on a general purpose binary and text encoding format for some time now as a personal project. It supports time, decimal floats, binary blobs as first-class citizens, supports comments, and focuses on encoding the most commonly used values more compactly. The binary format [1] is almost done (I've come up with a more compact date representation that I'll be adding this weekend to replace smalltime in the C and go implementations), and the text format isn't far behind. I almost had a better floating point compression format, but it turned out to be too complicated, and only works well for decimal floating point, so I'll probably not use it in CBE. [1] https://github.com/kstenerud/concise-encoding/blob/master/cbe-specification.md https://github.com/kstenerud/concise-encoding/blob/master/cb...
- larodi 7y agothis been here for a while... including the website. question: is anyone actually/effectively using it in a commercial project?
- ktpsns 7y agoFun Fact: CBOR is both an acronym for the software as well as the initials of the author, Professor Carsten Bormann (https://www.informatik.uni-bremen.de/~cabo/ https://www.informatik.uni-bremen.de/~cabo/)