packages feed

cereal 0.3.1.0 → 0.3.2.0

raw patch · 5 files changed

+53/−10 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Serialize.Get: runGetLazy :: Get a -> ByteString -> Either String a
+ Data.Serialize.Get: runGetLazyState :: Get a -> ByteString -> Either String (a, ByteString)
+ Data.Serialize.Put: runPutLazy :: Put -> ByteString
+ Data.Serialize.Put: runPutMLazy :: PutM a -> (a, ByteString)

Files

cereal.cabal view
@@ -1,5 +1,5 @@ name:                   cereal-version:                0.3.1.0+version:                0.3.2.0 license:                BSD3 license-file:           LICENSE author:                 Lennart Kolmodin <kolmodin@dtek.chalmers.se>,
src/Data/Serialize.hs view
@@ -62,16 +62,23 @@ ------------------------------------------------------------------------ -- Wrappers to run the underlying monad --- | Encode a value using binary serialisation to a strict ByteString.---+-- | Encode a value using binary serialization to a strict ByteString. encode :: Serialize a => a -> ByteString encode = runPut . put +-- | Encode a value using binary serialization to a lazy ByteString.+encodeLazy :: Serialize a => a -> L.ByteString+encodeLazy  = runPutLazy . put+ -- | Decode a value from a strict ByteString, reconstructing the original -- structure.--- decode :: Serialize a => ByteString -> Either String a decode = runGet get++-- | Decode a value from a lazy ByteString, reconstructing the original+-- structure.+decodeLazy :: Serialize a => L.ByteString -> Either String a+decodeLazy  = runGetLazy get  ------------------------------------------------------------------------ -- Simple instances
src/Data/Serialize/Builder.hs view
@@ -58,10 +58,9 @@  import Data.Monoid import Foreign-import qualified Data.ByteString               as S-import qualified Data.ByteString.Lazy          as L-import qualified Data.ByteString.Internal      as S-import qualified Data.ByteString.Lazy.Internal as L+import qualified Data.ByteString          as S+import qualified Data.ByteString.Lazy     as L+import qualified Data.ByteString.Internal as S  #if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__) import GHC.Base
src/Data/Serialize/Get.hs view
@@ -26,7 +26,9 @@     -- * The Get type       Get     , runGet+    , runGetLazy     , runGetState+    , runGetLazyState     , Result(..)     , runGetPartial @@ -198,6 +200,18 @@   Partial{} -> Left "Failed reading: Internal error: unexpected Partial." {-# INLINE runGet #-} +-- | Run the Get monad over a Lazy ByteString.  Note that this will not run the+-- Get parser lazily, but will operate on lazy ByteStrings.+runGetLazy :: Get a -> L.ByteString -> Either String a+runGetLazy m lstr = loop (runGetPartial m) (L.toChunks lstr)+  where+  loop _ []     = Left "Failed reading: Internal error: unexpected end of input"+  loop k (c:cs) = case k c of+    Fail str   -> Left str+    Partial k' -> loop k' cs+    Done r _   -> Right r+{-# INLINE runGetLazy #-}+ -- | Run the Get monad applies a 'get'-based parser on the input ByteString runGetPartial :: Get a -> B.ByteString -> Result a runGetPartial m str = unGet m str Incomplete failK finalK@@ -214,6 +228,18 @@       Done a bs   -> Right (a, bs)       Partial{}   -> Left "Failed reading: Internal error: unexpected Partial." {-# INLINE runGetState #-}++-- | Run the Get monad over a Lazy ByteString.  Note that this does not run the+-- Get parser lazily, but will operate on lazy ByteStrings.+runGetLazyState :: Get a -> L.ByteString -> Either String (a,L.ByteString)+runGetLazyState m lstr = loop (runGetPartial m) (L.toChunks lstr)+  where+  loop _ []     = Left "Failed reading: Internal error: unexpected end of input"+  loop k (c:cs) = case k c of+    Fail str   -> Left str+    Partial k' -> loop k' cs+    Done r c'  -> Right (r,L.fromChunks (c':cs))+{-# INLINE runGetLazyState #-}  ------------------------------------------------------------------------ 
src/Data/Serialize/Put.hs view
@@ -20,6 +20,8 @@     , Putter     , runPut     , runPutM+    , runPutLazy+    , runPutMLazy     , putBuilder     , execPut @@ -62,12 +64,11 @@    ) where -import Data.Serialize.Builder (Builder, toByteString)+import Data.Serialize.Builder (Builder, toByteString, toLazyByteString) import qualified Data.Serialize.Builder as B  import Control.Applicative import Data.Array.Unboxed-import Data.Ix import Data.Monoid import Data.Word import qualified Data.ByteString        as S@@ -150,6 +151,16 @@ runPutM :: PutM a -> (a, S.ByteString) runPutM (Put (PairS f s)) = (f, toByteString s) {-# INLINE runPutM #-}++-- | Run the 'Put' monad with a serialiser+runPutLazy :: Put -> L.ByteString+runPutLazy = toLazyByteString . sndS . unPut+{-# INLINE runPutLazy #-}++-- | Run the 'Put' monad with a serialiser+runPutMLazy :: PutM a -> (a, L.ByteString)+runPutMLazy (Put (PairS f s)) = (f, toLazyByteString s)+{-# INLINE runPutMLazy #-}  ------------------------------------------------------------------------