packages feed

byteable (empty) → 0.1.0

raw patch · 5 files changed

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

Dependencies added: base, bytestring

Files

+ Data/Byteable.hs view
@@ -0,0 +1,47 @@+-- |+-- Module      : Data.Byteable+-- License     : BSD-style+-- Maintainer  : Vincent Hanquez <vincent@snarc.org>+-- Stability   : experimental+-- Portability : good+--+module Data.Byteable+    ( Byteable(..)+    , constEqBytes+    ) where++import Data.ByteString (ByteString)+import Data.List (foldl')+import qualified Data.ByteString as B (length, zipWith)++-- | Class of things that can generate sequence of bytes+class Byteable a where+    toBytes :: a -> ByteString++instance Byteable ByteString where+    toBytes bs = bs++-- | A constant time equality test for 2 byteable objects.+--+-- If objects are of 2 different sizes, the function will abort early+-- without comparing any bytes.+--+-- compared to == , this function will go over all the bytes+-- present before yielding a result even when knowing the+-- overall result early in the processing.+constEqBytes :: Byteable a => a -> a -> Bool+constEqBytes a b = constEqByteString (toBytes a) (toBytes b)+{-# RULES "constEqBytes/ByteString" constEqBytes = constEqByteString #-}++{-# INLINE constEqByteString #-}+constEqByteString :: ByteString -> ByteString -> Bool+constEqByteString a b+    | len /= B.length b = False+    | otherwise         = foldl' (&&!) True $ B.zipWith (==) a b+  where len = B.length a++        (&&!) :: Bool -> Bool -> Bool+        True  &&! True  = True+        True  &&! False = False+        False &&! True  = False+        False &&! False = False
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) 2013 Vincent Hanquez <vincent@snarc.org>++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 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 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 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.
+ README.md view
@@ -0,0 +1,4 @@+byteable+=======++Documentation: [byteable on hackage](http://hackage.haskell.org/package/byteable)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ byteable.cabal view
@@ -0,0 +1,32 @@+Name:                byteable+Version:             0.1.0+Synopsis:            Type class for sequence of bytes+Description:+    Abstract class to manipulate sequence of bytes+    .+    The use case of this class is abstracting manipulation of+    types that are just wrapping a bytestring with stronger and+    more meaniful name.+    .+    Usual definition is of the form: newtype MyType = MyType ByteString+License:             BSD3+License-file:        LICENSE+Copyright:           Vincent Hanquez <vincent@snarc.org>+Author:              Vincent Hanquez <vincent@snarc.org>+Maintainer:          vincent@snarc.org+Category:            Data+Stability:           experimental+Build-Type:          Simple+Homepage:            http://github.com/vincenthz/hs-byteable+Cabal-Version:       >=1.8+data-files:          README.md++Library+  Exposed-modules:   Data.Byteable+  Build-depends:     base >= 4 && < 5+                   , bytestring+  ghc-options:       -Wall -fwarn-tabs++source-repository head+  type: git+  location: git://github.com/vincenthz/hs-byteable