Closed janvda closed 4 years ago
The problem is that cbor in string format (see point 2 above) is not containing all relevant information (bits). So there is no issue with this repository.
I fixed it by directly converting the cbor buffer to hex format (using buffer.toString('hex')
).
This resulted in following string:
a26970726f746563746564a36376657262763163616c67646e6f6e65636961741a5f1716f3677061796c6f6164a46b6465766963655f6e616d657161633a38373a61333a30613a32643a31626b6465766963655f7479706573444953434f2d4c34373556472d494f543031416b696e74657276616c5f6d730a6773656e736f727383a2646e616d65646163635865756e697473646d2f7332a2646e616d65646163635965756e697473646d2f7332a2646e616d65646163635a65756e697473646d2f7332
which is correctly converted back as specified in step 4 above.
There's really no such thing as "CBOR in string format", as you found out. CBOR is bytes, not a valid string in any Unicode encoding.
When encoding a json string with multiple levels using node-red which uses janvda/node-red-contrib-cbor (which is based on hildjj/node-cbor version v5.0.2) I don't get proper output when I test this as follows:
An example of the problem
The input json string:
the json string converted to cbor (represented in string format)
cbor this time converted to hex format (using https://codebeautify.org/string-hex-converter)
cbor converted back gives (http://cbor.me/)
and reports following error:
71 unused bytes after the end of the data item