module Ptr.Receive
(
Receive,
create,
peek,
)
where
import Ptr.Prelude hiding (peek)
import qualified Ptr.Receive.Core as A
import qualified Ptr.Peek as B
data Receive =
Receive !(Ptr Word8 -> Int -> IO (Either Text Int)) !(ForeignPtr Word8) !(IORef (Int, Int)) !Int
create :: (Ptr Word8 -> Int -> IO (Either Text Int)) -> Int -> IO Receive
create fetch chunkSize =
do
bufferFP <- mallocForeignPtrBytes chunkSize
bufferStateRef <- newIORef (0, 0)
return (Receive fetch bufferFP bufferStateRef chunkSize)
peek :: Receive -> B.Peek peekd -> IO (Either Text peekd)
peek (Receive fetch bufferFP bufferStateRef chunkSize) (B.Peek amount action) =
A.peek fetch bufferFP bufferStateRef chunkSize amount action