-- 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.
--   
--   <ul>
--   <li><i>0.7</i> Upgrade to conduit 1.0.0</li>
--   </ul>
@package cereal-conduit
@version 0.7

module Data.Conduit.Cereal.Internal

-- | What should we do if the Get fails?
type ConduitErrorHandler m o = String -> Conduit ByteString m o
type SinkErrorHandler m r = String -> Consumer ByteString m r

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

-- | Construct a conduitGet with the specified <tt>ErrorHandler</tt>
mkConduitGet :: Monad m => ConduitErrorHandler m o -> Get o -> Conduit ByteString m o

-- | Construct a sinkGet with the specified <tt>ErrorHandler</tt> and
--   <tt>TerminationHandler</tt>
mkSinkGet :: Monad m => SinkErrorHandler m r -> SinkTerminationHandler m r -> Get r -> Consumer ByteString 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 :: MonadThrow m => Get r -> Consumer ByteString m r

-- | Run a <a>Get</a> repeatedly on the input stream, producing an output
--   stream of whatever the <a>Get</a> outputs.
conduitGet :: MonadThrow m => Get o -> Conduit ByteString m o

-- | Convert a <a>Put</a> into a <tt>Source</tt>. Runs in constant memory.
sourcePut :: Monad m => Put -> Producer m ByteString

-- | Run a <a>Putter</a> repeatedly on the input stream, producing a
--   concatenated <tt>ByteString</tt> stream.
conduitPut :: Monad m => Putter a -> Conduit a m ByteString
instance Typeable GetException
instance Show GetException
instance Exception GetException
