[Haskell-cafe] Parsing binary data.
agl at imperialviolet.org
Sat Aug 18 13:47:28 EDT 2007
On 8/18/07, Peter Cai <newptcai at gmail.com> wrote:
> As the old version of this component is written in C, it's very natural that
> this protocol is base on C structure definitions, which are, unfortunately,
> very complicated. And the worse is that every field in every structure must
> be converted to Network Endian.
You could certainly try Data.Binary for this. It has a nice Get
monad with methods such as getWord32be which sounds like it might be
what you want. One caveat is that it's fully lazy - you get the result
immediately and parse errors can only be caught as exceptions when you
actually come to using the result. This is perfect for very large
messages, but might be slightly wrong for you.
Adam Langley agl at imperialviolet.org
More information about the Haskell-Cafe