Skip to content

Tag binary values in cbor if set - #2244

Merged
nlohmann merged 2 commits into
nlohmann:developfrom
matthewbauer:tag-cbor
Jul 17, 2020
Merged

nlohmann merged 2 commits into
nlohmann:developfrom
matthewbauer:tag-cbor

Conversation

@matthewbauer

@matthewbauer matthewbauer commented Jul 6, 2020

Copy link
Copy Markdown
Contributor

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.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header file single_include/nlohmann/json.hpp. The whole process is described here.

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.
@matthewbauer
matthewbauer requested a review from nlohmann as a code owner July 6, 2020 20:33
matthewbauer added a commit to obsidiansystems/nix that referenced this pull request Jul 6, 2020

@nlohmann nlohmann left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread include/nlohmann/detail/output/binary_writer.hpp
@matthewbauer

Copy link
Copy Markdown
Contributor Author

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.

@coveralls

coveralls commented Jul 6, 2020

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling dd08f77 on matthewbauer:tag-cbor into efcc826 on nlohmann:develop.

@Ericson2314

Copy link
Copy Markdown

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.

@nlohmann

nlohmann commented Jul 9, 2020

Copy link
Copy Markdown
Owner

As the library does not support tags in the moment (#1968), it would fail to parse its own output, or am I mistaken?

@matthewbauer

Copy link
Copy Markdown
Contributor Author

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.

@Ericson2314

Copy link
Copy Markdown

Yes this change just attempts serialization for now, as a stop-gap which is good enough for our purposes.

@nlohmann

Copy link
Copy Markdown
Owner

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.

@Ericson2314

Copy link
Copy Markdown

Oh! We'll if you are fine doing it after is there anything more this PR needs?

@nlohmann

nlohmann commented Jul 15, 2020

Copy link
Copy Markdown
Owner

@Ericson2314 @matthewbauer It would be great if you could have a look at #2273.

@nlohmann nlohmann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann nlohmann self-assigned this Jul 17, 2020
@nlohmann nlohmann added this to the Release 3.8.1 milestone Jul 17, 2020
@nlohmann
nlohmann merged commit a10d486 into nlohmann:develop Jul 17, 2020
@nlohmann

Copy link
Copy Markdown
Owner

Thanks!

@nlohmann

Copy link
Copy Markdown
Owner

🔖 Release item

This issue/PR will be part of the next release of the library. This template helps preparing the release notes.

Type

  • ✨ New Feature
  • 🐛 Bug Fix
  • ⚡️ Improvement
  • 🔨 Further Change
  • 🔥 Deprecated function

Description


@Ericson2314

Copy link
Copy Markdown

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants