binary-io-0.5.0: Read and write values of types that implement Binary
Safe HaskellNone
LanguageHaskell2010

Data.Binary.IO.Lifted

Description

Read and write values of types that implement Binary.

Synopsis

Reader

data ReaderError Source #

An error that can occur during reading

Since: 0.4.0

Constructors

ReaderGetError

Error from the Get operation

Fields

newtype Reader m Source #

Since: 0.4.0

Constructors

Reader 

Fields

Instances

Instances details
CanGet (Reader m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runGet :: Reader m -> Get a -> m a Source #

newReader Source #

Arguments

:: (MonadConc m, MonadIO m) 
=> Handle

Handle to read from

-> m (Reader m) 

Create a new reader.

Inherits properties from newReaderWith.

Other threads reading from the Handle will interfere with read operations of the Reader. However, the Reader itself is thread-safe and can be utilized concurrently.

The given Handle will be swiched to binary mode via hSetBinaryMode.

Since: 0.4.0

newReaderWith Source #

Arguments

:: MonadConc m 
=> m ByteString

Chunk provider

-> m (Reader m) 

Create a new Reader using an action that provides the chunks.

The chunk producers indicates the end of the stream by returning an empty ByteString.

Reading using the Reader may throw ReaderError.

The internal position of the Reader is not advanced when it throws an exception during reading. This has the consequence that if you're trying to read with the same faulty Get operation multiple times, you will always receive an exception.

The Reader is safe to use concurrently.

Since: 0.4.0

mapReader :: (forall a. m a -> n a) -> Reader m -> Reader n Source #

Transform the underlying functor.

Since: 0.4.0

Writer

newtype Writer m Source #

Since: 0.4.0

Constructors

Writer 

Fields

Instances

Instances details
CanPut (Writer m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runPut :: Writer m -> PutM a -> m a Source #

newWriter Source #

Arguments

:: MonadIO m 
=> Handle

Write target

-> Writer m 

Create a writer.

Other threads writing to the same Handle do not interfere with the resulting Writer. The Writer may be used concurrently.

Since: 0.4.0

newWriterWith Source #

Arguments

:: Functor m 
=> (ByteString -> m ())

Chunk writer

-> Writer m 

Create a writer using a function that handles the output chunks.

Since: 0.4.0

mapWriter :: (forall x. m x -> n x) -> Writer m -> Writer n Source #

Transform the underlying functor.

Since: 0.4.0

Pipe

newPipe :: (MonadConc m, MonadIO m) => m (Reader m, Writer m) Source #

Create a connected pair of Reader and Writer.

The Reader will automatically end the stream if the Writer goes out of scope.

Since: 0.4.0

Duplex

data Duplex m Source #

Pair of Reader and Writer

Since: 0.4.0

Constructors

Duplex 

Instances

Instances details
CanPut (Duplex m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runPut :: Duplex m -> PutM a -> m a Source #

CanGet (Duplex m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runGet :: Duplex m -> Get a -> m a Source #

newDuplex Source #

Arguments

:: (MonadConc m, MonadIO m) 
=> Handle

Handle to read from and write to

-> m (Duplex m) 

Create a new duplex. The Duplex inherits all the properties of Reader and Writer when created with newReader and newWriter.

Since: 0.4.0

newDuplexWith Source #

Arguments

:: MonadConc m 
=> m ByteString

Input chunk producer for Reader

-> (ByteString -> m ())

Chunk writer for Writer

-> m (Duplex m) 

Combines newReaderWith and newWriterWith.

Since: 0.4.0

mapDuplex :: (forall a. m a -> n a) -> Duplex m -> Duplex n Source #

Transform the underlying functor.

Since: 0.4.0

Classes

class CanGet r m where Source #

r can execute Get operations in m

Since: 0.4.0

Methods

runGet :: r -> Get a -> m a Source #

Instances

Instances details
CanGet Duplex IO Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Duplex -> Get a -> IO a Source #

CanGet Reader IO Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Reader -> Get a -> IO a Source #

CanGet (Duplex m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runGet :: Duplex m -> Get a -> m a Source #

CanGet (Reader m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runGet :: Reader m -> Get a -> m a Source #

read Source #

Arguments

:: (CanGet r m, Binary a) 
=> r

Source to read from

-> m a 

Read something from r. Inherits properties from runGet.

Since: 0.4.0

isEmpty Source #

Arguments

:: CanGet r m 
=> r

Source to check for stream depletion

-> m Bool 

Check if there is no more input to consume. This function may block. All properties of runGet apply to this function as well.

Since: 0.4.0

class CanPut w m where Source #

w can execute Put operations in m

Since: 0.4.0

Methods

runPut :: w -> PutM a -> m a Source #

Instances

Instances details
MonadIO m => CanPut Handle m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runPut :: Handle -> PutM a -> m a Source #

CanPut Duplex IO Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Duplex -> PutM a -> IO a Source #

CanPut Writer IO Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Writer -> PutM a -> IO a Source #

CanPut (Duplex m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runPut :: Duplex m -> PutM a -> m a Source #

CanPut (Writer m) m Source # 
Instance details

Defined in Data.Binary.IO.Lifted

Methods

runPut :: Writer m -> PutM a -> m a Source #

write Source #

Arguments

:: (CanPut w m, Binary a) 
=> w

Write target

-> a

Value to write

-> m () 

Write something to w.

Since: 0.4.0