Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBOR string #757

Closed
arnaudbrejeon opened this issue Sep 28, 2017 · 4 comments
Closed

CBOR string #757

arnaudbrejeon opened this issue Sep 28, 2017 · 4 comments
Assignees
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@arnaudbrejeon
Copy link

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?

@nlohmann
Copy link
Owner

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 :-)

@azadkuh
Copy link

azadkuh commented Sep 30, 2017

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.

@stale
Copy link

stale bot commented Oct 30, 2017

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.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 30, 2017
@stale stale bot closed this as completed Nov 6, 2017
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated labels Apr 16, 2020
@nlohmann nlohmann self-assigned this Apr 16, 2020
@nlohmann nlohmann added this to the Release 3.8.0 milestone Apr 16, 2020
@nlohmann
Copy link
Owner

Binary strings are now there, see #1662.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants