bit-protocol 0.2.2.0 → 0.2.3.0
raw patch · 3 files changed
+19/−7 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- bit-protocol.cabal +2/−2
- src/Data/BitProtocol.hs +8/−4
- test/tests.hs +9/−1
bit-protocol.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: da0f8e1767f716ba8e01975185dad2a9cffe3e268e0f70bbb628b436b06de3a9+-- hash: 3a2c164de313070c2e6c8702de2e635377ea8071115d354381b1c04ac8a49254 name: bit-protocol-version: 0.2.2.0+version: 0.2.3.0 synopsis: Encode binary protocols with some odd bit numbers into a bytestring description: Encode binary protocols with some odd bit numbers into a bytestring. category: Data, Parsing, Bits, Bytes, Protocols
src/Data/BitProtocol.hs view
@@ -165,12 +165,16 @@ where go [] bvInp inp acc = (DL.toList acc, bvInp, inp) go (x:xs) bvInp inp acc =- let bytesNeeded =- ((x - bvBitsNum bvInp) `div` 8) +- (if (x - bvBitsNum bvInp) `mod` 8 == 0+ let bits =+ if x <= bvBitsNum bvInp+ then 0+ else x - bvBitsNum bvInp+ bytes =+ (bits `div` 8) ++ (if bits `mod` 8 == 0 then 0 else 1)- (chunk, rest) = BL.splitAt (fromIntegral bytesNeeded) inp+ (chunk, rest) = BL.splitAt (fromIntegral bytes) inp (bv, bvLeftover) = readBitValue x bvInp chunk in go xs bvLeftover rest (DL.snoc acc bv)
test/tests.hs view
@@ -7,6 +7,7 @@ import Data.BitProtocol import qualified Data.ByteString.Base64.URL.Lazy as B64URL+import GHC.Natural import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck as QC@@ -126,6 +127,12 @@ , singleVendorId ]) @?= expectedResult+ , testCase "Parsing a single bit" $ do+ (parseBS8Prefixed+ [1]+ "\NUL@\SOH "+ BitsVal {bvBitsNum = 4, bvVal = (12 :: Natural)}) @?=+ ([BitsVal {bvBitsNum = 1, bvVal = 1}],BitsVal {bvBitsNum = 3, bvVal = 4},"\NUL@\SOH ") , testCase "byteStringToBitsVal simple" $ do byteStringToBitsVal "\x04\xE1\xe05\x10" @?= BitsVal 32 (0b00000100111000010000010100010000 :: Int)@@ -194,7 +201,8 @@ (res, _, _) = parseBS8 bitNums (encodeBS8 xs) in res == xs , testCase "numberToBits simple" $ do- numberToBits (BitsVal 6 (0b010110::Int)) @?= [False, True, False, True, True, False]+ numberToBits (BitsVal 6 (0b010110 :: Int)) @?=+ [False, True, False, True, True, False] ] main :: IO ()