Previously attoparsec was suggested to me for parsing complex binary file formats. While I can find examples of attoparsec parsing HTTP, which is essentially text based, I cannot find an example parsing actual binary, for example, a TCP packet, or image file, or mp3. Can someone post some code or pointer to some code which does this using attoparsec?
+5
A:
There are few or no examples of attoparsec for parsing binary formats, as parsec-style combinator parsing is mostly for text formats, not binary formats (though there's no good reason for this).
For straight binary parsing, see Data.Binary, examples include:
and the examples in Real World Haskell.
The main example for attoparsec at the moment is an RFC2616 parser (HTTP).
Don Stewart
2010-03-13 05:37:00
Appreciate the "no good reason" comment because I don't see why a parser is more suitable for text and less for binary. Seems to me just as reasonable that a binary file can have multiple paths and need backtracking, etc.
me2
2010-03-13 17:23:42
Sure, it's just that attoparsec is so new, you'll be pushing out on your own. Just use Data.Binary like everyone else, and you'd be done by now :)
Don Stewart
2010-03-13 18:53:59
@Don that link is for the Parsec version, the Attoparsec version is here: http://bitbucket.org/bos/attoparsec/src/tip/examples/RFC2616.hs
Dan Dyer
2010-06-06 15:19:25
Combinatorrent has a attoparsec bitstream parser:http://github.com/jlouis/combinatorrent/blob/master/src/Protocol/Wire.hs#L171and the cereal-parser right next to it for your amusement.
jlouis
2010-06-07 13:37:51