AndrasKovacs / flatparse

Fast parsing from bytestrings
MIT License
146 stars 12 forks source link

add parseWithLength #56

Open raehik opened 7 months ago

raehik commented 7 months ago

Returns parse result along with number of bytes consumed. Maybe useful for low level binary parsing.

raehik commented 7 months ago

I found myself wanting this in a library where I define arbitrary null-padded data. I parse a value of the type, then parse(/skip) nulls until a given size is reached. For that, I need to check how many bytes the parser consumed. (Previously I was doing something silly, now I'm taking a second look I realize I should be using such a combinator.)