Copyright | Soostone Inc |
---|---|
License | BSD3 |
Maintainer | Michael Xavier |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
io-streams interface to the cereal binary serialization library.
- getFromStream :: Get r -> InputStream ByteString -> IO r
- putToStream :: Put -> IO (InputStream ByteString)
- getEachStream :: Get r -> InputStream ByteString -> IO (InputStream r)
- putEachStream :: Putter r -> InputStream r -> IO (InputStream ByteString)
- contramapPut :: Putter r -> OutputStream ByteString -> IO (OutputStream r)
- data GetException = GetException String
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 ByteString
s 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 ByteString
s
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.