cereal-io-streams-0.0.1.0: io-streams support for the cereal binary serialization library

CopyrightSoostone Inc
LicenseBSD3
MaintainerMichael Xavier
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

System.IO.Streams.Cereal

Description

io-streams interface to the cereal binary serialization library.

Synopsis

Documentation

getFromStream :: Get r -> InputStream ByteString -> IO r Source

Take a Get and an InputStream and deserialize a value. Consumes only as much input as necessary to deserialize the value. Unconsumed input is left on the InputStream. If there is an error while deserializing, a GetException is thrown.

Examples:

>>> getFromStream (get :: Get String) =<< putToStream (put "serialize me")
"serialize me"
>>> getFromStream (get :: Get String) =<< Streams.fromByteString (Data.ByteString.drop 1 $ runPut $ put ("serialize me" :: String))
*** Exception: Get exception: too few bytes
From:	demandInput


putToStream :: Put -> IO (InputStream ByteString) Source

Convert a Put into an InputStream

Example:

>>> putToStream (put False)

getEachStream :: Get r -> InputStream ByteString -> IO (InputStream r) Source

Convert a stream of individual serialized ByteStrings to a stream of Results. Throws a GetException on error.

Example:

>>> Streams.toList =<< getEachStream (get :: Get String) =<< Streams.fromList (map (runPut . put) ["foo", "bar"])
["foo","bar"]

putEachStream :: Putter r -> InputStream r -> IO (InputStream ByteString) Source

Convert a stream of serializable objects into a stream of individual ByteStrings Example:

>>> Streams.toList =<< getEachStream (get :: Get String) =<< putEachStream put =<< Streams.fromList ["foo","bar"]
["foo","bar"]

contramapPut :: Putter r -> OutputStream ByteString -> IO (OutputStream r) Source

Take an output stream of serializable values and create an output stream of bytestrings, one for each value.