This pull request is built on top of PR #194 and PR #195 (thus the commits for those branches are showing as well). If those PRs are not accepted but there is interest in this one, I can rebase this branch onto master.
This PR allows parsing one object at a time:
Normally, jsmn parses the entire input string. If multiple objects are present, it will parse all of them consecutively into the tokens array. If the last object is incomplete, jsmn returns JSMN_ERROR_PART, even if there were one or more complete objects before it. This can make parsing a stream of JSON objects difficult. The input reader must ensure the input buffer passed to jsmn ends on an object boundary.
This PR adds a new macro, JSMN_SINGLE, to provide a solution to this. When defined, jsmn will only parse one object at a time. Once it has parsed a complete object, it returns immediately, ignoring the rest of the input string. The parser state will be reinitialized, so to parse the next object, simply advance the input buffer pointer ahead by tokens[0].end and call jsmn_parse() again.
This pull request is built on top of PR #194 and PR #195 (thus the commits for those branches are showing as well). If those PRs are not accepted but there is interest in this one, I can rebase this branch onto
master
.This PR allows parsing one object at a time:
Normally, jsmn parses the entire input string. If multiple objects are present, it will parse all of them consecutively into the
tokens
array. If the last object is incomplete, jsmn returnsJSMN_ERROR_PART
, even if there were one or more complete objects before it. This can make parsing a stream of JSON objects difficult. The input reader must ensure the input buffer passed to jsmn ends on an object boundary.This PR adds a new macro,
JSMN_SINGLE
, to provide a solution to this. When defined, jsmn will only parse one object at a time. Once it has parsed a complete object, it returns immediately, ignoring the rest of the input string. The parser state will be reinitialized, so to parse the next object, simply advance the input buffer pointer ahead bytokens[0].end
and calljsmn_parse()
again.