[Haskell-cafe] Using Get monad to efficiently parse byte-stuffed data

Pom Monico pommonico at gmail.com
Wed Mar 24 00:36:05 EDT 2010


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.

Going through the data using getWord8 is a no-go. It is just too slow.
My solution so far has been to get the underlying bytestring and work
with that, but obviously defeats the purpose of using the Get monad.
What might be a better solution?

Pom.


More information about the Haskell-Cafe mailing list