on master help sign in
Fix BitOrder naming coherence
1bfa8cbSylvain HENRY
Data/Binary/Bits/BitOrder.hs+2−2
@@ -19,9 +19,9 @@ where
19--
19--
20-- E.g. two words of 5 bits: ABCDE, VWXYZ
20-- E.g. two words of 5 bits: ABCDE, VWXYZ
21-- - BB: ABCDEVWX YZxxxxxx
21-- - BB: ABCDEVWX YZxxxxxx
22−-- - LB: XYZABCDE xxxxxxVW
22+-- - LL: XYZABCDE xxxxxxVW
23-- - BL: EDCBAZYX WVxxxxxx
23-- - BL: EDCBAZYX WVxxxxxx
24−-- - LL: XWVEDCBA xxxxxxZY
24+-- - LB: XWVEDCBA xxxxxxZY
25data BitOrder
25data BitOrder
26 = BB -- ^ Big-endian bytes and bits
26 = BB -- ^ Big-endian bytes and bits
27 | LB -- ^ Little-endian bytes, big-endian bits
27 | LB -- ^ Little-endian bytes, big-endian bits
Data/Binary/Bits/Get.hs+10−10
@@ -179,8 +179,8 @@ readBool :: S -> Bool
179readBool (S bs o bo) = case bo of
179readBool (S bs o bo) = case bo of
180 BB -> testBit (unsafeHead bs) (7-o)
180 BB -> testBit (unsafeHead bs) (7-o)
181 BL -> testBit (unsafeHead bs) (7-o)
181 BL -> testBit (unsafeHead bs) (7-o)
182− LB -> testBit (unsafeHead bs) o
183 LL -> testBit (unsafeHead bs) o
182 LL -> testBit (unsafeHead bs) o
183+ LB -> testBit (unsafeHead bs) o
184
184
185-- | Extract a range of bits from (ws :: ByteString)
185-- | Extract a range of bits from (ws :: ByteString)
186--
186--
@@ -203,17 +203,17 @@ extract bo bs o n
203
203
204 -- shift offset depending on the byte position (0..B.length-1)
204 -- shift offset depending on the byte position (0..B.length-1)
205 off i = case bo of
205 off i = case bo of
206− LB -> 8*i - o
207 LL -> 8*i - o
206 LL -> 8*i - o
207+ LB -> 8*i - o
208 BB -> (B.length bs -1 - i) * 8 - r
208 BB -> (B.length bs -1 - i) * 8 - r
209 BL -> (B.length bs -1 - i) * 8 - r
209 BL -> (B.length bs -1 - i) * 8 - r
210
210
211 -- reverse bits if necessary
211 -- reverse bits if necessary
212 rev = case bo of
212 rev = case bo of
213− LL -> reverseBits n
213+ LB -> reverseBits n
214 BL -> reverseBits n
214 BL -> reverseBits n
215 BB -> id
215 BB -> id
216− LB -> id
216+ LL -> id
217
217
218
218
219-- | Generic readWord
219-- | Generic readWord
@@ -234,9 +234,9 @@ readWordChecked m n s
234--
234--
235-- Examples:
235-- Examples:
236-- BB: xxxABCDE FGHIJKLM NOPxxxxx -> ABCDEFGH IJKLMNOP
236-- BB: xxxABCDE FGHIJKLM NOPxxxxx -> ABCDEFGH IJKLMNOP
237−-- LB: LMNOPxxx DEFGHIJK xxxxxABC -> ABCDEFGH IJKLMNOP
237+-- LL: LMNOPxxx DEFGHIJK xxxxxABC -> ABCDEFGH IJKLMNOP
238-- BL: xxxPONML KJIHGFED CBAxxxxx -> ABCDEFGH IJKLMNOP
238-- BL: xxxPONML KJIHGFED CBAxxxxx -> ABCDEFGH IJKLMNOP
239−-- LL: EDCBAxxx MLKJIHGF xxxxxPON -> ABCDEFGH IJKLMNOP
239+-- LB: EDCBAxxx MLKJIHGF xxxxxPON -> ABCDEFGH IJKLMNOP
240readByteString :: Int -> S -> ByteString
240readByteString :: Int -> S -> ByteString
241readByteString n (S bs o bo) =
241readByteString n (S bs o bo) =
242 let
242 let
@@ -245,12 +245,12 @@ readByteString n (S bs o bo) =
245 rev = B.map (reverseBits 8)
245 rev = B.map (reverseBits 8)
246 in case (o,bo) of
246 in case (o,bo) of
247 (0,BB) -> bs''
247 (0,BB) -> bs''
248− (0,LB) -> B.reverse bs''
248+ (0,LL) -> B.reverse bs''
249− (0,LL) -> rev bs''
249+ (0,LB) -> rev bs''
250 (0,BL) -> rev . B.reverse $ bs''
250 (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)
252 (_,BL) -> rev . B.reverse $ readByteString n (S bs' o BB)
252 (_,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)
254 (_,BB) -> unsafePerformIO $ do
254 (_,BB) -> unsafePerformIO $ do
255 let len = n+1
255 let len = n+1
256 ptr <- mallocBytes len
256 ptr <- mallocBytes len
Data/Binary/Bits/Put.hs+11−11
@@ -85,8 +85,8 @@ putWordS n w s@(S builder b o bo) = s'
85 w' = case bo of
85 w' = case bo of
86 BB -> w
86 BB -> w
87 BL -> w `fastShiftR` cn
87 BL -> w `fastShiftR` cn
88− LB -> w `fastShiftR` cn
88+ LL -> w `fastShiftR` cn
89− LL -> w
89+ LB -> w
90
90
91 -- Select bits to store in the current byte.
91 -- Select bits to store in the current byte.
92 -- Put them in the correct order and return them in the least-significant
92 -- 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'
94 selectBits :: (Num a, FastBits a, Integral a) => a -> Word8
94 selectBits :: (Num a, FastBits a, Integral a) => a -> Word8
95 selectBits x = fromIntegral $ case bo of
95 selectBits x = fromIntegral $ case bo of
96 BB -> mask cn $ x `fastShiftR` (n-cn)
96 BB -> mask cn $ x `fastShiftR` (n-cn)
97− LL -> reverseBits cn $ mask cn $ x `fastShiftR` (n-cn)
97+ LB -> reverseBits cn $ mask cn $ x `fastShiftR` (n-cn)
98− LB -> mask cn x
98+ LL -> mask cn x
99 BL -> reverseBits cn $ mask cn x
99 BL -> reverseBits cn $ mask cn x
100
100
101 -- shift left at the correct position
101 -- shift left at the correct position
@@ -103,8 +103,8 @@ putWordS n w s@(S builder b o bo) = s'
103 shl x = case bo of
103 shl x = case bo of
104 BB -> x `fastShiftL` (8-o-cn)
104 BB -> x `fastShiftL` (8-o-cn)
105 BL -> x `fastShiftL` (8-o-cn)
105 BL -> x `fastShiftL` (8-o-cn)
106− LB -> x `fastShiftL` o
107 LL -> x `fastShiftL` o
106 LL -> x `fastShiftL` o
107+ LB -> x `fastShiftL` o
108
108
109 flush s2@(S b2 w2 o2 bo2)
109 flush s2@(S b2 w2 o2 bo2)
110 | o2 == 8 = S (b2 `mappend` B.singleton w2) 0 0 bo2
110 | o2 == 8 = S (b2 `mappend` B.singleton w2) 0 0 bo2
@@ -143,9 +143,9 @@ putWord64be = putWord
143--
143--
144-- Examples: 3 bits are already written in the current byte
144-- Examples: 3 bits are already written in the current byte
145-- BB: ABCDEFGH IJKLMNOP -> xxxABCDE FGHIJKLM NOPxxxxx
145-- BB: ABCDEFGH IJKLMNOP -> xxxABCDE FGHIJKLM NOPxxxxx
146−-- LB: ABCDEFGH IJKLMNOP -> LMNOPxxx DEFGHIJK xxxxxABC
146+-- LL: ABCDEFGH IJKLMNOP -> LMNOPxxx DEFGHIJK xxxxxABC
147-- BL: ABCDEFGH IJKLMNOP -> xxxPONML KJIHGFED CBAxxxxx
147-- BL: ABCDEFGH IJKLMNOP -> xxxPONML KJIHGFED CBAxxxxx
148−-- LL: ABCDEFGH IJKLMNOP -> EDCBAxxx MLKJIHGF xxxxxPON
148+-- LB: ABCDEFGH IJKLMNOP -> EDCBAxxx MLKJIHGF xxxxxPON
149putByteString :: ByteString -> BitPut ()
149putByteString :: ByteString -> BitPut ()
150putByteString bs = BitPut $ \s -> PairS () (putByteStringS bs s)
150putByteString bs = BitPut $ \s -> PairS () (putByteStringS bs s)
151
151
@@ -154,13 +154,13 @@ putByteStringS bs s
154 | BS.null bs = s
154 | BS.null bs = s
155 | otherwise = case s of
155 | otherwise = case s of
156 (S builder b 0 BB) -> S (builder `mappend` B.fromByteString bs) b 0 BB
156 (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
157+ (S builder b 0 LL) -> S (builder `mappend` B.fromByteString (BS.reverse bs)) b 0 LL
158− (S builder b 0 LL) -> S (builder `mappend` B.fromByteString (rev bs)) b 0 LL
158+ (S builder b 0 LB) -> S (builder `mappend` B.fromByteString (rev bs)) b 0 LB
159 (S builder b 0 BL) -> S (builder `mappend` B.fromByteString (rev (BS.reverse bs))) b 0 BL
159 (S builder b 0 BL) -> S (builder `mappend` B.fromByteString (rev (BS.reverse bs))) b 0 BL
160 (S _ _ _ BB) -> putByteStringS (BS.unsafeTail bs) (putWordS 8 (BS.unsafeHead bs) s)
160 (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)
162 (S _ _ _ BL) -> putByteStringS (BS.unsafeInit bs) (putWordS 8 (BS.unsafeLast bs) s)
162 (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)
164 where
164 where
165 rev = BS.map (reverseBits 8)
165 rev = BS.map (reverseBits 8)
166
166