pipes-binary-0.1.0.0: Encode and decode binary streams using the pipes and binary libraries.

Safe HaskellNone

Control.Proxy.Binary

Contents

Description

This module exports facilities that allows you to encode and decode streams of Binary values using the pipes and pipes-parse libraries.

Synopsis

Decoding

There are two different Binary decoding facilities exported by this module, and choosing between them is easy: If you need to interleave decoding with other stream effects you must use decode, otherwise you may use the simpler decodeD.

decode :: (Proxy p, Monad m, Binary r) => EitherP DecodingError (StateP [ByteString] p) () (Maybe ByteString) y' y m rSource

Decodes one Binary instance flowing downstream.

  • In case of decoding errors, a DecodingError exception is thrown in the EitherP proxy transformer.
  • Requests more input from upstream using draw when needed.
  • Do not use this proxy if isEndOfBytes returns True, otherwise you may get unexpected decoding errors.

decodeD :: (Proxy p, Monad m, Binary b) => () -> Pipe (EitherP DecodingError (StateP [ByteString] p)) (Maybe ByteString) b m ()Source

Decodes Binary instances flowing downstream until end of input.

  • In case of decoding errors, a DecodingError exception is thrown in the EitherP proxy transformer.
  • Requests more input from upstream using draw, when needed.
  • Empty input chunks flowing downstream will be discarded.

Encoding

There are two different Binary encoding facilities exported by this module, and choosing between them is easy: If you need to interleave encoding with other stream effects you must use encode, otherwise you may use the simpler encodeD.

encode :: (Proxy p, Monad m, Binary x) => x -> p x' x () ByteString m ()Source

Encodes the given Binary instance and sends it downstream in ByteString chunks.

encodeD :: (Proxy p, Monad m, Binary a) => () -> Pipe p a ByteString m rSource

Encodes Binary instances flowing downstream, each in possibly more than one ByteString chunk.

Types

data DecodingError Source

Constructors

DecodingError 

Fields

peConsumed :: ByteOffset

Number of bytes consumed before the error.

peMessage :: String

Error message.