this post was submitted on 31 Aug 2024
2 points (100.0% liked)

The C Programming Language

32 readers
6 users here now

Everything related to the C programming language.

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 3 weeks ago* (last edited 3 weeks ago)

CBOR uses variable-sized length prefixes. Strings zero to 23 bytes long require just one byte of overhead, after that it becomes two bytes for strings up to length 255, and 3 bytes of overhead for strings up to 65535. Above that, it requires 5 bytes of overhead, which is probably enough for strings up to at least a few hundred GB, though I didn't test that far.

click to see how i empirically determined those numbers$ python -c 'import cbor; overhead=0; print({ length:overhead for length in range(65537) if overhead < (overhead:=len(cbor.dumps("a"*length))-length) })'

{0: 1, 24: 2, 256: 3, 65536: 5}