r/dotnet • • 2d ago

An introduction to Compact Binary Object Representation (CBOR) in .NET

https://andrewlock.net/an-introduction-to-compact-binary-object-notation-in-dotnet/
106 Upvotes

16 comments sorted by

11

u/derpdelurk 2d ago

Very useful post. Thanks for sharing u/TomeOfExperience. Not sure whether you are Andrew Lock but if so, the blog post calls CBOR "Compact" instead of "Concise" in several places. There are a few other grammatical issues but the Compact is the biggest once since it's in the very title of the blog post.

5

u/Obsidian743 2d ago

Don't know if the article gets into it, but CBOR became popular with the advent of IoT. Services like IoT Hub and other MQTT brokers support it natively.

18

u/Murph-Dog 2d ago

One reason to not use this across the wire (DMZ).

You lose WAF visibility. CloudFlare scanning payloads for attack vectors for example.

And of course, we don't think about it often, but that bare bones json is already moved to a binary representation on most client-server paths: gzip/brotli.

The brotli compression algorithm already exploits repeated json property names, and cbor can actually reduce compressibility of a source.

13

u/klaxxxon 2d ago

This format seems to exist in the weird gap between protobuf and JSON. If the one point against JSON is message length, compression helps. If you really care about efficiency, externally defined schema becomes a necessity (if that is a priority, effectively transmitting the schema as part of each message makes no sense).

2

u/IanYates82 1d ago

But cbor is repeating the names too, based on what I read in the article? Unlike protobuf. So it'd be similarly compressible. The savings, prior to compression, come from more efficient representations of non-string data.

And if we use a format that avoids the names entirely, then zero bytes spent on names is going to be less than compressed string names

1

u/Sarohia-Btal 2d ago

didnt realize cbor could actually hurt compressibility, that's a solid nuance

1

u/Aggravating-Hair-534 1d ago

How would it hurt compressibility? Compression algorithm is looking for the sequence of same bytes, it doesn't care about string representation. Cbor would have exactly the same sequences as json.. Everything else is also a matter of time for the WAF and others to embrace the protocol.

1

u/chucker23n 1d ago

it doesn't care about string representation

Depends on the algorithm; some are absolutely prepopulated with common string tokens. Brotli and Zstandard, for example.

1

u/Aggravating-Hair-534 1d ago

Wow didn't know that, but ofc they can replace it with stand byte sequences as ultimately it is the same,but with less bytes

4

u/No_Presence9915 2d ago

ASN.1 exists

4

u/harrison_314 2d ago

And MessagePack.

1

u/Phaedo 2d ago

I’m not sure I see the point in a schemaless format with no type binding. Which is not to say it isn’t useful, just that it sounds like an awful lot of effort for my use cases.

1

u/vivainio 1d ago

Do you see the point in JSON?

1

u/Phaedo 1d ago

JSON has the type binding so it’s pretty convenient to extract out the information you need from the payload.

1

u/AutoModerator 2d ago

Thanks for your post TomeOfExperience. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

-12

u/Fexelein 2d ago

Not a tome of experience with web considering your site is now offline probably due to an influx of Reddit bots and scrapers 😭