packages feed

attoparsec-binary (empty) → 0.1

raw patch · 5 files changed

+151/−0 lines, 5 filesdep +attoparsecdep +basedep +bytestringsetup-changed

Dependencies added: attoparsec, base, bytestring

Files

+ Data/Attoparsec/Binary.hs view
@@ -0,0 +1,85 @@+-- |Binary processing extensions to Attoparsec.+module Data.Attoparsec.Binary(+  anyWord16be,+  anyWord16le,+  anyWord32be,+  anyWord32le,+  anyWord64be,+  anyWord64le,+  word16be,+  word16le,+  word32be,+  word32le,+  word64be,+  word64le+  ) where++import Data.Attoparsec+import Data.Bits+import qualified Data.ByteString as B+import Data.Word++byteSize :: (Bits a) => a -> Int+byteSize = (`div` 8) . bitSize++pack :: (Bits a) => B.ByteString -> a+pack = B.foldl' (\n h -> (n `shiftL` 8) .|. fromIntegral h) 0++anyWordN :: (Bits a) => (B.ByteString -> a) -> Parser a+anyWordN = anyWordN' undefined+  where anyWordN' :: (Bits a) => a -> (B.ByteString -> a) -> Parser a+        anyWordN' d = flip fmap $ Data.Attoparsec.take $ byteSize d++-- |Match any 16-bit big-endian word.+anyWord16be :: Parser Word16+anyWord16be = anyWordN pack++-- |Match any 16-bit little-endian word.+anyWord16le :: Parser Word16+anyWord16le = anyWordN $ pack . B.reverse++-- |Match any 32-bit big-endian word.+anyWord32be :: Parser Word32+anyWord32be = anyWordN pack++-- |Match any 32-bit little-endian word.+anyWord32le :: Parser Word32+anyWord32le = anyWordN $ pack . B.reverse++-- |Match any 64-bit big-endian word.+anyWord64be :: Parser Word64+anyWord64be = anyWordN pack++-- |Match any 64-bit little-endian word.+anyWord64le :: Parser Word64+anyWord64le = anyWordN $ pack . B.reverse++unpack :: (Bits a, Integral a) => a -> B.ByteString+unpack x = B.pack $ map (fromIntegral . shiftR x . (8 *)) $ reverse [0..byteSize x - 1]++wordN :: (Bits a) => (a -> B.ByteString) -> a -> Parser a+wordN u w = string (u w) >> return w++-- |Match a specific 16-bit big-endian word.+word16be :: Word16 -> Parser Word16+word16be = wordN unpack++-- |Match a specific 16-bit little-endian word.+word16le :: Word16 -> Parser Word16+word16le = wordN $ B.reverse . unpack++-- |Match a specific 32-bit big-endian word.+word32be :: Word32 -> Parser Word32+word32be = wordN unpack++-- |Match a specific 32-bit little-endian word.+word32le :: Word32 -> Parser Word32+word32le = wordN $ B.reverse . unpack++-- |Match a specific 64-bit big-endian word.+word64be :: Word64 -> Parser Word64+word64be = wordN unpack++-- |Match a specific 64-bit little-endian word.+word64le :: Word64 -> Parser Word64+word64le = wordN $ B.reverse . unpack
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Andrew Drake++All rights reserved.++Redistribution and use in source and binary forms, with or without+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.++    * 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 Andrew Drake nor the names of other+      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.
+ README view
@@ -0,0 +1,1 @@+See the Haddock documentation for more details.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ attoparsec-binary.cabal view
@@ -0,0 +1,33 @@+Name: attoparsec-binary+Version: 0.1+Author: Andrew Drake+Copyright: (c) 2011 Andrew Drake+Maintainer: adrake@adrake.org+Version: 0.1+Synopsis: Binary processing extensions to Attoparsec.+Stability: unstable++License: BSD3+License-file: LICENSE++Description: This package adds a collection of helper functions to make+ the task dealing with binary data of varying endianness from within an+ Attoparsec parser easier.++Category: Data+Build-type: Simple++Extra-source-files: README+Cabal-version: >=1.6++Source-Repository head+  Type: git+  Location: git://github.com/drakedevel/attoparsec-binary.git++Library+  Exposed-modules: Data.Attoparsec.Binary+  Build-depends:+    attoparsec >= 0.8.5.0,+    base >= 3 && < 5,+    bytestring >= 0.9.1.10+  GHC-Options: -Wall