packages feed

BitSyntax 0.3.2 → 0.3.2.1

raw patch · 3 files changed

+56/−9 lines, 3 filesdep −haskell98dep ~basenew-uploaderPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies removed: haskell98

Dependency ranges changed: base

API changes (from Hackage documentation)

- Data.BitSyntax: instance Arbitrary Word16
- Data.BitSyntax: instance Arbitrary Word32
- Data.BitSyntax: instance Show BitBlock
+ Data.BitSyntax: instance GHC.Show.Show Data.BitSyntax.BitBlock

Files

BitSyntax.cabal view
@@ -1,13 +1,23 @@ Name:            BitSyntax-Version:         0.3.2+Version:         0.3.2.1 License:         BSD3+license-file:    LICENSE Author:          Adam Langley-Homepage:        http://www.imperialviolet.org/bitsyntax+Maintainer:      Joe Crayne+category:        Serialization+Homepage:        https://github.com/joecrayne/hs-bitsyntax Stability:       experimental+cabal-version:   >= 1.6 Synopsis:        A module to aid in the (de)serialisation of binary data-Build-Depends:   base, haskell98, QuickCheck, template-haskell, bytestring Build-Type:      Simple-Exposed-modules: Data.BitSyntax-Extensions:      ForeignFunctionInterface-ghc-options:         -Wall -optl-Wl,-s-ghc-prof-options:    -prof -auto-all++library+  Exposed-modules:     Data.BitSyntax+  Build-Depends:       base < 5, QuickCheck, template-haskell, bytestring+  ghc-options:         -Wall+  Extensions:          ForeignFunctionInterface, CPP, TemplateHaskell++source-repository this+  type: git+  location: git@github.com:joecrayne/hs-bitsyntax.git+  tag: 0.3.2.1
Data/BitSyntax.hs view
@@ -1,4 +1,3 @@-{-# OPTIONS_GHC -fth -ffi #-} -- | This module contains fuctions and templates for building up and breaking --   down packed bit structures. It's something like Erlang's bit-syntax (or, --   actually, more like Python's struct module).@@ -218,21 +217,27 @@                 --   decoding to return the trailing part at that point.                 Rest -fromBytes :: (Bits a) => [a] -> a+fromBytes :: (Num a, Bits a) => [a] -> a fromBytes input =     let dofb accum [] = accum         dofb accum (x:xs) = dofb ((shiftL accum 8) .|. x) xs         in         dofb 0 $ reverse input ++-- | First byte of a 'BS.ByteString'. decodeU8 :: BS.ByteString -> Word8 decodeU8 = fromIntegral . head . BS.unpack+-- | Convert little-endian 'BS.ByteString' to big-endian 'Word16'. decodeU16 :: BS.ByteString -> Word16 decodeU16 = htons . fromBytes . map fromIntegral . BS.unpack+-- | Convert little-endian 'BS.ByteString' to big-endian 'Word32'. decodeU32 :: BS.ByteString -> Word32 decodeU32 = htonl . fromBytes . map fromIntegral . BS.unpack+-- | Convert little-endian 'BS.ByteString' to little-endian 'Word16'. decodeU16LE :: BS.ByteString -> Word16 decodeU16LE = littleEndian16 . fromBytes . map fromIntegral . BS.unpack+-- | Convert little-endian 'BS.ByteString' to little-endian 'Word32'. decodeU32LE :: BS.ByteString -> Word32 decodeU32LE = littleEndian32 . fromBytes . map fromIntegral . BS.unpack @@ -386,6 +391,10 @@ decGetName (ValD (VarP name) _ _) = name decGetName _                      = undefined -- Error! +-- | Example usage:+--+-- > parsePascalString :: Monad m => ByteString -> m (Word16, ByteString)+-- > parsePascalString bs = $( bitSyn [UnsignedLE 2, LengthPrefixed] ) bs bitSyn :: [ReadType] -> Q Exp bitSyn elements = do     inputname <- newName "input"@@ -409,10 +418,12 @@     packed = bits $ PackBits fields'     postvalues = decodeBits (map (fromIntegral . fst) fields') packed +#if !MIN_VERSION_QuickCheck(2,1,2) instance Arbitrary Word16 where   arbitrary = (arbitrary :: Gen Int) >>= return . fromIntegral instance Arbitrary Word32 where   arbitrary = (arbitrary :: Gen Int) >>= return . fromIntegral+#endif  -- | This only works on little-endian machines as it checks that the foreign --   functions (htonl and htons) match the native ones
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) The Regents of the University of California.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+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.+3. Neither the name of the University nor the names of its contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.