I am using POCO 1.6.0. I am trying to write a service that receives a JSON message on a raw socket and parses it.
However, the only way that POCO's parser seems to work is to take an entire string as input, and either return the parsed result, or throw a "Syntax error" exception.
So this means I have to re-parse the whole message each time a new byte arrives on the socket; and also there is no way of distinguishing between an actual syntax error versus it just being an incomplete message so far.
The parseChar
function looks nice but it is private. Is there any way to have the parser parse some of a message and remain in that state so that I can resume parsing by passing more data?
Also, is there any way to distinguish actual syntax errors from incomplete messages (and preferably get feedback about the exact nature of the syntax error).
Pseudocode:
Poco::JSON::Parser parser;
std::string input_buffer;
for(;;)
{
// (append byte(s) from socket into input_buffer)
// (return failure if this read times out after 5 seconds)
parser.reset();
try
{
parser.parse(input_buffer);
break;
}
catch(Poco::Exception &e)
{
// (abort, but we don't know if data incomplete or data malformed
}
}
Note: I realize that this problem could be mooted by having the client frame the entire message as described in this thread, however I was hoping to make things as simple as possible for the client by just having a correctly-formed packet be sufficient to define a frame (method 5 of that question).