-
-
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
CBOR/MessagePack from uint8_t * and size #478
Comments
I think those methods should behave like |
At a first look I thought that simply replacing the vector as argument and giving a |
I have a question regarding this issue. For the default JSON parser, we currently have a lot of overloads:
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 template<class ... Types>
static basic_json from_cbor(Types ... args) which then forwards 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 Anyway, what are your thoughts about this? |
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. |
|
Opened #623 as place to discuss the structure of the parsing functions. |
- You can now pass a reference to a vector to the to_cbor and to_msgpack functions. The output will be written (appended) to the vector. #476 - You can now pass an output stream with uint8_t character type to the to_cbor and to_msgpack functions. #477 - You can now read from uint8_t */size in the to_cbor and to_msgpack functions. An input adapter will be created from this pair, so you need to use braces. #478
Function static basic_json from_cbor(detail::input_adapter i)
{
return binary_reader(i).parse_cbor();
} now allows to read CBOR (and similarly, MessagePack) to a lot of types from which an For a json::from_cbor({packed.data(), packed.size()} (Note the braces around the pair.) |
Great. And no copy of the buffer. Thanks. Can't wait for a release ;-) . |
How would one use
from_cbor
/from_messagepack
when data is stored in auint8_t
-buffer received via a low-level C library?Could something be done in this library to support this without doing copy of the data into a vector?
The text was updated successfully, but these errors were encountered: