mysql-pure-1.0.2: pure haskell MySQL driver
CopyrightPetter Bergman Winterland
LicenseBSD3
MaintainerWinterland
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.IO.Streams.Binary

Description

Use binary 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. binary decoder use Nothing to indicate input end, so EOFs/Nothing will close a binary decoder. Examples:

>>> import qualified System.IO.Streams as Streams
>>> getFromStream (get :: Get String) =<< Streams.fromLazyByteString (Data.ByteString.Lazy.drop 1 $ runPut $ put "encode me")
*** Exception: System.IO.Streams.Binary: binary decode exception: offset 16, "not enough bytes"

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

Write an instance of Binary 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.

OutputStream encode

putOutputStream :: (a -> Put) -> OutputStream ByteString -> IO (OutputStream a) Source #

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

exception type

data DecodeException Source #

An Exception raised when binary decoding fails.

it contains offset information where cereal don't.