From 11ef4b79c7bc4dab9796ed5d080e37289393cc66 Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Wed, 14 May 2014 13:08:02 -0400 Subject: [PATCH 1/3] add getMany --- src/Pipes/Binary.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Pipes/Binary.hs b/src/Pipes/Binary.hs index 425d986..a763cab 100644 --- a/src/Pipes/Binary.hs +++ b/src/Pipes/Binary.hs @@ -29,6 +29,7 @@ module Pipes.Binary ( -- ** Explicit 'Get' , decodeGet , decodeGetL + , getMany -- * Types , DecodingError(..) @@ -173,6 +174,7 @@ decodedL k p = fmap _encode (k (_decode p)) Right r -> return r {-# INLINABLE decodedL #-} + -------------------------------------------------------------------------------- -- | Like 'decode', except this requires an explicit 'Get' instead of any @@ -202,6 +204,19 @@ decodeGetL m = S.StateT (go id (Get.runGetIncremental m)) Right (bs, p1) -> go (diffP . (yield bs >>)) (k (Just bs)) p1 {-# INLINABLE decodeGetL #-} +-- |Produce values from a ByteString, given an explicit Get monad +getMany + :: (Monad m) => Get a -> Producer ByteString m r -> Producer a m DecodingError +getMany getA = go + where go p = do + (x,p') <- lift $ S.runStateT (decodeGet getA) p + case x of + Left err -> return err + Right a -> do + yield a + go p' +{-# INLINABLE getMany #-} + -------------------------------------------------------------------------------- -- | A 'Get' decoding error, as provided by 'Get.Fail'. From 15bc60303ad2f24f4414aba3d6a8a4774cde93eb Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Wed, 14 May 2014 13:17:34 -0400 Subject: [PATCH 2/3] version --- pipes-binary.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipes-binary.cabal b/pipes-binary.cabal index 33c1f59..a8bab3f 100644 --- a/pipes-binary.cabal +++ b/pipes-binary.cabal @@ -1,5 +1,5 @@ name: pipes-binary -version: 0.4.0 +version: 0.4.1 license: BSD3 license-file: LICENSE copyright: Copyright (c) Renzo Carbonara 2013-2014 From f4459f4d2c0fcedf0bbff9d246be129d6a2dff86 Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Wed, 14 May 2014 13:18:47 -0400 Subject: [PATCH 3/3] oops newline --- src/Pipes/Binary.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Pipes/Binary.hs b/src/Pipes/Binary.hs index a763cab..0ed3059 100644 --- a/src/Pipes/Binary.hs +++ b/src/Pipes/Binary.hs @@ -174,7 +174,6 @@ decodedL k p = fmap _encode (k (_decode p)) Right r -> return r {-# INLINABLE decodedL #-} - -------------------------------------------------------------------------------- -- | Like 'decode', except this requires an explicit 'Get' instead of any