-- Produced by boxnd-gen; edit the generator, not this file.

module Box3D.Recording
  ( create
  , destroy
  , getData
  , getSize
  )

  where

import Foreign
import Foreign.C.Types (CInt(..))
import Box3D.Tags (Recording)

foreign import ccall unsafe "b3CreateRecording"
  c_b3CreateRecording :: CInt -> IO (Ptr Recording)

foreign import ccall unsafe "b3DestroyRecording"
  c_b3DestroyRecording :: Ptr Recording -> IO ()

foreign import ccall unsafe "b3Recording_GetData"
  c_b3Recording_GetData :: Ptr Recording -> IO (Ptr Word8)

foreign import ccall unsafe "b3Recording_GetSize"
  c_b3Recording_GetSize :: Ptr Recording -> IO CInt

{- | Create a recording buffer with an optional initial byte capacity.
Pass 0 to use the default (64 KiB). The buffer grows on demand.

Returns: a new recording, owned by the caller

Binds @b3CreateRecording@.
-}
create
  :: Int
  -- ^ @byteCapacity@
  -> IO (Ptr Recording)
create :: Int -> IO (Ptr Recording)
create Int
a0 =
  CInt -> IO (Ptr Recording)
c_b3CreateRecording (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a0)

{- | Destroy a recording and free its buffer.

Binds @b3DestroyRecording@.
-}
destroy
  :: Ptr Recording
  -- ^ @recording@: may be NULL
  -> IO ()
destroy :: Ptr Recording -> IO ()
destroy Ptr Recording
a0 =
  Ptr Recording -> IO ()
c_b3DestroyRecording Ptr Recording
a0

{- | Get a pointer to the raw recording bytes.
Valid until the recording buffer is modified or destroyed.

Returns: pointer to the byte buffer, or NULL if no bytes have been written

Binds @b3Recording_GetData@.
-}
getData
  :: Ptr Recording
  -- ^ @recording@: the recording handle
  -> IO (Ptr Word8)
getData :: Ptr Recording -> IO (Ptr Word8)
getData Ptr Recording
a0 =
  Ptr Recording -> IO (Ptr Word8)
c_b3Recording_GetData Ptr Recording
a0

{- | Get the number of bytes currently in the recording buffer.

Binds @b3Recording_GetSize@.
-}
getSize
  :: Ptr Recording
  -- ^ @recording@: the recording handle
  -> IO Int
getSize :: Ptr Recording -> IO Int
getSize Ptr Recording
a0 =
  CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr Recording -> IO CInt
c_b3Recording_GetSize Ptr Recording
a0)