[Haskell-cafe] Parsing binary data.
Adam Langley
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[1] 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.
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.3
--
Adam Langley agl at imperialviolet.org
http://www.imperialviolet.org 650-283-9641
More information about the Haskell-Cafe
mailing list