CBOR
CBOR copied to clipboard
how to encode binary data that is incidentally valid UTF-8?
cbor.encode{a='\x66\xc3\xb9'}
encodes as:
A1 # map(1)
61 # text(1)
61 # "a"
63 # text(3)
66C3B9 # "f\xC3\xB9"
however the 3 bytes '\x66\xc3\xb9' are meant as bytes(3) (0x43), not text(3) (0x63).
Is there a way to force bytes for a particular field? I mean without resorting to a low-level encoding such as:
enc = cbor.TYPE.MAP(3)
.. cbor.encode"a" .. cbor.TYPE.BIN('\x66\xc3\xb9')
Also, I can imagine if the library has to guess wether a Lua string is text or bytes, it has to scan the string, so telling what it is upfront could also save some CPU time.