@@ -57,9 +57,6 @@ module Data.Binary.Bits.Get
59 , runBitGet
59 , runBitGet
64 -- ** Get bytes
61 -- ** Get bytes
@@ -176,10 +173,6 @@ incS o (S bs n bo) = S (unsafeDrop d bs) n' bo
176 !d = byte_offset o'
173 !d = byte_offset o'
177 !n' = bit_offset o'
174 !n' = bit_offset o'
179−-- | Select the bit ordering
180−selectBitOrderS :: BitOrder -> S -> S
181−selectBitOrderS bo (S bs o _) = S bs o bo
183-- | Read a single bit
176-- | Read a single bit
184readBool :: S -> Bool
177readBool :: S -> Bool
185readBool (S bs o bo) = case bo of
178readBool (S bs o bo) = case bo of
@@ -288,6 +281,15 @@ instance Applicative BitGet where
288 pure x = return x
281 pure x = return x
289 fm <*> m = fm >>= \f -> m >>= \v -> return (f v)
282 fm <*> m = fm >>= \f -> m >>= \v -> return (f v)
284+instance BitOrderable BitGet where
286+ (S bs o _) <- getState
287+ putState (S bs o bo)
290+ (S _ _ bo) <- getState
291-- | Run a 'BitGet' within the Binary packages 'Get' monad. If a byte has
293-- | Run a 'BitGet' within the Binary packages 'Get' monad. If a byte has
292-- been partially consumed it will be discarded once 'runBitGet' is finished.
294-- been partially consumed it will be discarded once 'runBitGet' is finished.
293runBitGet :: BitGet a -> Get a
295runBitGet :: BitGet a -> Get a
@@ -322,13 +324,6 @@ withState f = do
322 s <- getState
324 s <- getState
323 putState $! f s
325 putState $! f s
325−-- | Get the bit ordering
326−getBitOrder :: BitGet BitOrder
328− (S _ _ bo) <- getState
332-- | Make sure there are at least @n@ bits.
327-- | Make sure there are at least @n@ bits.
333ensureBits :: Int -> BitGet ()
328ensureBits :: Int -> BitGet ()
334ensureBits n = do
329ensureBits n = do
@@ -355,19 +350,6 @@ alignByte = do
355 when (o /= 0) $
350 when (o /= 0) $
356 skipBits (8-o)
351 skipBits (8-o)
358−-- | Select the bit ordering
359−selectBitOrder :: BitOrder -> BitGet ()
360−selectBitOrder = withState . selectBitOrderS
362−withBitOrder :: BitOrder -> BitGet a -> BitGet a
363−withBitOrder bo f = do
372-- | Test whether all input has been consumed, i.e. there are no remaining
354-- | Test whether all input has been consumed, i.e. there are no remaining
373-- undecoded bytes.
355-- undecoded bytes.