You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At a first look I thought that simply replacing the vector as argument and giving a uint8_t *and a size_t could work with the existing functions. On a second glance, I think this needs to be tried ;-) .
When I now add these overloads to the CBOR and MessagePack parsers, this would mean 8 additional functions which are more or less the same, because each chooses one of the input adapters, which is then used to configure a binary reader (https://github.com/nlohmann/json/blob/develop/src/json.hpp#L8954) which takes care of the acutal parsing.
Before I start copying/pasting, I was wondering if there was a more elegant solution. A first idea would be to implement some kind of
which then forwards args to the constructors of the input_adapter class and basically allowing to read CBOR from anything that can create an input adapter.
This would have the advantage of only two functions (one for CBOR and one for MessagePack), but would have the disadvantage of being a bit obscure for the users of the library, because they cannot immediately recognize which arguments can be used. Of course, this could be tackled by extensive documentation, but still.
Another disadvantage of this approach is the fact that it cannot be used to limit the number of parse overloads, because these all have a const parser_callback_t cb = nullptr as last parameter which cannot follow a parameter pack.
now allows to read CBOR (and similarly, MessagePack) to a lot of types from which an input_adapter can be constructed. This includes a uint8_t */size_t pair.
Activity
theodelrieu commentedon Feb 28, 2017
I think those methods should behave like
parse, to be more generic indeedpboettch commentedon Feb 28, 2017
At a first look I thought that simply replacing the vector as argument and giving a
uint8_t *and asize_tcould work with the existing functions. On a second glance, I think this needs to be tried ;-) .nlohmann commentedon May 8, 2017
I have a question regarding this issue.
For the default JSON parser, we currently have a lot of overloads:
T (&array)[N]const CharT(CharTis a pointer to a 1-byte integral type)std::istream&andstd::istream&&IteratorType first, IteratorType lastconst ContiguousContainer&(container with contiguous storage of 1-byte values)Internally, this is realized with an input adapter class, see https://github.com/nlohmann/json/blob/develop/src/json.hpp#L8708.
When I now add these overloads to the CBOR and MessagePack parsers, this would mean 8 additional functions which are more or less the same, because each chooses one of the input adapters, which is then used to configure a binary reader (https://github.com/nlohmann/json/blob/develop/src/json.hpp#L8954) which takes care of the acutal parsing.
Before I start copying/pasting, I was wondering if there was a more elegant solution. A first idea would be to implement some kind of
which then forwards
argsto the constructors of theinput_adapterclass and basically allowing to read CBOR from anything that can create an input adapter.This would have the advantage of only two functions (one for CBOR and one for MessagePack), but would have the disadvantage of being a bit obscure for the users of the library, because they cannot immediately recognize which arguments can be used. Of course, this could be tackled by extensive documentation, but still.
Another disadvantage of this approach is the fact that it cannot be used to limit the number of
parseoverloads, because these all have aconst parser_callback_t cb = nullptras last parameter which cannot follow a parameter pack.Anyway, what are your thoughts about this?
Type1J commentedon Jun 1, 2017
I'm not sure what the status of it is, but std::array_view is proposed. I think that this is a task well suited to it.
nlohmann commentedon Jun 1, 2017
std::array_viewis not part of C++11, so unfortunately it won't be applicable to this library for a while.nlohmann commentedon Jun 17, 2017
Opened #623 as place to discuss the structure of the parsing functions.
🔨 using input/output adapters for CBOR and MessagePack
nlohmann commentedon Jul 23, 2017
Function
now allows to read CBOR (and similarly, MessagePack) to a lot of types from which an
input_adaptercan be constructed. This includes auint8_t */size_tpair.For a
std::vector<uint8_t> packed, the call is(Note the braces around the pair.)
pboettch commentedon Jul 24, 2017
Great. And no copy of the buffer. Thanks. Can't wait for a release ;-) .