CBOR (Was: My experiences with Rust)

From: Vadim Goncharov <vadimnuclight_at_gmail.com>
Date: Mon, 25 Aug 2025 17:34:23 UTC
On Fri, 22 Aug 2025 21:33:55 +0000
"Poul-Henning Kamp" <phk@phk.freebsd.dk> wrote:

> --------
> Vadim Goncharov writes:
> 
> 
> > And nobody needs to open "format" *directly* in text editor   
> 
> Yes, people actually do, and the ability to do things like that is

Of course they don't. Nobody opens .tar in text editor or pipes it to sed/awk,
there is tar(1) for it - and that was so in 1970-s already. Nobody opens .pcap
in text editor - there is tcpdump(1) for this, from late 1980-s.
Nobody opens object file in text editor - there is nm(1) and friends for it.
Nobody opens /var/db/locate.database in text editor - there is locate(1) and
it's friend to update DB for it.
Nobody opens utmp in text editor - there are last(1), who(1) and so on.
Nobody opens ktrace output in text editor - there is kdump for it.
Oh, and nobody opens files in /proc as text when there is sysctl(8) for it!

There are much more examples you can find in {/usr,}/{s,}bin (e.g.
crypto-related), but finally, the most matching for this discussion:

 - nobody opens /var/log/all.log.0.bz2 in text editor - just another filter
   in pipe is added!

Because in context CBOR could be viewed just as a "compression" format
for JSON.

$ gem install edn-abnf
$ perl -MCBOR::XS -E '$c=CBOR::XS->new->text_strings; $d=["foobarbaz1",
  "foobrbaz2foobarquux", {"foo"=>"bar"}, 'bar', "baz"];
  print $c->encode($d)'  > test.cbor
$ hexdump -C test.cbor                                                                
00000000  85 6a 66 6f 6f 62 61 72  62 61 7a 31 73 66 6f 6f  |.jfoobarbaz1sfoo|
00000010  62 72 62 61 7a 32 66 6f  6f 62 61 72 71 75 75 78  |brbaz2foobarquux|
00000020  a1 63 66 6f 6f 63 62 61  72 63 62 61 72 63 62 61  |.cfoocbarcbarcba|
00000030  7a                                                |z|
$ cbor2diag.rb < test.cbor
["foobarbaz1", "foobrbaz2foobarquux", {"foo": "bar"}, "bar", "baz"]

Yeah, it's *that* simple!

And libcbor is already in -stable for years.

> why UNIX has beaten out all the crappy systems where you needed 
> 19 different programs to see 15 different binary data formats.

Unix was utterly shit at early 1980-s, and was taken due to despair: the real
viable alterntive - mainframes - were very, VERY expensive. It took decades to
fix all flaws - e.g. panics when pulling out diskette then USB flash. Of
course real causes had nothing to do with text vs binary formats, especially
noting above there were many binary ones in Unix.

-- 
WBR, @nuclight