Closed arnaudbrejeon closed 6 years ago
This is currently not supported, as we only support UTF-8 as encoding. I we would accept byte strings, we would also need to support additional encodings.
While this would just be a programming exercise (it seems that only base64url, base64, base16, and CBOR are mentioned in RFC 7049), it is currently not a priority for this library. However, PRs are always welcome :-)
ATM, it's possible to misuse the json::to_cbor()
/ json::to_msgpack()
as:
const std::string binary = load_some_binary_like_a_jpeg_file();
json src = {"data", binary};
const auto bin_serialization = json::to_cbor(src); // json::to_msgpack()
auto dest = json::from_cbor(bin_serialization); // json::from_msgpack()
// now: dest["data"].get<std::string>() == binary
// if: serialization/deserialization by this library
it may sound weird, but as long as all modern std:string
implementations can handle binary data as well as utf8 text, what if to_cbor()/from_cbor()
consider all strings as byte strings (raw/binary)?
then both binary/text are covered in msgpack
/cbor
serialization.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Binary strings are now there, see #1662.
I received some CBOR files that contain strings (major type 2) and not UTF-8 strings(major type 3). It looks like parsing fails. Is it on purpose?