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 am attempting to parse a field that is a potentially Null Terminated ASCII string with a max of 64 bytes. If there is no null terminator at the 64th byte then I would like to terminate the string automatically.
This is what I have for a Null Terminated ASCII string and it appears to work fine. I just need to find a way to stop parsing past 64 bytes if there is no null terminator. Ideally in an efficient manner.
ofc that won't be very efficient cos you're building parsers at runtime and storing the output bytes in a linked list shaped structure. (Could perhaps tweak this by eg putting the bytes in a List or caching the recursive NullTerminated calls but that's messy.)
One way to design an API for this might be some sort of "bounded Many", which runs a parser in a loop until it fails without consuming input or some maximum number of repetitions is reached. Then your code would look like this:
Parser<byte,IEnumerable<byte>> NullTerminated
=>Token(b =>b!=0).ManyUpTo(64);// name TBD
I'd be happy to accept a PR implementing this ManyUpTo combinator.
I am attempting to parse a field that is a potentially Null Terminated ASCII string with a max of 64 bytes. If there is no null terminator at the 64th byte then I would like to terminate the string automatically.
This is what I have for a Null Terminated ASCII string and it appears to work fine. I just need to find a way to stop parsing past 64 bytes if there is no null terminator. Ideally in an efficient manner.
Thoughts?
The text was updated successfully, but these errors were encountered: