-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Encode and decode binary streams using the pipes and binary libraries. -- -- Encode and decode binary Pipes streams using the binary -- library. -- -- See the NEWS file in the source distribution to learn about -- any important changes between version. @package pipes-binary @version 0.2.0 -- | This module exports facilities that allow you to encode and decode -- Pipes streams of binary values. It builds on top of the -- binary, pipes and pipes-parse libraries, -- and assumes you know how to use those libraries. module Pipes.Binary -- | Encodes the given Binary instance and sends it downstream in -- ByteString chunks. encode :: (Monad m, Binary x) => x -> Producer' ByteString m () -- | Try to decode leading output from the underlying Producer into -- a Binary instance, returning either a DecodingError on -- failure, or a pair with the decoded entity together with the number of -- bytes consumed in order to produce it. -- -- Do not use this function if isEndOfBytes returns -- True, otherwise you may get unexpected decoding errors. decode :: (Monad m, Binary b) => StateT (Producer ByteString m r) m (Either DecodingError (ByteOffset, b)) -- | Continuously decode output from the given Producer into a -- Binary instance, sending downstream pairs of each successfully -- decoded entity together with the number of bytes consumed in order to -- produce it. -- -- This Producer runs until it either runs out of input or a -- decoding failure occurs, in which case it returns Left with a -- DecodingError and a Producer with any leftovers. You can -- use errorP to turn the Either return value into an -- ErrorT monad transformer. decodeMany :: (Monad m, Binary b) => Producer ByteString m r -> Producer' (ByteOffset, b) m (Either (DecodingError, Producer ByteString m r) r) -- | Like decode, except it takes an explicit Get monad. decodeGet :: Monad m => Get b -> StateT (Producer ByteString m r) m (Either DecodingError (ByteOffset, b)) -- | Like decodeMany, except it takes an explicit Get monad. decodeGetMany :: Monad m => Get b -> Producer ByteString m r -> Producer' (ByteOffset, b) m (Either (DecodingError, Producer ByteString m r) r) -- | Like encode, except it takes an explicit Put monad. encodePut :: Monad m => Put -> Producer' ByteString m () -- | A Get decoding error, as provided by Fail. data DecodingError DecodingError :: ByteOffset -> String -> DecodingError -- | Number of bytes consumed before the error. peConsumed :: DecodingError -> ByteOffset -- | Error message. peMessage :: DecodingError -> String -- | Checks if the underlying Producer has any bytes left. Leading -- empty chunks are discarded. -- | Deprecated: Will be removed as soon as the `pipes-bytestring` -- library exports it isEndOfBytes :: Monad m => StateT (Producer ByteString m r) m Bool