Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update copyright notices and cabal file

  • Loading branch information...
commit 9c76157cba3f7b0a31bb65dd928ec7f98982b6c6 1 parent a1409ef
@elliottt elliottt authored
View
2  LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) Lennart Kolmodin
+Copyright (c) Lennart Kolmodin, Galois, Inc.
All rights reserved.
View
13 binary-safe.cabal
@@ -2,8 +2,8 @@ name: binary-safe
version: 0.1
license: BSD3
license-file: LICENSE
-author: Galois, Inc.
-maintainer: Galois, Inc.
+author: Lennart Kolmodin <kolmodin@dtek.chalmers.se>, Galois Inc.
+maintainer: Galois Inc.
category: Data, Parsing
stability: provisional
build-type: Simple
@@ -11,8 +11,13 @@ cabal-version: >= 1.6
extra-source-files: README index.html
flag bytestring-in-base
+ default: False
+
flag split-base
+ default: True
+
flag applicative-in-base
+ default: True
library
if flag(bytestring-in-base)
@@ -46,10 +51,8 @@ library
extensions: CPP,
FlexibleContexts,
+ FlexibleInstances,
Rank2Types,
MagicHash
ghc-options: -O2 -Wall -fliberate-case-threshold=1000
-
--- if impl(ghc < 6.5)
--- ghc-options: -fallow-undecidable-instances
View
11 src/Data/Binary/Compat.hs
@@ -1,3 +1,14 @@
+--------------------------------------------------------------------------------
+-- |
+-- Module : Data.Binary.Compat
+-- Copyright : (c) Galois Inc. 2009
+-- License : BSD3
+--
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
+--
+
module Data.Binary.Compat (
Safe.Binary(..)
View
10 src/Data/Binary/Compat/Builder.hs
@@ -4,13 +4,13 @@
-----------------------------------------------------------------------------
-- |
--- Module : Data.Binary.Safe.Builder
--- Copyright : Lennart Kolmodin, Ross Paterson
+-- Module : Data.Binary.Compat.Builder
+-- Copyright : Lennart Kolmodin, Ross Paterson, Galois Inc. 2009
-- License : BSD3-style (see LICENSE)
--
--- Maintainer : Galois, Inc.
--- Stability : experimental
--- Portability : portable to Hugs and GHC
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
--
-- Efficient construction of lazy bytestrings.
--
View
13 src/Data/Binary/Compat/Get.hs
@@ -1,3 +1,14 @@
+--------------------------------------------------------------------------------
+-- |
+-- Module : Data.Binary.Compat.Get
+-- Copyright : (c) Galois, Inc, 2009
+-- License : BSD3
+--
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
+--
+
module Data.Binary.Compat.Get (
-- * The Get type
Get
@@ -49,9 +60,11 @@ import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
+-- | Run the Get monad.
runGet :: Get a -> L.ByteString -> Either String a
runGet m bs = Safe.runGet m (S.concat (L.toChunks bs))
+-- | Run the Get monad, starting from an offset in the given ByteString.
runGetState :: Get a -> L.ByteString -> Int -> Either String (a, L.ByteString)
runGetState m bs off = case Safe.runGetState m (S.concat (L.toChunks bs)) off of
Left err -> Left err
View
8 src/Data/Binary/Compat/Put.hs
@@ -1,13 +1,13 @@
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
--- Module : Data.Binary.Put
+-- Module : Data.Binary.Compat.Put
-- Copyright : Lennart Kolmodin
-- License : BSD3-style (see LICENSE)
--
--- Maintainer : Galois, Inc.
--- Stability : stable
--- Portability : Portable to Hugs and GHC. Requires MPTCs
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
--
-- The Put monad. A monad for efficiently constructing lazy bytestrings.
--
View
94 src/Data/Binary/Safe.hs
@@ -1,23 +1,23 @@
-{-# LANGUAGE CPP, FlexibleInstances, FlexibleContexts #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
+
-----------------------------------------------------------------------------
-- |
-- Module : Data.Binary.Safe
--- Copyright : Lennart Kolmodin
+-- Copyright : Lennart Kolmodin, Galois Inc. 2009
-- License : BSD3-style (see LICENSE)
--
--- Maintainer : Lennart Kolmodin <kolmodin@dtek.chalmers.se>
--- Stability : unstable
--- Portability : portable to Hugs and GHC. Requires the FFI and some flexible instances
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
--
--- Binary serialisation of Haskell values to and from lazy ByteStrings.
+-- Binary serialisation of Haskell values to and from strict ByteStrings.
-- The Binary library provides methods for encoding Haskell values as
-- streams of bytes directly in memory. The resulting @ByteString@ can
-- then be written to disk, sent over the network, or futher processed
-- (for example, compressed with gzip).
--
--- The 'Binary' package is notable in that it provides both pure, and
--- high performance serialisation.
---
-- Values are always encoded in network order (big endian) form, and
-- encoded data should be portable across machine endianess, word size,
-- or compiler version. For example, data encoded using the Binary class
@@ -365,72 +365,6 @@ roll = foldr unstep 0
where
unstep b a = a `shiftL` 8 .|. fromIntegral b
-{-
-
---
--- An efficient, raw serialisation for Integer (GHC only)
---
-
--- TODO This instance is not architecture portable. GMP stores numbers as
--- arrays of machine sized words, so the byte format is not portable across
--- architectures with different endianess and word size.
-
-import Data.ByteString.Base (toForeignPtr,unsafePackAddress, memcpy)
-import GHC.Base hiding (ord, chr)
-import GHC.Prim
-import GHC.Ptr (Ptr(..))
-import GHC.IOBase (IO(..))
-
-instance Binary Integer where
- put (S# i) = putWord8 0 >> put (I# i)
- put (J# s ba) = do
- putWord8 1
- put (I# s)
- put (BA ba)
-
- get = do
- b <- getWord8
- case b of
- 0 -> do (I# i#) <- get
- return (S# i#)
- _ -> do (I# s#) <- get
- (BA a#) <- get
- return (J# s# a#)
-
-instance Binary ByteArray where
-
- -- Pretty safe.
- put (BA ba) =
- let sz = sizeofByteArray# ba -- (primitive) in *bytes*
- addr = byteArrayContents# ba
- bs = unsafePackAddress (I# sz) addr
- in put bs -- write as a ByteString. easy, yay!
-
- -- Pretty scary. Should be quick though
- get = do
- (fp, off, n@(I# sz)) <- liftM toForeignPtr get -- so decode a ByteString
- assert (off == 0) $ return $ unsafePerformIO $ do
- (MBA arr) <- newByteArray sz -- and copy it into a ByteArray#
- let to = byteArrayContents# (unsafeCoerce# arr) -- urk, is this safe?
- withForeignPtr fp $ \from -> memcpy (Ptr to) from (fromIntegral n)
- freezeByteArray arr
-
--- wrapper for ByteArray#
-data ByteArray = BA {-# UNPACK #-} !ByteArray#
-data MBA = MBA {-# UNPACK #-} !(MutableByteArray# RealWorld)
-
-newByteArray :: Int# -> IO MBA
-newByteArray sz = IO $ \s ->
- case newPinnedByteArray# sz s of { (# s', arr #) ->
- (# s', MBA arr #) }
-
-freezeByteArray :: MutableByteArray# RealWorld -> IO ByteArray
-freezeByteArray arr = IO $ \s ->
- case unsafeFreezeByteArray# arr s of { (# s', arr' #) ->
- (# s', BA arr' #) }
-
--}
-
instance (Binary a,Integral a) => Binary (R.Ratio a) where
put r = put (R.numerator r) >> put (R.denominator r)
get = liftM2 (R.%) get get
@@ -576,16 +510,6 @@ instance Binary B.ByteString where
putByteString bs
get = get >>= getByteString
---
--- Using old versions of fps, this is a type synonym, and non portable
---
--- Requires 'flexible instances'
---
-{-
-instance Binary ByteString where
- put bs = do put (fromIntegral (L.length bs) :: Int)
- putLazyByteString bs
- get = get >>= getLazyByteString-}
------------------------------------------------------------------------
-- Maps and Sets
View
10 src/Data/Binary/Safe/Get.hs
@@ -5,15 +5,15 @@
-----------------------------------------------------------------------------
-- |
-- Module : Data.Binary.Safe.Get
--- Copyright : Lennart Kolmodin
+-- Copyright : Lennart Kolmodin, Galois Inc. 2009
-- License : BSD3-style (see LICENSE)
--
--- Maintainer : Galois, Inc.
--- Stability : experimental
--- Portability : portable to Hugs and GHC.
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
--
-- The Get monad. A monad for efficiently building structures from
--- encoded lazy ByteStrings
+-- strict ByteStrings
--
-----------------------------------------------------------------------------
View
13 src/Data/Binary/Safe/Put.hs
@@ -1,3 +1,14 @@
+--------------------------------------------------------------------------------
+-- |
+-- Module : Data.Binary.Safe.Put
+-- Copyright : (c) Galois Inc. 2009
+-- License : BSD3
+--
+-- Maintainer : Trevor Elliott <trevor@galois.com>
+-- Stability :
+-- Portability :
+--
+
module Data.Binary.Safe.Put (
-- * The Put type
@@ -40,9 +51,11 @@ import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
+-- | Run the Put monad.
runPut :: Put -> S.ByteString
runPut m = S.concat (L.toChunks (Bin.runPut m))
+-- | Run the Put monad, and get its result.
runPutM :: PutM a -> (a, S.ByteString)
runPutM m = (a, S.concat (L.toChunks bs))
where (a,bs) = Bin.runPutM m
Please sign in to comment.
Something went wrong with that request. Please try again.