Read-ahead choices that do not consume data
I am currently parsing a binary file and I have to make a decision based on a byte value.
If the value is 0x16, I want to start parsing an array that consumes the 0x16 at the start of every array element (which itself has some more fields) until no more 0x16 follow.
If the value is 0x15, I want to skip parsing the array completely and consume the 0x15 with the next parser function.
The 0x15 value is guaranteed to be present, but the array is optional. I want the 0x15 value to be saved to the parser with a dedicated key
Currently, I think I have to consume either 0x16 or 0x15 and make the decision based on that, and as a consequence my array-parser has to take care of the fact that I already consumed 0x16 for the object in the following array, making it hard to split up the parsing logic overall.
A read-ahead-choice that does not require to consume data would make this scenario quite easy. Do you have any recommendations on how to deal with this with the current tools aswell?
Edit: Another option might be calling the readUntil-function once before starting to parse an array for the first time instead of after the first element.
Seeing how this is unanswered and I had the same issue: You can call skip with a negative value. Not really a great solution but it works. By now you've probably already figured this out.