packages feed

bit-protocol 0.2.0.0 → 0.2.1.0

raw patch · 3 files changed

+14/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.BitProtocol: numberToBits :: (Integral a, Bits a) => BitsVal a -> [Bool]

Files

bit-protocol.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: c8084713be489e1d73baae68e5a9c777a86d8df4dd818e9bc3b0c5b6cfe470a0+-- hash: 51fcbce5462295f23a2a6b98b1433cfbb27309fa7ed82d1e05c71d43b12a0b52  name:           bit-protocol-version:        0.2.0.0+version:        0.2.1.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
@@ -9,6 +9,8 @@   ( BitsVal(..)   , encodeBS8   , parseBS8+  -- * helpers / nice things to have+  , numberToBits   -- * internal   , bitsValBiggerToCharUnsafe   , word8sToIntegral@@ -160,3 +162,11 @@           (chunk, rest) = BL.splitAt (fromIntegral bytesNeeded) inp           (bv, bvLeftover) = readBitValue x bvInp chunk        in go xs bvLeftover rest (DL.snoc acc bv)++-- | Convert a number into a list of bools describing every bit.+numberToBits :: (Integral a, Bits a) => BitsVal a -> [Bool]+numberToBits (BitsVal len val) =+  map getBit [1..len']+  where+    len' = fromIntegral len+    getBit i = testBit val (len' - i)
test/tests.hs view
@@ -193,6 +193,8 @@             bitNums = map bvBitsNum xs             (res, _, _) = parseBS8 bitNums (encodeBS8 xs)          in res == xs+    , testCase "numberToBits simple" $ do+        numberToBits (BitsVal 6 (0b010110::Int)) @?= [False, True, False, True, True, False]     ]  main :: IO ()