-- 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 :: Type -> Type) o = String -> ConduitT ByteString o m ()
type SinkErrorHandler (m :: Type -> Type) 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 :: Type -> Type) r = forall o. () => ByteString -> Result r -> ConduitT ByteString o m r

-- | Construct a conduitGet with the specified <tt>ErrorHandler</tt>
mkConduitGet :: forall (m :: Type -> Type) o. Monad m => ConduitErrorHandler m o -> Get o -> ConduitT ByteString o m ()

-- | Construct a sinkGet with the specified <tt>ErrorHandler</tt> and
--   <tt>TerminationHandler</tt>
mkSinkGet :: forall (m :: Type -> Type) r o. Monad m => SinkErrorHandler m r -> SinkTerminationHandler m r -> Get r -> ConduitT ByteString o m r


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

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

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

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

-- | Reapply <tt>Get o</tt> to a stream of bytes as long as more data is
--   available, and yielding each new value downstream. This has a few
--   differences from <tt>conduitGet</tt>:
--   
--   <ul>
--   <li>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 <tt>ByteString</tt>s, which leads to
--   non-constant memory usage.</li>
--   <li>This function will properly terminate a <tt>Get</tt> function at
--   end of stream, see
--   <a>https://github.com/snoyberg/conduit/issues/246</a>.</li>
--   <li><tt>conduitGet</tt> will pass empty <tt>ByteString</tt>s 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 <tt>conduitGet2</tt>, all empty
--   <tt>ByteString</tt>s are filtered out and not passed to cereal.</li>
--   <li>After <tt>conduitGet2</tt> successfully returns, we are guaranteed
--   that there is no data left to be consumed in the stream.</li>
--   </ul>
conduitGet2 :: forall (m :: Type -> Type) o. MonadThrow m => Get o -> ConduitT ByteString o m ()

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

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