@@ -64,6 +64,10 @@ module Data.Binary.Bits.Get
6464 , getWord32be
6565 , getWord64be
6666
67+ -- ** Skip bits
68+ , skipBits
69+ , alignByte
70+
6771 -- * Blocks
6872
6973 -- $blocks
@@ -93,6 +97,7 @@ import Data.ByteString.Unsafe
9397import Data.Bits
9498import Data.Word
9599import Control.Applicative
100+import Control.Monad (when)
96101
97102import Prelude as P
98103
@@ -392,6 +397,20 @@ ensureBits n = do
392397 put B.empty
393398 return (S (bs`append`bs') o, ())
394399
400+-- | Skip the given number of bits
401+skipBits :: Int -> BitGet ()
402+skipBits n = do
403+ ensureBits n
404+ s <- getState
405+ putState $! (incS n s)
406+
407+-- | Skip bits if necessary to align on a byte
408+alignByte :: BitGet ()
409+alignByte = do
410+ (S _ n) <- getState
411+ when (n /= 0) $
412+ skipBits (8-n)
413+
395414-- | Get 1 bit as a 'Bool'.
396415getBool :: BitGet Bool
397416getBool = block bool