You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case where I want to parse a JSON string representing a flatbuffer that is to be compiled, but that json string is embedded in the middle of a larger string. In my ideal world, I would be able to pass the pointer to the start of the json to parser.ParseJson(...) to parse it, then have some function that would allow me to find out how many bytes were consumed so that I can step over the json substring from my own code.
Unfortunately this doesn't work out of the box because ParseJson(...)requires that the string its given always end in a kTokenEof token. One relatively straightforward way to deal with this would be to add an option to IDLOptions to allow embedded json strings, then make a minor change to the parser logic to just stop parsing when it reaches the end of the root table instead of continuing on, looking for that kTokenEof.
Figuring out how many bytes were parsed isn't that hard either. The parser already has a protected cursor pointer variable on it, so if I want to see how many bytes were consumed I can just do this hacky thing:
class ParserThatCanGetCursorLocation : public flatbuffer::Parser {
public:
const char* cursor() { return cursor_; }
};
But it would be nice if that functionality were officially exposed somehow too as a bytesConsumed getter or something.
I'm happy to put together a PR myself to add this functionality but I wanted to check here first to make sure this sounds like something reasonable to add.
The text was updated successfully, but these errors were encountered:
I have a use case where I want to parse a JSON string representing a flatbuffer that is to be compiled, but that json string is embedded in the middle of a larger string. In my ideal world, I would be able to pass the pointer to the start of the json to
parser.ParseJson(...)
to parse it, then have some function that would allow me to find out how many bytes were consumed so that I can step over the json substring from my own code.Unfortunately this doesn't work out of the box because
ParseJson(...)
requires that the string its given always end in akTokenEof
token. One relatively straightforward way to deal with this would be to add an option toIDLOptions
to allow embedded json strings, then make a minor change to the parser logic to just stop parsing when it reaches the end of the root table instead of continuing on, looking for thatkTokenEof
.Figuring out how many bytes were parsed isn't that hard either. The parser already has a protected cursor pointer variable on it, so if I want to see how many bytes were consumed I can just do this hacky thing:
But it would be nice if that functionality were officially exposed somehow too as a bytesConsumed getter or something.
I'm happy to put together a PR myself to add this functionality but I wanted to check here first to make sure this sounds like something reasonable to add.
The text was updated successfully, but these errors were encountered: