{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Context ( Cxt(..)
, cxtSize
, cxtBlockCount
, unsafeSetCxtEmpty
, unsafeSetCxtFull
, unsafeGenerateBlocks
, unsafeConsumeBlocks
, unsafeWriteTo
, unsafeFillFrom
, unsafeUpdate
, unsafeFinalise
) where
import GHC.TypeLits
import Raaz.Core
import Implementation
import Buffer
data Cxt n = Cxt { Cxt n -> Internals
cxtInternals :: Internals
, Cxt n -> Buffer n
cxtBuf :: Buffer n
, Cxt n -> MemoryCell (BYTES Int)
cxtAvailableBytes :: MemoryCell (BYTES Int)
}
instance KnownNat n => Memory (Cxt n) where
memoryAlloc :: Alloc (Cxt n)
memoryAlloc = Internals -> Buffer n -> MemoryCell (BYTES Int) -> Cxt n
forall (n :: Nat).
Internals -> Buffer n -> MemoryCell (BYTES Int) -> Cxt n
Cxt (Internals -> Buffer n -> MemoryCell (BYTES Int) -> Cxt n)
-> TwistRF AllocField (BYTES Int) Internals
-> TwistRF
AllocField
(BYTES Int)
(Buffer n -> MemoryCell (BYTES Int) -> Cxt n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TwistRF AllocField (BYTES Int) Internals
forall m. Memory m => Alloc m
memoryAlloc TwistRF
AllocField
(BYTES Int)
(Buffer n -> MemoryCell (BYTES Int) -> Cxt n)
-> TwistRF AllocField (BYTES Int) (Buffer n)
-> TwistRF AllocField (BYTES Int) (MemoryCell (BYTES Int) -> Cxt n)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TwistRF AllocField (BYTES Int) (Buffer n)
forall m. Memory m => Alloc m
memoryAlloc TwistRF AllocField (BYTES Int) (MemoryCell (BYTES Int) -> Cxt n)
-> TwistRF AllocField (BYTES Int) (MemoryCell (BYTES Int))
-> Alloc (Cxt n)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TwistRF AllocField (BYTES Int) (MemoryCell (BYTES Int))
forall m. Memory m => Alloc m
memoryAlloc
unsafeToPointer :: Cxt n -> Ptr Word8
unsafeToPointer = Buffer n -> Ptr Word8
forall m. Memory m => m -> Ptr Word8
unsafeToPointer (Buffer n -> Ptr Word8)
-> (Cxt n -> Buffer n) -> Cxt n -> Ptr Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cxt n -> Buffer n
forall (n :: Nat). Cxt n -> Buffer n
cxtBuf
cxtBlockCount :: KnownNat n => Proxy (Cxt n) -> BlockCount Prim
cxtBlockCount :: Proxy (Cxt n) -> BlockCount Prim
cxtBlockCount = Proxy (Buffer n) -> BlockCount Prim
forall (n :: Nat).
KnownNat n =>
Proxy (Buffer n) -> BlockCount Prim
bufferSize (Proxy (Buffer n) -> BlockCount Prim)
-> (Proxy (Cxt n) -> Proxy (Buffer n))
-> Proxy (Cxt n)
-> BlockCount Prim
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cxt n -> Buffer n) -> Proxy (Cxt n) -> Proxy (Buffer n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Cxt n -> Buffer n
forall (n :: Nat). Cxt n -> Buffer n
cxtBuf
cxtSize :: KnownNat n => Proxy (Cxt n) -> BYTES Int
cxtSize :: Proxy (Cxt n) -> BYTES Int
cxtSize = BlockCount Prim -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes (BlockCount Prim -> BYTES Int)
-> (Proxy (Cxt n) -> BlockCount Prim) -> Proxy (Cxt n) -> BYTES Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (Cxt n) -> BlockCount Prim
forall (n :: Nat). KnownNat n => Proxy (Cxt n) -> BlockCount Prim
cxtBlockCount
getCxtBytes :: KnownNat n => Cxt n -> IO (BYTES Int)
getCxtBytes :: Cxt n -> IO (BYTES Int)
getCxtBytes = MemoryCell (BYTES Int) -> IO (BYTES Int)
forall m v. Extractable m v => m -> IO v
extract (MemoryCell (BYTES Int) -> IO (BYTES Int))
-> (Cxt n -> MemoryCell (BYTES Int)) -> Cxt n -> IO (BYTES Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cxt n -> MemoryCell (BYTES Int)
forall (n :: Nat). Cxt n -> MemoryCell (BYTES Int)
cxtAvailableBytes
setBytes :: BYTES Int -> Cxt n -> IO ()
setBytes :: BYTES Int -> Cxt n -> IO ()
setBytes BYTES Int
nbytes = BYTES Int -> MemoryCell (BYTES Int) -> IO ()
forall m v. Initialisable m v => v -> m -> IO ()
initialise BYTES Int
nbytes (MemoryCell (BYTES Int) -> IO ())
-> (Cxt n -> MemoryCell (BYTES Int)) -> Cxt n -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cxt n -> MemoryCell (BYTES Int)
forall (n :: Nat). Cxt n -> MemoryCell (BYTES Int)
cxtAvailableBytes
unsafeSetCxtEmpty :: Cxt n -> IO ()
unsafeSetCxtEmpty :: Cxt n -> IO ()
unsafeSetCxtEmpty Cxt{Internals
MemoryCell (BYTES Int)
Buffer n
cxtAvailableBytes :: MemoryCell (BYTES Int)
cxtBuf :: Buffer n
cxtInternals :: Internals
cxtAvailableBytes :: forall (n :: Nat). Cxt n -> MemoryCell (BYTES Int)
cxtBuf :: forall (n :: Nat). Cxt n -> Buffer n
cxtInternals :: forall (n :: Nat). Cxt n -> Internals
..} = BYTES Int -> MemoryCell (BYTES Int) -> IO ()
forall m v. Initialisable m v => v -> m -> IO ()
initialise (BYTES Int
0 :: BYTES Int) MemoryCell (BYTES Int)
cxtAvailableBytes
unsafeSetCxtFull :: KnownNat n => Cxt n -> IO ()
unsafeSetCxtFull :: Cxt n -> IO ()
unsafeSetCxtFull cxt :: Cxt n
cxt@Cxt{Internals
MemoryCell (BYTES Int)
Buffer n
cxtAvailableBytes :: MemoryCell (BYTES Int)
cxtBuf :: Buffer n
cxtInternals :: Internals
cxtAvailableBytes :: forall (n :: Nat). Cxt n -> MemoryCell (BYTES Int)
cxtBuf :: forall (n :: Nat). Cxt n -> Buffer n
cxtInternals :: forall (n :: Nat). Cxt n -> Internals
..} = BYTES Int -> MemoryCell (BYTES Int) -> IO ()
forall m v. Initialisable m v => v -> m -> IO ()
initialise (Proxy (Cxt n) -> BYTES Int
forall (n :: Nat). KnownNat n => Proxy (Cxt n) -> BYTES Int
cxtSize (Proxy (Cxt n) -> BYTES Int) -> Proxy (Cxt n) -> BYTES Int
forall a b. (a -> b) -> a -> b
$ Cxt n -> Proxy (Cxt n)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Cxt n
cxt) MemoryCell (BYTES Int)
cxtAvailableBytes
unsafeProcessBlocks :: KnownNat n
=> (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n
-> IO ()
unsafeProcessBlocks :: (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeProcessBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
action Cxt{Internals
MemoryCell (BYTES Int)
Buffer n
cxtAvailableBytes :: MemoryCell (BYTES Int)
cxtBuf :: Buffer n
cxtInternals :: Internals
cxtAvailableBytes :: forall (n :: Nat). Cxt n -> MemoryCell (BYTES Int)
cxtBuf :: forall (n :: Nat). Cxt n -> Buffer n
cxtInternals :: forall (n :: Nat). Cxt n -> Internals
..} = (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Buffer n -> Internals -> IO ()
forall (n :: Nat) a.
KnownNat n =>
(BufferPtr -> BlockCount Prim -> a) -> Buffer n -> a
withBufferPtr BufferPtr -> BlockCount Prim -> Internals -> IO ()
action Buffer n
cxtBuf Internals
cxtInternals
unsafeGenerateBlocks :: KnownNat n
=> (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n
-> IO ()
unsafeGenerateBlocks :: (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeGenerateBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
genBlocks Cxt n
cxt = (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
forall (n :: Nat).
KnownNat n =>
(BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeProcessBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
genBlocks Cxt n
cxt IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Cxt n -> IO ()
forall (n :: Nat). KnownNat n => Cxt n -> IO ()
unsafeSetCxtFull Cxt n
cxt
unsafeConsumeBlocks :: KnownNat n
=> (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n
-> IO ()
unsafeConsumeBlocks :: (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeConsumeBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
action Cxt n
cxt = (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
forall (n :: Nat).
KnownNat n =>
(BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeProcessBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
action Cxt n
cxt IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Cxt n -> IO ()
forall (n :: Nat). Cxt n -> IO ()
unsafeSetCxtEmpty Cxt n
cxt
startPtr :: Cxt n -> Ptr Word8
startPtr :: Cxt n -> Ptr Word8
startPtr = (Ptr Word8 -> Ptr Word8)
-> AlignedPtr BufferAlignment (Tuple 16 (LE Word32)) -> Ptr Word8
forall (ptr :: * -> *) a b something.
Pointer ptr =>
(Ptr a -> b) -> ptr something -> b
unsafeWithPointerCast Ptr Word8 -> Ptr Word8
forall a. a -> a
id (AlignedPtr BufferAlignment (Tuple 16 (LE Word32)) -> Ptr Word8)
-> (Cxt n -> AlignedPtr BufferAlignment (Tuple 16 (LE Word32)))
-> Cxt n
-> Ptr Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Buffer n -> AlignedPtr BufferAlignment (Tuple 16 (LE Word32))
forall (n :: Nat). Buffer n -> BufferPtr
unsafeGetBufferPointer (Buffer n -> AlignedPtr BufferAlignment (Tuple 16 (LE Word32)))
-> (Cxt n -> Buffer n)
-> Cxt n
-> AlignedPtr BufferAlignment (Tuple 16 (LE Word32))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cxt n -> Buffer n
forall (n :: Nat). Cxt n -> Buffer n
cxtBuf
unsafeWriteTo :: KnownNat n
=> BYTES Int
-> Dest (Ptr Word8)
-> Cxt n
-> IO (BYTES Int)
unsafeWriteTo :: BYTES Int -> Dest (Ptr Word8) -> Cxt n -> IO (BYTES Int)
unsafeWriteTo BYTES Int
req Dest (Ptr Word8)
dbuf Cxt n
cxt = do
BYTES Int
ava <- Cxt n -> IO (BYTES Int)
forall (n :: Nat). KnownNat n => Cxt n -> IO (BYTES Int)
getCxtBytes Cxt n
cxt
let satisfy :: BYTES Int
satisfy = BYTES Int -> BYTES Int -> BYTES Int
forall a. Ord a => a -> a -> a
min BYTES Int
req BYTES Int
ava
leftover :: BYTES Int
leftover = BYTES Int
ava BYTES Int -> BYTES Int -> BYTES Int
forall a. Num a => a -> a -> a
- BYTES Int
satisfy
srcPtr :: Ptr Word8
srcPtr = Cxt n -> Ptr Word8
forall (n :: Nat). Cxt n -> Ptr Word8
startPtr Cxt n
cxt Ptr Word8 -> BYTES Int -> Ptr Word8
forall l a. LengthUnit l => Ptr a -> l -> Ptr a
`movePtr` BYTES Int
leftover
in do Dest (Ptr Word8) -> Src (Ptr Word8) -> BYTES Int -> IO ()
forall l (ptrS :: * -> *) (ptrD :: * -> *) dest src.
(LengthUnit l, Pointer ptrS, Pointer ptrD) =>
Dest (ptrD dest) -> Src (ptrS src) -> l -> IO ()
memcpy Dest (Ptr Word8)
dbuf (Ptr Word8 -> Src (Ptr Word8)
forall a. a -> Src a
source Ptr Word8
srcPtr) BYTES Int
satisfy
Ptr Word8 -> BYTES Int -> IO ()
forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO ()
wipeMemory Ptr Word8
srcPtr BYTES Int
satisfy
BYTES Int -> Cxt n -> IO ()
forall (n :: Nat). BYTES Int -> Cxt n -> IO ()
setBytes BYTES Int
leftover Cxt n
cxt
BYTES Int -> IO (BYTES Int)
forall (m :: * -> *) a. Monad m => a -> m a
return BYTES Int
satisfy
unsafeFillFrom :: (KnownNat n, ByteSource src)
=> src
-> Cxt n
-> IO (FillResult src)
unsafeFillFrom :: src -> Cxt n -> IO (FillResult src)
unsafeFillFrom src
src Cxt n
cxt = do
BYTES Int
ava <- Cxt n -> IO (BYTES Int)
forall (n :: Nat). KnownNat n => Cxt n -> IO (BYTES Int)
getCxtBytes Cxt n
cxt
let vacant :: BYTES Int
vacant = Proxy (Cxt n) -> BYTES Int
forall (n :: Nat). KnownNat n => Proxy (Cxt n) -> BYTES Int
cxtSize (Cxt n -> Proxy (Cxt n)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Cxt n
cxt) BYTES Int -> BYTES Int -> BYTES Int
forall a. Num a => a -> a -> a
- BYTES Int
ava
destPtr :: Ptr Word8
destPtr = Cxt n -> Ptr Word8
forall (n :: Nat). Cxt n -> Ptr Word8
startPtr Cxt n
cxt Ptr Word8 -> BYTES Int -> Ptr Word8
forall l a. LengthUnit l => Ptr a -> l -> Ptr a
`movePtr` BYTES Int
ava
srcExhausted :: BYTES Int -> IO (FillResult src)
srcExhausted BYTES Int
trfed = BYTES Int -> Cxt n -> IO ()
forall (n :: Nat). BYTES Int -> Cxt n -> IO ()
setBytes (BYTES Int
ava BYTES Int -> BYTES Int -> BYTES Int
forall a. Num a => a -> a -> a
+ BYTES Int
trfed) Cxt n
cxt IO () -> IO (FillResult src) -> IO (FillResult src)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FillResult src -> IO (FillResult src)
forall (m :: * -> *) a. Monad m => a -> m a
return (BYTES Int -> FillResult src
forall a. BYTES Int -> FillResult a
Exhausted BYTES Int
trfed)
srcRemaining :: src -> IO (FillResult src)
srcRemaining src
remSrc = Cxt n -> IO ()
forall (n :: Nat). KnownNat n => Cxt n -> IO ()
unsafeSetCxtFull Cxt n
cxt IO () -> IO (FillResult src) -> IO (FillResult src)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FillResult src -> IO (FillResult src)
forall (m :: * -> *) a. Monad m => a -> m a
return (src -> FillResult src
forall a. a -> FillResult a
Remaining src
remSrc)
in BYTES Int -> src -> Ptr Word8 -> IO (FillResult src)
forall src a.
ByteSource src =>
BYTES Int -> src -> Ptr a -> IO (FillResult src)
fillBytes BYTES Int
vacant src
src Ptr Word8
destPtr IO (FillResult src)
-> (FillResult src -> IO (FillResult src)) -> IO (FillResult src)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (src -> IO (FillResult src))
-> (BYTES Int -> IO (FillResult src))
-> FillResult src
-> IO (FillResult src)
forall a b. (a -> b) -> (BYTES Int -> b) -> FillResult a -> b
withFillResult src -> IO (FillResult src)
srcRemaining BYTES Int -> IO (FillResult src)
srcExhausted
unsafeContinue :: (KnownNat n, ByteSource src)
=> (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> src
-> Cxt n
-> IO ()
unsafeContinue :: (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> src -> Cxt n -> IO ()
unsafeContinue BufferPtr -> BlockCount Prim -> Internals -> IO ()
action src
src Cxt n
cxt = IO ()
-> (BYTES Int -> IO ()) -> src -> Ptr Word8 -> BYTES Int -> IO ()
forall (ptr :: * -> *) (m :: * -> *) chunkSize src a b something.
(Pointer ptr, MonadIO m, LengthUnit chunkSize, ByteSource src) =>
m a
-> (BYTES Int -> m b) -> src -> ptr something -> chunkSize -> m b
processChunks IO ()
actFilled BYTES Int -> IO ()
lastChunk src
src Ptr Word8
bufPtr BYTES Int
bufSize
where actFilled :: IO ()
actFilled = (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
forall (n :: Nat).
KnownNat n =>
(BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeProcessBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
action Cxt n
cxt
lastChunk :: BYTES Int -> IO ()
lastChunk BYTES Int
nbytes = BYTES Int -> Cxt n -> IO ()
forall (n :: Nat). BYTES Int -> Cxt n -> IO ()
setBytes BYTES Int
nbytes Cxt n
cxt
bufPtr :: Ptr Word8
bufPtr = Cxt n -> Ptr Word8
forall (n :: Nat). Cxt n -> Ptr Word8
startPtr Cxt n
cxt
bufSize :: BYTES Int
bufSize = Proxy (Cxt n) -> BYTES Int
forall (n :: Nat). KnownNat n => Proxy (Cxt n) -> BYTES Int
cxtSize (Proxy (Cxt n) -> BYTES Int) -> Proxy (Cxt n) -> BYTES Int
forall a b. (a -> b) -> a -> b
$ Cxt n -> Proxy (Cxt n)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Cxt n
cxt
unsafeUpdate :: (KnownNat n, ByteSource src)
=> (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> src
-> Cxt n
-> IO ()
unsafeUpdate :: (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> src -> Cxt n -> IO ()
unsafeUpdate BufferPtr -> BlockCount Prim -> Internals -> IO ()
action src
src Cxt n
cxt =
src -> Cxt n -> IO (FillResult src)
forall (n :: Nat) src.
(KnownNat n, ByteSource src) =>
src -> Cxt n -> IO (FillResult src)
unsafeFillFrom src
src Cxt n
cxt IO (FillResult src) -> (FillResult src -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (src -> IO ()) -> (BYTES Int -> IO ()) -> FillResult src -> IO ()
forall a b. (a -> b) -> (BYTES Int -> b) -> FillResult a -> b
withFillResult src -> IO ()
process BYTES Int -> IO ()
forall b. b -> IO ()
doNothing
where doNothing :: b -> IO ()
doNothing = IO () -> b -> IO ()
forall a b. a -> b -> a
const (IO () -> b -> IO ()) -> IO () -> b -> IO ()
forall a b. (a -> b) -> a -> b
$ () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
process :: src -> IO ()
process src
remSrc = (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
forall (n :: Nat).
KnownNat n =>
(BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> Cxt n -> IO ()
unsafeConsumeBlocks BufferPtr -> BlockCount Prim -> Internals -> IO ()
action Cxt n
cxt IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> src -> Cxt n -> IO ()
forall (n :: Nat) src.
(KnownNat n, ByteSource src) =>
(BufferPtr -> BlockCount Prim -> Internals -> IO ())
-> src -> Cxt n -> IO ()
unsafeContinue BufferPtr -> BlockCount Prim -> Internals -> IO ()
action src
remSrc Cxt n
cxt
unsafeFinalise :: KnownNat n
=> (BufferPtr -> BYTES Int -> Internals -> IO ())
-> Cxt n
-> IO ()
unsafeFinalise :: (BufferPtr -> BYTES Int -> Internals -> IO ()) -> Cxt n -> IO ()
unsafeFinalise BufferPtr -> BYTES Int -> Internals -> IO ()
action cxt :: Cxt n
cxt@Cxt{Internals
MemoryCell (BYTES Int)
Buffer n
cxtAvailableBytes :: MemoryCell (BYTES Int)
cxtBuf :: Buffer n
cxtInternals :: Internals
cxtAvailableBytes :: forall (n :: Nat). Cxt n -> MemoryCell (BYTES Int)
cxtBuf :: forall (n :: Nat). Cxt n -> Buffer n
cxtInternals :: forall (n :: Nat). Cxt n -> Internals
..} = do
BYTES Int
ava <- Cxt n -> IO (BYTES Int)
forall (n :: Nat). KnownNat n => Cxt n -> IO (BYTES Int)
getCxtBytes Cxt n
cxt
(BufferPtr -> BYTES Int -> Internals -> IO ())
-> Buffer n -> BYTES Int -> Internals -> IO ()
forall (n :: Nat) a.
KnownNat n =>
(BufferPtr -> a) -> Buffer n -> a
unsafeWithBufferPtr BufferPtr -> BYTES Int -> Internals -> IO ()
action Buffer n
cxtBuf BYTES Int
ava Internals
cxtInternals