on master help sign in
Reorder exports in BitGet and cleanup a bit
554c906Lennart Kolmodin
BitsGet.hs+9−8
@@ -1,13 +1,7 @@
1{-# LANGUAGE GADTs, RankNTypes, MagicHash, CPP #-}
1{-# LANGUAGE GADTs, RankNTypes, MagicHash, CPP #-}
2
2
3module BitsGet
3module BitsGet
4− ( -- R(..),
5− T(..)
4+ ( T(..)
6− -- , get
7− -- , getR
8− , readBool
9− , readWord8
10− , readWord16be
11 , runBitGet
5 , runBitGet
12 , runBitGetSimple
6 , runBitGetSimple
13 , BitGet
7 , BitGet
@@ -16,6 +10,10 @@ module BitsGet
16 , getWord16be
10 , getWord16be
17 , getWord32be
11 , getWord32be
18
12
13+ , readBool
14+ , readWord8
15+ , readWord16be
16+
19 ) where
17 ) where
20
18
21import Data.Binary.Get ( runGet, Get, needMore, getByteString, getS, putS )
19import Data.Binary.Get ( runGet, Get, needMore, getByteString, getS, putS )
@@ -136,13 +134,16 @@ readWithoutOffset s@(S bs o) shifterL shifterR n
136 in (bn (segs-1) :*: incS s n)
134 in (bn (segs-1) :*: incS s n)
137
135
138 | n <= 64 = let segs = byte_offset n
136 | n <= 64 = let segs = byte_offset n
137+ o' = bit_offset (n - 8 + o)
139
138
140 bn 0 = fromIntegral (unsafeHead bs)
139 bn 0 = fromIntegral (unsafeHead bs)
141 bn n = (bn (n-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs n)
140 bn n = (bn (n-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs n)
142
141
142+ msegs = bn segs `shifterL` o'
143+
143 last = (fromIntegral (unsafeIndex bs (segs + 1))) `shifterR` (8 - (bit_offset n))
144 last = (fromIntegral (unsafeIndex bs (segs + 1))) `shifterR` (8 - (bit_offset n))
144
145
145− w = bn segs .|. last
146+ w = msegs .|. last
146 in w :*: incS s n
147 in w :*: incS s n
147
148
148readWithOffset s@(S bs o) shifterL shifterR n
149readWithOffset s@(S bs o) shifterL shifterR n