-
-
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
Support startIndex for from_cbor/from_msgpack #462
Comments
Done. |
Thanks! |
The CBOR and MessagePack parsers now expect the input to be read until the end. Unless the new parameter "strict" is set to false (it is true by default), an exception is raised if the parser ends prematurely. This is a breaking change as the parsers ignored unread input so far. Furthermore, the offset/startIndex paramter introduced in #462 was removed as this behavior can be mimicked with an iterator range. For instance, instead of calling "from_cbor(vec, 5);", you can write "from_cbor({vec.begin()+5, vec.end()});".
With 22b5969, the offset/startIndex parameter was removed as this behavior can be mimicked with an iterator range. For instance, instead of calling json j = json::from_cbor(vec, 5); you can write json j = json::from_cbor({vec.begin()+5, vec.end()}); |
Are the braces |
Yes, I did not find a better way to implicitly create an input adapter from two parameters. And since there is a parameter with a default value following, I cannot use variadic parameters. (Though I would love to find a solution!) |
I didn't go into the details of You could then construct the |
That would be one solution, but then I also have an input adapter to parse from a |
(Of course, the example above could be written as json j = json::from_cbor(json::input_adapter(vec.begin()+5, vec.end())); |
Actually, this is also supported by auto j = json::parse(vec.begin(), vec.end());
auto j2 = json::parse(vec.data(), vec.data() + vec.size()); Both cases are covered with the same overload. Plus, that would be symmetrical with other parts of the API (e.g. If those kind of methods could share the same API, that would become really intuitive to use IMO. |
I know that this is desirable, but I don't really like copy/pasting so many functions... |
On the other hand, there are at most two parameters, so I can add two functions for each parser and forward the arguments to the input_adapter constructors. |
@theodelrieu Since you are the SFINAE wizard - what do you think of template<typename A1, typename A2,
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
static basic_json from_cbor(A1&& a1, A2&& a2, const bool strict = true)
{
return binary_reader(detail::input_adapter(std::forward<A1>(a1), std::forward<A2>(a2))).parse_cbor(strict);
} |
Ahah I'm not sure I deserve that title :) Well that will work, but I think it's quite brittle for some reasons:
I understand that you don't want to copy code, in order to get the same interface than All those functions ( Last but not least, I'd rather write boilerplate in the library code than in the client code, all day everyday! Even more when it's just a few lines ;) |
I wish I had some arguments that do not translate into "I am too lazy to do the copying...". :-/ |
I can take care of it :p Anyway I'd rather not have to rebase my PR (#700) twice a day, so if you want to wait a bit before committing that's fine for me! |
I won't touch this one right now. I'm about to finish #593 and then I let the library go. |
About #462 (comment): I just realized we do more or less the same here: https://github.com/nlohmann/json/blob/develop/src/json.hpp#L8368 |
The idea is to not create another copy of std::vector since my cbor data start at certain offset.
The text was updated successfully, but these errors were encountered: