[Haskell-cafe] Using Get monad to efficiently parse byte-stuffed
paul at cogito.org.uk
Wed Mar 24 15:44:34 EDT 2010
On 24/03/10 04:36, Pom Monico wrote:
> Hello all,
> I'm struggling to use the Get monad to efficiently parse the some
> binary data of the format below. I simply can't find a way to use the
> monad to parse it efficiently.
> Binary data is terminated by a 0xFF marker. If the data itself
> contains an 0xFF, a 0x00 is byte-stuffed after it to indicate it is
> part of the data. An 0xFF followed by a non-zero byte indicates that
> it is a real marker and terminates the data and the 0xFF is not part
> of the data.
So the only way to find out if you have reached the end of the data is
to read beyond it? Yuck!
I haven't used it myself, but I suggest taking a look at Attoparsec,
which is like Parsec but for bytestrings. That might be able to handle
this kind of non-determinism.
More information about the Haskell-Cafe