Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Haskell's Parsec to parse binary files?

Parsec is designed to parse textual information, but it occurs to me that Parsec could also be suitable to do binary file format parsing for complex formats that involve conditional segments, out-of-order segments, etc.

Is there an ability to do this or a similar, alternative package that does this? If not, what is the best way in Haskell to parse binary file formats?

like image 514
me2 Avatar asked Mar 11 '10 09:03

me2


3 Answers

The key tools for parsing binary files are:

  • Data.Binary
  • cereal
  • attoparsec

Binary is the most general solution, Cereal can be great for limited data sizes, and attoparsec is perfectly fine for e.g. packet parsing. All of these are aimed at very high performance, unlike Parsec. There are many examples on hackage as well.

like image 157
Don Stewart Avatar answered Nov 07 '22 20:11

Don Stewart


You might be interested in AttoParsec, which was designed for this purpose, I think.

like image 41
Chris Eidhof Avatar answered Nov 07 '22 21:11

Chris Eidhof


I've used Data Binary successfully.

like image 4
Luca Molteni Avatar answered Nov 07 '22 21:11

Luca Molteni