packages feed

cereal 0.4.0.1 → 0.4.1.0

raw patch · 4 files changed

+22/−18 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.Serialize: expect :: (Eq a, Serialize a) => a -> Get a

Files

cereal.cabal view
@@ -1,5 +1,5 @@ name:                   cereal-version:                0.4.0.1+version:                0.4.1.0 license:                BSD3 license-file:           LICENSE author:                 Lennart Kolmodin <kolmodin@dtek.chalmers.se>,@@ -20,10 +20,7 @@                         tests/Tests.hs description:   A binary serialization library, similar to binary, that introduces an isolate-  primitive for parser isolation, and replaces the asynchronous errors with a-  user-handleable Either type.  Similar to binary in performance, but uses a-  strict ByteString instead of a lazy ByteString, thus restricting it to-  operating on finite inputs.+  primitive for parser isolation, and labeled blocks for better error messages.  source-repository head   type:     git
src/Data/Serialize.hs view
@@ -33,6 +33,7 @@     , encode, encodeLazy     , decode, decodeLazy +    , expect     , module Data.Serialize.Get     , module Data.Serialize.Put     , module Data.Serialize.IEEE754@@ -111,6 +112,16 @@ -- structure. decodeLazy :: Serialize a => L.ByteString -> Either String a decodeLazy  = runGetLazy get+++------------------------------------------------------------------------+-- Combinators++-- | Perform an action, failing if the read result does not match the argument+--   provided.+expect :: (Eq a, Serialize a) => a -> Get a+expect x = get >>= \y -> if x == y then return x else mzero+  ------------------------------------------------------------------------ -- Simple instances
src/Data/Serialize/Builder.hs view
@@ -67,7 +67,7 @@ import qualified Data.ByteString.Internal as S  #if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__)-import GHC.Base+import GHC.Base (Int(..), uncheckedShiftRL#) import GHC.Word (Word32(..),Word16(..),Word64(..))  #if WORD_SIZE_IN_BITS < 64 && __GLASGOW_HASKELL__ >= 608
src/Data/Serialize/Get.hs view
@@ -267,22 +267,18 @@ -- Lazy Get --------------------------------------------------------------------  runGetLazy' :: Get a -> L.ByteString -> (Either String a,L.ByteString)-runGetLazy' m lstr = loop run (L.toChunks lstr)+runGetLazy' m lstr = loop (Partial (runGetPartial m)) (L.toChunks lstr)   where-  remLen c = fromIntegral (L.length lstr) - B.length c-  run str  = unGet m str Nothing (Incomplete (Just (remLen str))) failK finalK -  loop k chunks = case chunks of+  loop result chunks = case result of -    c:cs -> case k c of-      Fail str rest -> (Left str,L.fromChunks [rest])-      Partial k'    -> loop k' cs-      Done r c'     -> (Right r,L.fromChunks (c':cs))+    Fail str rest -> (Left str, L.fromChunks (rest : chunks)) -    [] -> case k B.empty of-      Fail str rest -> (Left str,L.fromChunks [rest])-      Partial _     -> (Left "Failed reading: Internal error: unexpected end of input",L.empty)-      Done r rest   -> (Right r,L.fromChunks [rest])+    Partial k     -> case chunks of+                       c:cs -> loop (k c)       cs+                       []   -> loop (k B.empty) []++    Done r rest   -> (Right r, L.fromChunks (rest : chunks)) {-# INLINE runGetLazy' #-}  -- | Run the Get monad over a Lazy ByteString.  Note that this will not run the