cereal-conduit-0.8.0: Turn Data.Serialize Gets and Puts into Sources, Sinks, and Conduits

Data.Conduit.Cereal

Description

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.

Synopsis

# Documentation

Instances

 Source # MethodsshowList :: [GetException] -> ShowS # Source # Methods

sinkGet :: MonadThrow m => Get r -> ConduitT ByteString o m r Source #

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.

conduitGet :: MonadThrow m => Get o -> ConduitT ByteString o m () Source #

Deprecated: Please switch to conduitGet2, see comment on that function

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

conduitGet2 :: MonadThrow m => Get o -> ConduitT ByteString o m () Source #

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.

Since: 0.7.3

sourcePut :: Monad m => Put -> ConduitT i ByteString m () Source #

Convert a Put into a Source. Runs in constant memory.

conduitPut :: Monad m => Putter a -> ConduitT a ByteString m () Source #

Run a Putter repeatedly on the input stream, producing a concatenated ByteString stream.