-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Fast binary io-streams adapter.
--   
--   Fast binary io-streams adapter.
@package wire-streams
@version 0.1.1.0


-- | Use binary to encode/decode io-streams.
module System.IO.Streams.Binary

-- | Take a <a>Get</a> and an <a>InputStream</a> and decode a value.
--   Consumes only as much input as necessary to decode the value.
--   Unconsumed input will be unread. If there is an error while
--   deserializing, a <a>DecodeException</a> is thrown, and unconsumed part
--   will be unread. binary decoder use <a>Nothing</a> to indicate input
--   end, so EOFs/Nothing will close a binary decoder. Examples:
--   
--   <pre>
--   &gt;&gt;&gt; import qualified System.IO.Streams as Streams
--   
--   &gt;&gt;&gt; getFromStream (get :: Get String) =&lt;&lt; Streams.fromLazyByteString (Data.ByteString.Lazy.drop 1 $ runPut $ put "encode me")
--   *** Exception: System.IO.Streams.Binary: binary decode exception: offset 16, "not enough bytes"
--   </pre>
getFromStream :: Get a -> InputStream ByteString -> IO (Maybe a)

-- | typeclass version of <a>getFromStream</a>
decodeFromStream :: Binary a => InputStream ByteString -> IO (Maybe a)

-- | Write an instance of <a>Binary</a> to an <a>OutputStream</a>.
putToStream :: Binary a => Maybe a -> OutputStream ByteString -> IO ()

-- | Convert a stream of individual encoded <a>ByteString</a>s to a stream
--   of Results. Throws a <a>DecodeException</a> on error.
getInputStream :: Get a -> InputStream ByteString -> IO (InputStream a)

-- | typeclass version of <a>getInputStream</a>
decodeInputStream :: Binary a => InputStream ByteString -> IO (InputStream a)

-- | create an <a>OutputStream</a> of serializable values from an
--   <a>OutputStream</a> of bytestrings with a <tt>Putter</tt>.
putOutputStream :: (a -> Put) -> OutputStream ByteString -> IO (OutputStream a)

-- | typeclass version of <a>putOutputStream</a>
encodeOutputStream :: Binary a => OutputStream ByteString -> IO (OutputStream a)

-- | An Exception raised when binary decoding fails.
--   
--   it contains offset information where cereal don't.
data DecodeException
DecodeException :: ByteString -> ByteOffset -> String -> DecodeException
instance GHC.Show.Show System.IO.Streams.Binary.DecodeException
instance GHC.Exception.Type.Exception System.IO.Streams.Binary.DecodeException
