on master help sign in
Fix BitOrder naming coherence
commit1bfa8cbbdf57c1f6d7cee0f4ae173d3cec4037b2 authorSylvain HENRY <hsyl20@gmail.com> dateFri 6 Mar 2015, 21:29 (12 years ago) parent858e615
3 files changed+23−23
Data/Binary/Bits/BitOrder.hs+2−2 Data/Binary/Bits/Get.hs+10−10 Data/Binary/Bits/Put.hs+11−11
Data/Binary/Bits/BitOrder.hs+2−2
@@ -19,9 +19,9 @@ where
1919--
2020-- E.g. two words of 5 bits: ABCDE, VWXYZ
2121-- - BB: ABCDEVWX YZxxxxxx
22−-- - LB: XYZABCDE xxxxxxVW
22+-- - LL: XYZABCDE xxxxxxVW
2323-- - BL: EDCBAZYX WVxxxxxx
24−-- - LL: XWVEDCBA xxxxxxZY
24+-- - LB: XWVEDCBA xxxxxxZY
2525data BitOrder
2626 = BB -- ^ Big-endian bytes and bits
2727 | LB -- ^ Little-endian bytes, big-endian bits
Data/Binary/Bits/Get.hs+10−10
@@ -179,8 +179,8 @@ readBool :: S -> Bool
179179readBool (S bs o bo) = case bo of
180180 BB -> testBit (unsafeHead bs) (7-o)
181181 BL -> testBit (unsafeHead bs) (7-o)
182− LB -> testBit (unsafeHead bs) o
183182 LL -> testBit (unsafeHead bs) o
183+ LB -> testBit (unsafeHead bs) o
184184
185185-- | Extract a range of bits from (ws :: ByteString)
186186--
@@ -203,17 +203,17 @@ extract bo bs o n
203203
204204 -- shift offset depending on the byte position (0..B.length-1)
205205 off i = case bo of
206− LB -> 8*i - o
207206 LL -> 8*i - o
207+ LB -> 8*i - o
208208 BB -> (B.length bs -1 - i) * 8 - r
209209 BL -> (B.length bs -1 - i) * 8 - r
210210
211211 -- reverse bits if necessary
212212 rev = case bo of
213− LL -> reverseBits n
213+ LB -> reverseBits n
214214 BL -> reverseBits n
215215 BB -> id
216− LB -> id
216+ LL -> id
217217
218218
219219-- | Generic readWord
@@ -234,9 +234,9 @@ readWordChecked m n s
234234--
235235-- Examples:
236236-- BB: xxxABCDE FGHIJKLM NOPxxxxx -> ABCDEFGH IJKLMNOP
237−-- LB: LMNOPxxx DEFGHIJK xxxxxABC -> ABCDEFGH IJKLMNOP
237+-- LL: LMNOPxxx DEFGHIJK xxxxxABC -> ABCDEFGH IJKLMNOP
238238-- BL: xxxPONML KJIHGFED CBAxxxxx -> ABCDEFGH IJKLMNOP
239−-- LL: EDCBAxxx MLKJIHGF xxxxxPON -> ABCDEFGH IJKLMNOP
239+-- LB: EDCBAxxx MLKJIHGF xxxxxPON -> ABCDEFGH IJKLMNOP
240240readByteString :: Int -> S -> ByteString
241241readByteString n (S bs o bo) =
242242 let
@@ -245,12 +245,12 @@ readByteString n (S bs o bo) =
245245 rev = B.map (reverseBits 8)
246246 in case (o,bo) of
247247 (0,BB) -> bs''
248− (0,LB) -> B.reverse bs''
249− (0,LL) -> rev bs''
248+ (0,LL) -> B.reverse bs''
249+ (0,LB) -> rev bs''
250250 (0,BL) -> rev . B.reverse $ bs''
251− (_,LB) -> readByteString n (S (B.reverse bs') (8-o) BB)
251+ (_,LL) -> readByteString n (S (B.reverse bs') (8-o) BB)
252252 (_,BL) -> rev . B.reverse $ readByteString n (S bs' o BB)
253− (_,LL) -> rev . B.reverse $ readByteString n (S bs' o LB)
253+ (_,LB) -> rev . B.reverse $ readByteString n (S bs' o LL)
254254 (_,BB) -> unsafePerformIO $ do
255255 let len = n+1
256256 ptr <- mallocBytes len
Data/Binary/Bits/Put.hs+11−11
@@ -85,8 +85,8 @@ putWordS n w s@(S builder b o bo) = s'
8585 w' = case bo of
8686 BB -> w
8787 BL -> w `fastShiftR` cn
88− LB -> w `fastShiftR` cn
89− LL -> w
88+ LL -> w `fastShiftR` cn
89+ LB -> w
9090
9191 -- Select bits to store in the current byte.
9292 -- Put them in the correct order and return them in the least-significant
@@ -94,8 +94,8 @@ putWordS n w s@(S builder b o bo) = s'
9494 selectBits :: (Num a, FastBits a, Integral a) => a -> Word8
9595 selectBits x = fromIntegral $ case bo of
9696 BB -> mask cn $ x `fastShiftR` (n-cn)
97− LL -> reverseBits cn $ mask cn $ x `fastShiftR` (n-cn)
98− LB -> mask cn x
97+ LB -> reverseBits cn $ mask cn $ x `fastShiftR` (n-cn)
98+ LL -> mask cn x
9999 BL -> reverseBits cn $ mask cn x
100100
101101 -- shift left at the correct position
@@ -103,8 +103,8 @@ putWordS n w s@(S builder b o bo) = s'
103103 shl x = case bo of
104104 BB -> x `fastShiftL` (8-o-cn)
105105 BL -> x `fastShiftL` (8-o-cn)
106− LB -> x `fastShiftL` o
107106 LL -> x `fastShiftL` o
107+ LB -> x `fastShiftL` o
108108
109109 flush s2@(S b2 w2 o2 bo2)
110110 | o2 == 8 = S (b2 `mappend` B.singleton w2) 0 0 bo2
@@ -143,9 +143,9 @@ putWord64be = putWord
143143--
144144-- Examples: 3 bits are already written in the current byte
145145-- BB: ABCDEFGH IJKLMNOP -> xxxABCDE FGHIJKLM NOPxxxxx
146−-- LB: ABCDEFGH IJKLMNOP -> LMNOPxxx DEFGHIJK xxxxxABC
146+-- LL: ABCDEFGH IJKLMNOP -> LMNOPxxx DEFGHIJK xxxxxABC
147147-- BL: ABCDEFGH IJKLMNOP -> xxxPONML KJIHGFED CBAxxxxx
148−-- LL: ABCDEFGH IJKLMNOP -> EDCBAxxx MLKJIHGF xxxxxPON
148+-- LB: ABCDEFGH IJKLMNOP -> EDCBAxxx MLKJIHGF xxxxxPON
149149putByteString :: ByteString -> BitPut ()
150150putByteString bs = BitPut $ \s -> PairS () (putByteStringS bs s)
151151
@@ -154,13 +154,13 @@ putByteStringS bs s
154154 | BS.null bs = s
155155 | otherwise = case s of
156156 (S builder b 0 BB) -> S (builder `mappend` B.fromByteString bs) b 0 BB
157− (S builder b 0 LB) -> S (builder `mappend` B.fromByteString (BS.reverse bs)) b 0 LB
158− (S builder b 0 LL) -> S (builder `mappend` B.fromByteString (rev bs)) b 0 LL
157+ (S builder b 0 LL) -> S (builder `mappend` B.fromByteString (BS.reverse bs)) b 0 LL
158+ (S builder b 0 LB) -> S (builder `mappend` B.fromByteString (rev bs)) b 0 LB
159159 (S builder b 0 BL) -> S (builder `mappend` B.fromByteString (rev (BS.reverse bs))) b 0 BL
160160 (S _ _ _ BB) -> putByteStringS (BS.unsafeTail bs) (putWordS 8 (BS.unsafeHead bs) s)
161− (S _ _ _ LB) -> putByteStringS (BS.unsafeInit bs) (putWordS 8 (BS.unsafeLast bs) s)
161+ (S _ _ _ LL) -> putByteStringS (BS.unsafeInit bs) (putWordS 8 (BS.unsafeLast bs) s)
162162 (S _ _ _ BL) -> putByteStringS (BS.unsafeInit bs) (putWordS 8 (BS.unsafeLast bs) s)
163− (S _ _ _ LL) -> putByteStringS (BS.unsafeTail bs) (putWordS 8 (BS.unsafeHead bs) s)
163+ (S _ _ _ LB) -> putByteStringS (BS.unsafeTail bs) (putWordS 8 (BS.unsafeHead bs) s)
164164 where
165165 rev = BS.map (reverseBits 8)
166166