[Haskell-cafe] binary IO

Donald Bruce Stewart dons at cse.unsw.edu.au
Mon Dec 26 23:55:24 EST 2005

> It seems I have found a hole in Haskell... :(
> Before I start to develop a library with functions such us those on 
> http://haskell.org/hawiki/BinaryIo (hGetWord8, hGetWord16le, hGetWord16be, 
> etc), is there some reliable library that can help me ?
> I basically need a set of functions to read binary data out of a Handle (a 
> higher lever of hGetBuf and hPutBuf). What I am doing is implementing a DNS 
> server, so, my typical need is:
> First two bytes are an integer.
> The next bit is a boolean.
> So are the following three bits.
> Then I have 4 bits which is also an integer.
> Etc.
> Any help is greatly appreciated.
> Thank you.

Use NewBinary, as suggested by that wiki page :)
This is the standard binary lib, used in ghc, nhc and lots of other
projects (even lambdabot!). With this, and Data.Bits, you should be able
to do whatever you need, I think.

-- Don

More information about the Haskell-Cafe mailing list