wire-streams-0.0.2.0: Use cereal or binary with io-streams.

CopyrightSoostone Inc, Winterland
LicenseBSD3
MaintainerWinterland
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

System.IO.Streams.Cereal

Contents

Description

Use cereal to encode/decode io-streams.

Synopsis

single element encode/decode

getFromStream :: Get a -> InputStream ByteString -> IO (Maybe a) Source

Take a Get and an InputStream and decode a value. Consumes only as much input as necessary to decode the value. Unconsumed input will be unread. If there is an error while deserializing, a DecodeException is thrown, and unconsumed part will be unread. To simplify upstream generation, all empty ByteString will be filtered out and not passed to cereal, only EOFs/Nothing will close a cereal decoder.

Examples:

>>> import qualified System.IO.Streams as Streams
>>> getFromStream (get :: Get String) =<< Streams.fromByteString (Data.ByteString.drop 1 $ runPut $ put "encode me")
*** Exception: System.IO.Streams.Cereal: cereal decode exception: too few bytes
From:	demandInput

decodeFromStream :: Serialize a => InputStream ByteString -> IO (Maybe a) Source

typeclass version of getFromStream

putToStream :: Serialize a => Maybe a -> OutputStream ByteString -> IO () Source

write a instance of Serialize to an OutputStream

InputStream encode/decode

getInputStream :: Get a -> InputStream ByteString -> IO (InputStream a) Source

Convert a stream of individual encoded ByteStrings to a stream of Results. Throws a DecodeException on error.

decodeInputStream :: Serialize a => InputStream ByteString -> IO (InputStream a) Source

typeclass version of getInputStream

OutputStream encode

putOutputStream :: Putter a -> OutputStream ByteString -> IO (OutputStream a) Source

create an OutputStream of serializable values from an OutputStream of bytestrings with a Putter.

encodeOutputStream :: Serialize a => OutputStream ByteString -> IO (OutputStream a) Source

typeclass version of putOutputStream

exception type

data DecodeException Source

An Exception raised when cereal decoding fails.

Constructors

DecodeException String