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?
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.
?
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.
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.
Fair enough. Note that reading from std::istream is "pull" parsing: the parser requests buffers until the parse is complete before returning.
Alright - I never "promised" push parsing. ;)
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 :)
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.
I think this is nothing I can realize right now.
Related: #971
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.
Most helpful comment
Alright - I never "promised" push parsing. ;)