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 diff --git a/src/Pipes/Binary.hs b/src/Pipes/Binary.hs index 425d986..0ed3059 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(..) @@ -202,6 +203,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'.