on master help sign in
Comments.
0285c99Lennart Kolmodin
BitsGet.hs+2−1
@@ -45,7 +45,7 @@ data S = S !ByteString -- ^ Input
45 !Int -- ^ Bit offset (0-7)
45 !Int -- ^ Bit offset (0-7)
46 deriving (Show)
46 deriving (Show)
47
47
48−-- make_mask 3 = 00000111
48+-- | make_mask 3 = 00000111
49make_mask :: Bits a => Int -> a
49make_mask :: Bits a => Int -> a
50make_mask n = (1 `shiftL` fromIntegral n) - 1
50make_mask n = (1 `shiftL` fromIntegral n) - 1
51{-# SPECIALIZE make_mask :: Int -> Word #-}
51{-# SPECIALIZE make_mask :: Int -> Word #-}
@@ -265,6 +265,7 @@ runBitGet bg = do
265 putS bs''
265 putS bs''
266 return (Right x)
266 return (Right x)
267
267
268+-- | Make sure there are at lest @n@ bits.
268ensureBits :: Int -> BitGet ()
269ensureBits :: Int -> BitGet ()
269ensureBits n = C $ \s kf ks ->
270ensureBits n = C $ \s kf ks ->
270 let loop (S bs o) | n <= (B.length bs * 8 - o) = ks (S bs o) ()
271 let loop (S bs o) | n <= (B.length bs * 8 - o) = ks (S bs o) ()