[Haskell-cafe] Re: Bit Streams
agl at imperialviolet.org
Wed Jun 18 12:49:26 EDT 2008
On Wed, Jun 18, 2008 at 12:46 AM, Dominic Steinitz
<dominic.steinitz at blueyonder.co.uk> 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 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 of
binary-strict, there's a fully lazy BitPut.
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.
Adam Langley agl at imperialviolet.org http://www.imperialviolet.org
More information about the Haskell-Cafe