-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Tag binary values in cbor if set #2244
Conversation
CBOR has tags, which work similarly to "subtype"s: https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml Unsure if this makes sense. Note that the subtype must just be one byte wide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one question (see comment). Furthermore, test cases are missing. Maybe with some examples, I understand the goal of this PR.
Note this only works for encoding subtypes, not decoding. Decoding is hard because the tag can come for any data type - not just binary. So we would need to add more state to handle it properly. |
For context, here is an issue from a Rust library about this exact issue pyfisch/cbor#157 . Serde also wasn't originally made with CBOR tags in mind, so again the sticking point is derialization without polluting everything else with CBOR-specific concepts. |
As the library does not support tags in the moment (#1968), it would fail to parse its own output, or am I mistaken? |
Yes - you wouldn't be able to parse a cbor with a subtype since it would have that tag. |
Yes this change just attempts serialization for now, as a stop-gap which is good enough for our purposes. |
Hm. Then I think it would be helpful to also adjust the parser to skip tags, because otherwise roundtripping would not work any more. This does not need to be done in this PR, of course, but I'm still re-opening #1968. |
Oh! We'll if you are fine doing it after is there anything more this PR needs? |
@Ericson2314 @matthewbauer It would be great if you could have a look at #2273. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thanks! |
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
Thank you! |
CBOR has tags, which work similarly to "subtype"s:
https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
Unsure if this makes sense. Note that the subtype must just be one
byte wide.
Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filesingle_include/nlohmann/json.hpp
. The whole process is described here.