1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
module Network.HPACK.Huffman.Bit (
-- * Bits
B (..),
Bits,
fromBits,
) where
import Imports
-- | Data type for Bit.
data B
= -- | Zero
F
| -- | One
T
deriving (Eq, Ord, Show)
-- | Bit stream.
type Bits = [B]
fromBit :: B -> Word8
fromBit F = 0
fromBit T = 1
-- | From 'Bits' of length 8 to 'Word8'.
--
-- >>> fromBits [T,F,T,F,T,F,T,F]
-- 170
-- >>> fromBits [F,T,F,T,F,T,F,T]
-- 85
fromBits :: Bits -> Word8
fromBits = foldl' (\x y -> x * 2 + y) 0 . map fromBit
|