-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Turn Data.Serialize Gets and Puts into Sources, Sinks, and Conduits
--   
--   Turn Data.Serialize Gets and Puts into Sources, Sinks, and Conduits.
@package cereal-conduit
@version 0.8.0

module Data.Conduit.Cereal.Internal

-- | What should we do if the Get fails?
type ConduitErrorHandler m o = String -> ConduitT ByteString o m ()
type SinkErrorHandler m r = forall o. String -> ConduitT ByteString o m r

-- | What should we do if the stream is done before the Get is done?
type SinkTerminationHandler m r = forall o. (ByteString -> Result r) -> ConduitT ByteString o m r

-- | Construct a conduitGet with the specified ErrorHandler
mkConduitGet :: Monad m => ConduitErrorHandler m o -> Get o -> ConduitT ByteString o m ()

-- | Construct a sinkGet with the specified ErrorHandler and
--   TerminationHandler
mkSinkGet :: Monad m => SinkErrorHandler m r -> SinkTerminationHandler m r -> Get r -> ConduitT ByteString o m r

-- | Turn a Get into a Sink and a Put into a
--   Source These functions are built upno the
--   Data.Conduit.Cereal.Internal functions with default implementations of
--   ErrorHandler and TerminationHandler
--   
--   The default ErrorHandler and TerminationHandler both
--   throw a GetException.
module Data.Conduit.Cereal
data GetException

-- | Convert a Get into a Sink. The Get will be
--   streamed bytes until it returns Done or Fail.
--   
--   If Get succeed it will return the data read and unconsumed part
--   of the input stream. If the Get fails due to deserialization
--   error or early termination of the input stream it raise an error.
sinkGet :: MonadThrow m => Get r -> ConduitT ByteString o m r

-- | Run a Get repeatedly on the input stream, producing an output
--   stream of whatever the Get outputs.

-- | Deprecated: Please switch to conduitGet2, see comment on that
--   function
conduitGet :: MonadThrow m => Get o -> ConduitT ByteString o m ()

-- | Reapply Get o to a stream of bytes as long as more data is
--   available, and yielding each new value downstream. This has a few
--   differences from conduitGet:
--   
--   
--   
- If there is a parse failure, the bytes consumed so far by this
--   will not be returned as leftovers. The reason for this is that the
--   only way to guarantee the leftovers will be returned correctly is to
--   hold onto all consumed ByteStrings, which leads to
--   non-constant memory usage.
--   
- This function will properly terminate a Get function at
--   end of stream, see
--   https://github.com/snoyberg/conduit/issues/246.
--   
- conduitGet will pass empty ByteStrings from the
--   stream directly to cereal, which will trigger cereal to think that the
--   stream has been closed. This breaks the normal abstraction in conduit
--   of ignoring how data is chunked. In conduitGet2, all empty
--   ByteStrings are filtered out and not passed to cereal.
--   
- After conduitGet2 successfully returns, we are guaranteed
--   that there is no data left to be consumed in the stream.
--   
conduitGet2 :: MonadThrow m => Get o -> ConduitT ByteString o m ()

-- | Convert a Put into a Source. Runs in constant memory.
sourcePut :: Monad m => Put -> ConduitT i ByteString m ()

-- | Run a Putter repeatedly on the input stream, producing a
--   concatenated ByteString stream.
conduitPut :: Monad m => Putter a -> ConduitT a ByteString m ()
instance GHC.Show.Show Data.Conduit.Cereal.GetException
instance GHC.Exception.Type.Exception Data.Conduit.Cereal.GetException
