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

Incremental parsing: Where's the push version? #605

Closed
vinniefalco opened this issue Jun 3, 2017 · 11 comments
Closed

Incremental parsing: Where's the push version? #605

vinniefalco opened this issue Jun 3, 2017 · 11 comments

Comments

@vinniefalco
Copy link

The promotional materials cite "incremental parsing" but where is the interface that lets me call into the parser with a buffer at a time?

I see the "pull" interface where it reads from a stream - where's the push?

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2017

Do you mean the line

Aaron Burghardt implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing.

?

@vinniefalco
Copy link
Author

I think so. What I'd like is to declare an object that holds the parser state, and then call it one or more times with buffers holding pieces of the incoming JSON stream until the serialized JSON is complete. Then take ownership of the tree from the parser.

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2017

The mentioned paragraph refers to the parser from std::istream. There, it is possible to call the parser multiple times on a stream and read a JSON value each. See #367 for details.

Your described usecase is interesting, but currently not possible.

@vinniefalco
Copy link
Author

vinniefalco commented Jun 4, 2017

Fair enough. Note that reading from std::istream is "pull" parsing: the parser requests buffers until the parse is complete before returning.

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2017

Alright - I never "promised" push parsing. ;)

@vinniefalco
Copy link
Author

Context: I am looking for a JSON pull parser to use as an example in my HTTP library Beast (being proposed for Boost). I want to show how you can declare a custom "Body" type which parses incoming JSON from HTTP requests on the fly. Hence the need for a push parser that operates incrementally on buffers.

Believe it or not, NONE of the JSON libraries that I have found with my Google searching have pull parsing as a feature! If yours was the first, I could feature your library in my examples :)

Beast:
https://github.com/vinniefalco/Beast/

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2017

I understand. The "issue" is, that I aim for an intuitive API and currently I tried not to expose the parser class to the user, so I am not sure whether such a parser would really benefit this library.

@nlohmann
Copy link
Owner

nlohmann commented Jun 7, 2017

I think this is nothing I can realize right now.

@nlohmann nlohmann closed this as completed Jun 7, 2017
@nlohmann
Copy link
Owner

#623 discusses a restructuring of the parser class. Maybe this issue can be reviewed there as well.

@nlohmann
Copy link
Owner

Related: #971

@OvermindDL1
Copy link

Someone can always work around it by 'pushing' it to a suspending iterator in another thread, or in a coroutine via Boost.Fiber or Boost.Coroutine2 or whatever as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants