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

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 BinaryComSource

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

binaryCom2HSource

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

binaryComBSSource

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

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

Flushes a BinaryCom. Do not forget to do this after sending!

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

Shortcut for sending a value and flushing the BinaryCom

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

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 aSource

Receives a value. Runs a Get monad to parse it