Skip to content
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

I think should implement an parser function #1016

Closed
mlkt opened this issue Mar 17, 2018 · 2 comments
Closed

I think should implement an parser function #1016

mlkt opened this issue Mar 17, 2018 · 2 comments
Labels
documentation kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@mlkt
Copy link

mlkt commented Mar 17, 2018

I see an issue #801

I think should implement an parser function, for example:
char* data = ....; //read from network or other data source;
size_t data_len = ....; //known when read data.
json j = parse_json(data, data_len);

call parse_json() is zero-copy, no need to convert to std::string.

@nlohmann
Copy link
Owner

We already have this, but it may be a bit hidden. You would need to write

json j = parse_json({data, data_len});

Explanation: We use input adapters for the parser, and {data, data_len} constructs one with the signature

input_buffer_adapter(const char* b, const std::size_t l)

It uses the buffer and does not make copies.

I really need to improve the documentation on this...

@nlohmann nlohmann added kind: question documentation solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Mar 17, 2018
@mlkt
Copy link
Author

mlkt commented Mar 18, 2018

OK, it looks well, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants