binary-communicator-1.0.2.2: Flexible way to ease transmission of binary data.

Safe HaskellSafe-Inferred
LanguageHaskell98

Data.BinaryCom

Description

Binary Communicator

This module provides the datatype BinaryCom, which enables you to easily send and receive data to and from a binary source. The transmitted data can be an instance of the Binary class, or you can provide your own Put and Get actions to serialize and parse the binary stream.

Synopsis

Documentation

binaryCom :: MonadIO m => Handle -> m BinaryCom Source

Creates a BinaryCom from a Handle opened for both reading and writing. Be careful not to use the handle afterwards

binaryCom2H Source

Arguments

:: MonadIO m 
=> Handle

For reading

-> Handle

For writing

-> m BinaryCom

New BinaryCom

Creates a BinaryCom from two Handles: one for reading, one for writing

binaryComBS Source

Arguments

:: MonadIO m 
=> ByteString

For reading

-> Handle

For writing

-> m BinaryCom

New BinaryCom

Creates a BinaryCom from a lazy ByteString (for reading) and a Handle (for writing)

send :: (Binary a, MonadIO m) => BinaryCom -> a -> m () Source

Sends a serializable value through a BinaryCom

flushAfter :: MonadIO m => BinaryCom -> (BinaryCom -> m ()) -> m () Source

Runs a continuation, passing it a binary com with auto-flush deactivated. Flushes when the continuation is finished. It permits not to flush at each call to send.

receive :: (Binary a, MonadIO m) => BinaryCom -> m a Source

Receives a serializable value through a BinaryCom

sendPut :: MonadIO m => BinaryCom -> Put -> m () Source

Runs a Put monad and sends its result

receiveGet :: MonadIO m => BinaryCom -> Get a -> m a Source

Receives a value. Runs a Get monad to parse it

(+|) :: a -> a -> Bool -> a Source

A if-then-else, but with the condition as last argument