-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Add binary type support to all binary file formats, as well as an internally represented binary type #1662
Conversation
Thank you very much! On first browsing, this looks all very good! Unfortunately, I won't be able to have a deeper look at this until next week. |
That's totally understandable. Clearly I'm OK with things taking a long while. ;) I'll patiently await your feedback before continuing. |
If you don't have anything specific to critique about my general approach, then I'll keep at it for now. Let me know though. |
Please go ahead! The approach appears sound and has great potential! |
Does anyone have any good test cases for the various binary types? I'd rather not haaaaave to make them all by hand if I don't need to. ;) |
5b12f18
to
b1c8bdd
Compare
I can add examples. Meanwhile, the build is red. It seems that you are using macros like |
Do you have an idea why the tests are failing? |
Yeah, sorry I buried the reason in a commit message. When I make the json it calls the json array constructor instead of the json binary constructor, because the template match is better somehow. I was contemplating a solution, but I think the best course of action is to simply remove the unadorned binary ctor so you can't accidentally call it, and then make static functions that return a constructed json of a specific type. Something like |
I have a few cbor data tests for binary. But no messagepack, ubjson, or bson. Soliciting contributions to make sure my code doesn't suck. ;) |
Thanks for the effort! I will have a look at this during the weekend! |
Any idea how I can add tests to this PR? Should I make a copy of the branch and go ahead from there? |
Typically the flow in Github is you make a fork of my branch of your fork, submit a pull request to me, I merge it there, and then you merge it here. But that's complicated and kind of dumb tbh. In regular git, you'd just merge my diff into a different branch, change that branch, and then merge that branch into the standard branch all locally. One thing that I did to fix the tests, which probably should be discussed a bit, is I added text serialization (but not deserialization) to binary values (as 'b[]'). This is because the testing harness really, really wants to print the value of json, and printing the value of the json is the same as serializing it. So it was throwing when it contained a binary value. I wanted to ask if I should add a deserialization or wrap the serialization code in a |
It looks like the failing travis test is a result of a failed apt-get command. Strange. |
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.
Some more comments.
I restarted the builds. Travis is flaky sometimes. |
I'll try the fork of your branch tomorrow and open a PR then. |
I'm intending on spending part of Sunday working on this. As far as I can tell all that is left is the test cases for msgpack, bson, and ubjson. Please let me know if this is correct. (And what you think of the serialization toggle.) |
@OmnipotentEntity Sorry for not answering earlier. I will try to check this during the weekend. |
I am really sorry. Something unexpected came up and I won't be able to work in this the next days. :-/ |
No worries, I understand life happens, and this is quite a large change that touches many, many different systems (so it's worth taking the time to make certain it's right). I'll try to get in some test cases for the other binary data types today, and then I'll wait for a review. |
2e91678
to
a8d1e47
Compare
@nlohmann I think this pull request is finally ready. |
Cool! Thanks for keeping working on this! I will have a look soon! |
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.
Thanks a lot for your contribution! I add some very picky remarks for polishing the last details. The only API issue is the handling of subtypes - I think the current functions can all be const
, but maybe I oversaw a use case for this.
As you see, I changed the @since
version to 3.8.0 as I think this contribution will deserve it's own feature release. I am looking forward to this!
da39bbd
to
d0dbc84
Compare
I guess Code Inspector is tired of this pull request lol Anyway, I implemented your requested changes. Let me know if it looks good to you and I'll squash back to a single commit. |
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.
One minor change request. Thanks for the quick responses!
…ernally represented binary type
d767c1c
to
012c966
Compare
Good morning. I've squashed the commits. |
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 a lot! I am not waiting for AppVeyor and will merge this as soon as all CI is green. |
THANKS! |
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
@OmnipotentEntity thanks a lot for this great contribution! |
This pull request completely implements binary type serialization and deserialization for all formats that support it. And it adds an internally represented binary type for JSONs (non-standard and serializable by default only to binary formats). The internally represented binary type also carries along an optional binary subtype, which is used by certain binary formats (msgpack, bson)
UBJSON does not support binary types, and they recommend serialization to a list of numbers, which is what is implemented by this pull request. This has the side effect of not being roundtrippable. Similarly, cbor does not support binary subtypes, so the subtype field for cbor is also not roundtrippable. Otherwise, the implementation should be roundtrippable on all inputs.
This pull request addresses #1129.
(Code coverage 100% is checked, because I think I covered everything, I don't know if we're using coveralls anymore, and I don't know how to trigger a recheck. Please trigger a recheck or tell me how, and if my code coverage is lacking I'll add more tests.)
deserialization. Currently no tests and completely untested other thanfor basic compilation
This is not a complete pull request as it stands, I have made no attempt to test or amalgamate the code yet. This is currently in the state it is in because I'd like feedback before going farther. This pull request is intended to address #1129 .Code is thus far only tested as compiling using gcc 7.4.0 (however, because much of the code is templated, and I don't have any tests that actually calls the code, there are undoubtedly numerous compilation issues just waiting to say hi just as soon as I get around to it.)Is this approach decent? Do you have any specific requests as far as implementation is concerned? Is there anything I'm doing that I ought not? Have I missed anything large?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.Please don't
#ifdef
s or other means.