Safe Haskell | None |
---|---|
Language | Haskell2010 |
Buffer
- data Buffer
- new :: Int -> IO Buffer
- push :: Buffer -> Int -> (Ptr Word8 -> IO (Int, result)) -> IO result
- pushBytes :: Buffer -> ByteString -> IO ()
- pushStorable :: Storable storable => Buffer -> storable -> IO ()
- pull :: Buffer -> Int -> (Ptr Word8 -> IO result) -> (Int -> IO result) -> IO result
- pullBytes :: Buffer -> Int -> (ByteString -> result) -> (Int -> IO result) -> IO result
- pullStorable :: Storable storable => Buffer -> (storable -> result) -> (Int -> IO result) -> IO result
- getBytes :: Buffer -> IO ByteString
- getSpace :: Buffer -> IO Int
Documentation
Pushing
push :: Buffer -> Int -> (Ptr Word8 -> IO (Int, result)) -> IO result Source #
Prepares the buffer to be filled with at maximum the specified amount of bytes, then uses the pointer-action to populate it. It is your responsibility to ensure that the action does not exceed the space limit.
The pointer-action returns the amount of bytes it actually writes to the buffer.
That amount then is used to move the buffer's cursor accordingly.
It can also produce some result
, which will then be emitted by push
.
It also aligns or grows the buffer if required.
pushStorable :: Storable storable => Buffer -> storable -> IO () Source #
Push a storable value into the buffer.
Pulling
pull :: Buffer -> Int -> (Ptr Word8 -> IO result) -> (Int -> IO result) -> IO result Source #
Pulls the specified amount of bytes from the buffer using the provided pointer-action, freeing the buffer from the pulled bytes afterwards.
In case the buffer does not contain enough bytes yet, the second action is called instead, given the amount of required bytes missing. You should use that action to refill the buffer accordingly and pull again.
pullBytes :: Buffer -> Int -> (ByteString -> result) -> (Int -> IO result) -> IO result Source #
Pulls the specified amount of bytes, converting them into result
,
if the buffer contains that amount.
In case the buffer does not contain enough bytes yet, the second action is called instead, given the amount of required bytes missing. You should use that action to refill the buffer accordingly and pull again.
pullStorable :: Storable storable => Buffer -> (storable -> result) -> (Int -> IO result) -> IO result Source #
Pulls a storable value, converting it into result
,
if the buffer contains enough bytes.
In case the buffer does not contain enough bytes yet, the second action is called instead, given the amount of required bytes missing. You should use that action to refill the buffer accordingly and pull again.