Challenge accepted.
CBOR diagnostic notation is quite versatile, you just have to tell cbor2diag.rb
what you want.
cbor2diag.rb -t: bytes_as_text, i.e., use text form for bytes if possible.
$ printf cbor | cbor2diag.rb -t
"bor"
$ printf CBOR | cbor2diag.rb -t
‘BOR'
Oh, and, BTW:
cbor2diag.rb -e: try_decode_embedded, i.e., try embedded CBOR.
$ printf CBOR | cbor2diag.rb -te
<< 'OR' >>
(Do a “gem update” to get cbor2diag.rb version 0.5.9 for -t.)
Back to the magic number issue:
For CBOR data items, I prefer registering a tag and prefixing with that head
(*) over prefixing with an array head and a string. See, we have a magic
number registry built right into CBOR...
For CBOR sequences, obviously prefixing the sequence with a CBOR-encoded (text
or byte) string sounds quite good. Making that optional (to save bytes when
you don’t need it) requires that the sequence otherwise cannot start with that
kind of string.
Grüße, Carsten
(*) E.g., tag 15309736 for the RAINS protocol:
>> CBOR::Tagged.new(15309736, "oooooo").to_cbor
=> "\xDA\x00\xE9\x9B\xA8foooooo"
>> CBOR::Tagged.new(15309736,
>> "oooooo").to_cbor[2..].force_encoding(Encoding::UTF_8)
=> "雨foooooo"
Oh, for those who don’t speak Chinese:
$ trans 雨
雨
(Yǔ)
rain
Definitions of 雨
[ 简体中文 -> English ]
noun
rain
雨, 雨天, 霅
adjective
rainy
雨, 多雨的
雨
rain
> On 2021-01-21, at 03:19, Josef 'Jeff' Sipek <[email protected]> wrote:
>
> On Wed, Jan 20, 2021 at 21:11:49 -0500, Michael Richardson wrote:
>>
>> Josef 'Jeff' Sipek <[email protected]> wrote:
>>> Recently, I was thinking about the fun fact that the Unicode string
>>> "bor" and the byte string "BOR" end up getting encoded as "cbor" and
>>> "CBOR", respectively.
>>
>> obiwan-[work/richardson/cbor-file-magic](2.6.6) mcr 10355 %echo -n cbor |
>> cbor2diag.rb
>> "bor"
>>
>> obiwan-[work/richardson/cbor-file-magic](2.6.6) mcr 10356 %echo -n CBOR |
>> cbor2diag.rb
>> h'424F52'
>
> Which is hex for 'B' 'O' 'R'. :)
>
> I'm guessing cbor2diag.rb sees the raw data and hexdumps it to be helpful.
> Here's what python has to say:
>
> In [1]: import cbor
>
> In [2]: cbor.loads(b'cbor')
> Out[2]: 'bor'
>
> In [3]: cbor.loads(b'CBOR')
> Out[3]: b'BOR'
>
> Note the difference in return type - the first is unicode string the second
> is a byte string.
>
> Jeff.
>
> _______________________________________________
> COSE mailing list
> [email protected]
> https://www.ietf.org/mailman/listinfo/cose
_______________________________________________
COSE mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/cose