
agl:
On Wed, Jun 18, 2008 at 12:46 AM, Dominic Steinitz
wrote: OK, so today I tried to write my first program using the Binary library. And I've hit a snag: It appears the library will only handle data that is byte-aligned. So if I try to write three Bool values, it uses three bytes, not three bits.
There's a BitGet[1] and BitPut in the Hackage version of binary-strict. However, these versions work on strict ByteStrings. Putting, for one, is pretty inefficient. In the darcs version[2] of binary-strict, there's a fully lazy BitPut[3].
There was a request for a lazy BitGet, but I never wrote it. Most of the time, bit fields are small and you can use the lazy Get from binary to extract a ByteString and parse that with strict BitGet. However, the BitPut should be just fine (including doing things like writing ByteStrings by shifting each byte etc).
If it's missing anything obvious, ping me and I'll see what I can do.
Cheers,
[1] http://darcs.imperialviolet.org/darcsweb.cgi?r=binary-strict;a=headblob;f=/s... [2] http://darcs.imperialviolet.org/binary-strict/ [3] http://darcs.imperialviolet.org/darcsweb.cgi?r=binary-strict;a=headblob;f=/s...
Adam, Would you recommend binary-strict over bitsyntax now? Or are none yet entirely satisfactory -- Don