binary-strict 0.4.8.4 → 0.4.8.5
raw patch · 7 files changed
+167/−31 lines, 7 filesdep +binary-strictsetup-changed
Dependencies added: binary-strict
Files
- CHANGELOG.md +0/−5
- LICENSE +22/−22
- Setup.hs +0/−2
- Setup.lhs +3/−0
- binary-strict.cabal +11/−2
- src/Data/Binary/Strict/Common.h +96/−0
- tests/BitGetTest.hs +35/−0
− CHANGELOG.md
@@ -1,5 +0,0 @@-# Revision history for binary-low-level--## 0.1.0.0 -- YYYY-mm-dd--* First version. Released on an unsuspecting world.
LICENSE view
@@ -1,30 +1,30 @@-Copyright (c) 2020, Dominic Steinitz+Copyright (c) Lennart Kolmodin All rights reserved. Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions are met:+modification, are permitted provided that the following conditions+are met: - * Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.+1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above- copyright notice, this list of conditions and the following- disclaimer in the documentation and/or other materials provided- with the distribution.+2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution. - * Neither the name of Dominic Steinitz nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission.+3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
binary-strict.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: binary-strict-version: 0.4.8.4+version: 0.4.8.5 synopsis: Binary deserialisation using strict ByteStrings description: This is a strict version of the Get monad from the binary package. It's pretty much just a copy and paste job@@ -18,7 +18,7 @@ copyright: Dominic Steinitz, Lennart Kolmodin category: Data, Parsing build-type: Simple-extra-source-files: CHANGELOG.md+extra-source-files: src/Data/Binary/Strict/Common.h library exposed-modules: Data.Binary.BitBuilder,@@ -40,3 +40,12 @@ array >=0.5 && <0.6 hs-source-dirs: src default-language: Haskell2010++Test-Suite test+ type: exitcode-stdio-1.0+ main-is: tests/BitGetTest.hs+ build-depends: base >=4.12 && <4.13,+ bytestring >=0.10 && <0.11,+ binary-strict+ default-language: Haskell2010+
+ src/Data/Binary/Strict/Common.h view
@@ -0,0 +1,96 @@+#define GETHOSTWORD(name, m, type) \+name :: m type ; \+name = getPtr (sizeOf (undefined :: type))++#define GETHOSTWORDS(m) \+GETHOSTWORD(getWord8, m, Word8); \+GETHOSTWORD(getWordhost, m, Word) ; \+GETHOSTWORD(getWord16host, m, Word16) ; \+GETHOSTWORD(getWord32host, m, Word32) ; \+GETHOSTWORD(getWord64host, m, Word64) ; \++#define DECWORD16LE(s) \+ ((fromIntegral (s `B.index` 1) `shiftl_w16` 8) .|. \+ (fromIntegral (s `B.index` 0) ) )++#define DECWORD16BE(s) \+ ((fromIntegral (s `B.index` 0) `shiftl_w16` 8) .|. \+ (fromIntegral (s `B.index` 1) ) )++#define DECWORD32BE(s) \+ ((fromIntegral (s `B.index` 0) `shiftl_w32` 24) .|. \+ (fromIntegral (s `B.index` 1) `shiftl_w32` 16) .|. \+ (fromIntegral (s `B.index` 2) `shiftl_w32` 8) .|. \+ (fromIntegral (s `B.index` 3) ) )++#define DECWORD32LE(s) \+ ((fromIntegral (s `B.index` 3) `shiftl_w32` 24) .|. \+ (fromIntegral (s `B.index` 2) `shiftl_w32` 16) .|. \+ (fromIntegral (s `B.index` 1) `shiftl_w32` 8) .|. \+ (fromIntegral (s `B.index` 0) ) )++#define DECWORD64BE(s) \+ ((fromIntegral (s `B.index` 0) `shiftl_w64` 56) .|. \+ (fromIntegral (s `B.index` 1) `shiftl_w64` 48) .|. \+ (fromIntegral (s `B.index` 2) `shiftl_w64` 40) .|. \+ (fromIntegral (s `B.index` 3) `shiftl_w64` 32) .|. \+ (fromIntegral (s `B.index` 4) `shiftl_w64` 24) .|. \+ (fromIntegral (s `B.index` 5) `shiftl_w64` 16) .|. \+ (fromIntegral (s `B.index` 6) `shiftl_w64` 8) .|. \+ (fromIntegral (s `B.index` 7) ) )++#define DECWORD64LE(s) \+ ((fromIntegral (s `B.index` 7) `shiftl_w64` 56) .|. \+ (fromIntegral (s `B.index` 6) `shiftl_w64` 48) .|. \+ (fromIntegral (s `B.index` 5) `shiftl_w64` 40) .|. \+ (fromIntegral (s `B.index` 4) `shiftl_w64` 32) .|. \+ (fromIntegral (s `B.index` 3) `shiftl_w64` 24) .|. \+ (fromIntegral (s `B.index` 2) `shiftl_w64` 16) .|. \+ (fromIntegral (s `B.index` 1) `shiftl_w64` 8) .|. \+ (fromIntegral (s `B.index` 0) ) )++#define GETWORD16LE(name, m, f) \+name :: m Word16 ; \+name = do { \+ s <- f 2; \+ return $! DECWORD16LE(s) }++#define GETWORD16BE(name, m, f) \+name :: m Word16 ; \+name = do { \+ s <- f 2; \+ return $! DECWORD16BE(s) }++#define GETWORD32LE(name, m, f) \+name :: m Word32 ; \+name = do { \+ s <- f 4; \+ return $! DECWORD32LE(s) }++#define GETWORD32BE(name, m, f) \+name :: m Word32 ; \+name = do { \+ s <- f 4; \+ return $! DECWORD32BE(s) }++#define GETWORD64LE(name, m, f) \+name :: m Word64 ; \+name = do { \+ s <- f 8; \+ return $! DECWORD64LE(s) }++#define GETWORD64BE(name, m, f) \+name :: m Word64 ; \+name = do { \+ s <- f 8; \+ return $! DECWORD64BE(s) }++#define GETWORDS(m, f) \+GETWORD16LE(getWord16le, m, f); \+GETWORD16BE(getWord16be, m, f); \+GETWORD32LE(getWord32le, m, f); \+GETWORD32BE(getWord32be, m, f); \+GETWORD64LE(getWord64le, m, f); \+GETWORD64BE(getWord64be, m, f);++
+ tests/BitGetTest.hs view
@@ -0,0 +1,35 @@+module Main where++import qualified Data.ByteString as B+import Data.Word++import qualified Data.Binary.Strict.BitGet as BG++t :: (Eq a, Show a) => [Word8] -> BG.BitGet a -> a -> Bool+t bytes m v = if result == v then True else error (show (bytes, v, result)) where+ Right result = BG.runBitGet (B.pack bytes) m++tests = [+ t [1] BG.getWord8 1+ , t [128] BG.getBit True+ , t [64] BG.getBit False+ , t [1, 0] BG.getWord16be 256+ , t [1, 2] BG.getWord16be 258+ , t [1, 0] BG.getWord16le 1+ , t [2, 1] BG.getWord16le 258+ , t [192, 0] (BG.getBit >> BG.getWord8) 128+ , t [193, 0] (BG.getBit >> BG.getWord8) 130+ , t [193, 42] (sequence (take 8 $ repeat BG.getBit) >> BG.getWord8) 42+ , t [193] (BG.getAsWord8 3) 6+ , t [193] (BG.getAsWord8 4) 12+ , t [193, 128] (BG.skip 4 >> BG.getAsWord8 4) 1+ , t [193, 128] (BG.skip 8 >> BG.getAsWord8 4) 8+ , t [1, 2, 3, 0] (BG.getAsWord32 24) 66051+ , t [1, 2, 3, 0] (BG.getAsWord32 8) 1+ , t [1, 2, 3, 4, 5] (BG.getAsWord64 40) 4328719365+ , t [251, 161, 235, 192] (BG.getAsInt32 28) (-4579652)+ ]++main = do+ print $ length $ filter id tests+ putStrLn "PASS"