on master help sign in
Add withBitOrder
commit99f47ee9d7f80f268d1086372405afba95117c8c authorSylvain HENRY <hsyl20@gmail.com> dateMon 2 Mar 2015, 01:02 (12 years ago) parentbf33730
1 file changed+18
Data/Binary/Bits/Get.hs+18
Data/Binary/Bits/Get.hs+18
@@ -58,6 +58,7 @@ module Data.Binary.Bits.Get
5858 , BitOrder(..)
5959 , runBitGet
6060 , selectBitOrder
61+ , withBitOrder
6162
6263 -- ** Get bytes
6364 , getBool
@@ -358,6 +359,13 @@ withState f = do
358359 s <- getState
359360 putState $! f s
360361
362+-- | Get the bit ordering
363+getBitOrder :: BitGet BitOrder
364+getBitOrder = do
365+ (S _ _ bo) <- getState
366+ return bo
367+
368+
361369-- | Make sure there are at least @n@ bits.
362370ensureBits :: Int -> BitGet ()
363371ensureBits n = do
@@ -388,6 +396,16 @@ alignByte = do
388396selectBitOrder :: BitOrder -> BitGet ()
389397selectBitOrder = withState . selectBitOrderS
390398
399+withBitOrder :: BitOrder -> BitGet a -> BitGet a
400+withBitOrder bo f = do
401+ bo' <- getBitOrder
402+ selectBitOrder bo
403+ r <- f
404+ selectBitOrder bo'
405+ return r
406+
407+
408+
391409-- | Test whether all input has been consumed, i.e. there are no remaining
392410-- undecoded bytes.
393411isEmpty :: BitGet Bool