{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

'GI.GstBase.Structs.BitWriter.BitWriter' provides a bit writer that can write any number of
bits into a memory buffer. It provides functions for writing any
number of bits into 8, 16, 32 and 64 bit variables.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.GstBase.Structs.BitWriter
    (

-- * Exported types
    BitWriter(..)                           ,
    newZeroBitWriter                        ,
    noBitWriter                             ,


 -- * Methods
-- ** alignBytes #method:alignBytes#

#if ENABLE_OVERLOADING
    BitWriterAlignBytesMethodInfo           ,
#endif
    bitWriterAlignBytes                     ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    BitWriterFreeMethodInfo                 ,
#endif
    bitWriterFree                           ,


-- ** freeAndGetBuffer #method:freeAndGetBuffer#

#if ENABLE_OVERLOADING
    BitWriterFreeAndGetBufferMethodInfo     ,
#endif
    bitWriterFreeAndGetBuffer               ,


-- ** getData #method:getData#

#if ENABLE_OVERLOADING
    BitWriterGetDataMethodInfo              ,
#endif
    bitWriterGetData                        ,


-- ** getRemaining #method:getRemaining#

#if ENABLE_OVERLOADING
    BitWriterGetRemainingMethodInfo         ,
#endif
    bitWriterGetRemaining                   ,


-- ** getSize #method:getSize#

#if ENABLE_OVERLOADING
    BitWriterGetSizeMethodInfo              ,
#endif
    bitWriterGetSize                        ,


-- ** putBitsUint16 #method:putBitsUint16#

#if ENABLE_OVERLOADING
    BitWriterPutBitsUint16MethodInfo        ,
#endif
    bitWriterPutBitsUint16                  ,


-- ** putBitsUint32 #method:putBitsUint32#

#if ENABLE_OVERLOADING
    BitWriterPutBitsUint32MethodInfo        ,
#endif
    bitWriterPutBitsUint32                  ,


-- ** putBitsUint64 #method:putBitsUint64#

#if ENABLE_OVERLOADING
    BitWriterPutBitsUint64MethodInfo        ,
#endif
    bitWriterPutBitsUint64                  ,


-- ** putBitsUint8 #method:putBitsUint8#

#if ENABLE_OVERLOADING
    BitWriterPutBitsUint8MethodInfo         ,
#endif
    bitWriterPutBitsUint8                   ,


-- ** putBytes #method:putBytes#

#if ENABLE_OVERLOADING
    BitWriterPutBytesMethodInfo             ,
#endif
    bitWriterPutBytes                       ,


-- ** reset #method:reset#

#if ENABLE_OVERLOADING
    BitWriterResetMethodInfo                ,
#endif
    bitWriterReset                          ,


-- ** resetAndGetBuffer #method:resetAndGetBuffer#

#if ENABLE_OVERLOADING
    BitWriterResetAndGetBufferMethodInfo    ,
#endif
    bitWriterResetAndGetBuffer              ,


-- ** setPos #method:setPos#

#if ENABLE_OVERLOADING
    BitWriterSetPosMethodInfo               ,
#endif
    bitWriterSetPos                         ,




 -- * Properties
-- ** bitSize #attr:bitSize#
{- | Size of written /@data@/ in bits
-}
#if ENABLE_OVERLOADING
    bitWriter_bitSize                       ,
#endif
    getBitWriterBitSize                     ,
    setBitWriterBitSize                     ,


-- ** data #attr:data#
{- | Allocated /@data@/ for bit writer to write
-}
#if ENABLE_OVERLOADING
    bitWriter_data                          ,
#endif
    getBitWriterData                        ,
    setBitWriterData                        ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.Gst.Structs.Buffer as Gst.Buffer

-- | Memory-managed wrapper type.
newtype BitWriter = BitWriter (ManagedPtr BitWriter)
instance WrappedPtr BitWriter where
    wrappedPtrCalloc = callocBytes 56
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 56 >=> wrapPtr BitWriter)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `BitWriter` struct initialized to zero.
newZeroBitWriter :: MonadIO m => m BitWriter
newZeroBitWriter = liftIO $ wrappedPtrCalloc >>= wrapPtr BitWriter

instance tag ~ 'AttrSet => Constructible BitWriter tag where
    new _ attrs = do
        o <- newZeroBitWriter
        GI.Attributes.set o attrs
        return o


-- | A convenience alias for `Nothing` :: `Maybe` `BitWriter`.
noBitWriter :: Maybe BitWriter
noBitWriter = Nothing

{- |
Get the value of the “@data@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' bitWriter #data
@
-}
getBitWriterData :: MonadIO m => BitWriter -> m Word8
getBitWriterData s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Word8
    return val

{- |
Set the value of the “@data@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' bitWriter [ #data 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBitWriterData :: MonadIO m => BitWriter -> Word8 -> m ()
setBitWriterData s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Word8)

#if ENABLE_OVERLOADING
data BitWriterDataFieldInfo
instance AttrInfo BitWriterDataFieldInfo where
    type AttrAllowedOps BitWriterDataFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BitWriterDataFieldInfo = (~) Word8
    type AttrBaseTypeConstraint BitWriterDataFieldInfo = (~) BitWriter
    type AttrGetType BitWriterDataFieldInfo = Word8
    type AttrLabel BitWriterDataFieldInfo = "data"
    type AttrOrigin BitWriterDataFieldInfo = BitWriter
    attrGet _ = getBitWriterData
    attrSet _ = setBitWriterData
    attrConstruct = undefined
    attrClear _ = undefined

bitWriter_data :: AttrLabelProxy "data"
bitWriter_data = AttrLabelProxy

#endif


{- |
Get the value of the “@bit_size@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' bitWriter #bitSize
@
-}
getBitWriterBitSize :: MonadIO m => BitWriter -> m Word32
getBitWriterBitSize s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Word32
    return val

{- |
Set the value of the “@bit_size@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' bitWriter [ #bitSize 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBitWriterBitSize :: MonadIO m => BitWriter -> Word32 -> m ()
setBitWriterBitSize s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Word32)

#if ENABLE_OVERLOADING
data BitWriterBitSizeFieldInfo
instance AttrInfo BitWriterBitSizeFieldInfo where
    type AttrAllowedOps BitWriterBitSizeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BitWriterBitSizeFieldInfo = (~) Word32
    type AttrBaseTypeConstraint BitWriterBitSizeFieldInfo = (~) BitWriter
    type AttrGetType BitWriterBitSizeFieldInfo = Word32
    type AttrLabel BitWriterBitSizeFieldInfo = "bit_size"
    type AttrOrigin BitWriterBitSizeFieldInfo = BitWriter
    attrGet _ = getBitWriterBitSize
    attrSet _ = setBitWriterBitSize
    attrConstruct = undefined
    attrClear _ = undefined

bitWriter_bitSize :: AttrLabelProxy "bitSize"
bitWriter_bitSize = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList BitWriter
type instance O.AttributeList BitWriter = BitWriterAttributeList
type BitWriterAttributeList = ('[ '("data", BitWriterDataFieldInfo), '("bitSize", BitWriterBitSizeFieldInfo)] :: [(Symbol, *)])
#endif

-- method BitWriter::align_bytes
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "trailing_bit", argType = TBasicType TUInt8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "trailing bits of last byte, 0 or 1", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_align_bytes" gst_bit_writer_align_bytes ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word8 ->                                -- trailing_bit : TBasicType TUInt8
    IO CInt

{- |
Write trailing bit to align last byte of /@data@/. /@trailingBit@/ can
only be 1 or 0.
-}
bitWriterAlignBytes ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> Word8
    {- ^ /@trailingBit@/: trailing bits of last byte, 0 or 1 -}
    -> m Bool
    {- ^ __Returns:__ 'True' if successful, 'False' otherwise. -}
bitWriterAlignBytes bitwriter trailingBit = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_align_bytes bitwriter' trailingBit
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterAlignBytesMethodInfo
instance (signature ~ (Word8 -> m Bool), MonadIO m) => O.MethodInfo BitWriterAlignBytesMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterAlignBytes

#endif

-- method BitWriter::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "#GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_free" gst_bit_writer_free ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO ()

{- |
Frees /@bitwriter@/ and the allocated data inside.
-}
bitWriterFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> m ()
bitWriterFree bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    gst_bit_writer_free bitwriter'
    touchManagedPtr bitwriter
    return ()

#if ENABLE_OVERLOADING
data BitWriterFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo BitWriterFreeMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterFree

#endif

-- method BitWriter::free_and_get_buffer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "#GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Buffer"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_free_and_get_buffer" gst_bit_writer_free_and_get_buffer ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO (Ptr Gst.Buffer.Buffer)

{- |
Frees /@bitwriter@/ without destroying the internal data, which is
returned as 'GI.Gst.Structs.Buffer.Buffer'.

Free-function: gst_buffer_unref
-}
bitWriterFreeAndGetBuffer ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> m Gst.Buffer.Buffer
    {- ^ __Returns:__ a new allocated 'GI.Gst.Structs.Buffer.Buffer' wrapping the
    data inside. @/gst_buffer_unref()/@ after usage. -}
bitWriterFreeAndGetBuffer bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_free_and_get_buffer bitwriter'
    checkUnexpectedReturnNULL "bitWriterFreeAndGetBuffer" result
    result' <- (wrapBoxed Gst.Buffer.Buffer) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterFreeAndGetBufferMethodInfo
instance (signature ~ (m Gst.Buffer.Buffer), MonadIO m) => O.MethodInfo BitWriterFreeAndGetBufferMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterFreeAndGetBuffer

#endif

-- XXX Could not generate method BitWriter::free_and_get_data
-- Error was : Bad introspection data: "`TCArray False (-1) (-1) (TBasicType TUInt8)' is an array type, but contains no length information,\nso it cannot be unpacked."
-- method BitWriter::get_data
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt8)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_get_data" gst_bit_writer_get_data ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO Word8

{- |
Get written data pointer
-}
bitWriterGetData ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> m Word8
    {- ^ __Returns:__ data pointer -}
bitWriterGetData bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_get_data bitwriter'
    touchManagedPtr bitwriter
    return result

#if ENABLE_OVERLOADING
data BitWriterGetDataMethodInfo
instance (signature ~ (m Word8), MonadIO m) => O.MethodInfo BitWriterGetDataMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterGetData

#endif

-- method BitWriter::get_remaining
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_get_remaining" gst_bit_writer_get_remaining ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO Word32

{- |
/No description available in the introspection data./
-}
bitWriterGetRemaining ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    -> m Word32
bitWriterGetRemaining bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_get_remaining bitwriter'
    touchManagedPtr bitwriter
    return result

#if ENABLE_OVERLOADING
data BitWriterGetRemainingMethodInfo
instance (signature ~ (m Word32), MonadIO m) => O.MethodInfo BitWriterGetRemainingMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterGetRemaining

#endif

-- method BitWriter::get_size
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_get_size" gst_bit_writer_get_size ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO Word32

{- |
Get size of written /@data@/
-}
bitWriterGetSize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> m Word32
    {- ^ __Returns:__ size of bits written in /@data@/ -}
bitWriterGetSize bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_get_size bitwriter'
    touchManagedPtr bitwriter
    return result

#if ENABLE_OVERLOADING
data BitWriterGetSizeMethodInfo
instance (signature ~ (m Word32), MonadIO m) => O.MethodInfo BitWriterGetSizeMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterGetSize

#endif

-- method BitWriter::put_bits_uint16
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "value of #guint16 to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbits", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bits to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_put_bits_uint16" gst_bit_writer_put_bits_uint16 ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word16 ->                               -- value : TBasicType TUInt16
    Word32 ->                               -- nbits : TBasicType TUInt
    IO CInt

{- |
Write /@nbits@/ bits of /@value@/ to 'GI.GstBase.Structs.BitWriter.BitWriter'.
-}
bitWriterPutBitsUint16 ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> Word16
    {- ^ /@value@/: value of @/guint16/@ to write -}
    -> Word32
    {- ^ /@nbits@/: number of bits to write -}
    -> m Bool
    {- ^ __Returns:__ 'True' if successful, 'False' otherwise. -}
bitWriterPutBitsUint16 bitwriter value nbits = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_put_bits_uint16 bitwriter' value nbits
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterPutBitsUint16MethodInfo
instance (signature ~ (Word16 -> Word32 -> m Bool), MonadIO m) => O.MethodInfo BitWriterPutBitsUint16MethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterPutBitsUint16

#endif

-- method BitWriter::put_bits_uint32
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "value of #guint32 to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbits", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bits to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_put_bits_uint32" gst_bit_writer_put_bits_uint32 ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word32 ->                               -- value : TBasicType TUInt32
    Word32 ->                               -- nbits : TBasicType TUInt
    IO CInt

{- |
Write /@nbits@/ bits of /@value@/ to 'GI.GstBase.Structs.BitWriter.BitWriter'.
-}
bitWriterPutBitsUint32 ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> Word32
    {- ^ /@value@/: value of @/guint32/@ to write -}
    -> Word32
    {- ^ /@nbits@/: number of bits to write -}
    -> m Bool
    {- ^ __Returns:__ 'True' if successful, 'False' otherwise. -}
bitWriterPutBitsUint32 bitwriter value nbits = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_put_bits_uint32 bitwriter' value nbits
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterPutBitsUint32MethodInfo
instance (signature ~ (Word32 -> Word32 -> m Bool), MonadIO m) => O.MethodInfo BitWriterPutBitsUint32MethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterPutBitsUint32

#endif

-- method BitWriter::put_bits_uint64
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "value of #guint64 to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbits", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bits to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_put_bits_uint64" gst_bit_writer_put_bits_uint64 ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word64 ->                               -- value : TBasicType TUInt64
    Word32 ->                               -- nbits : TBasicType TUInt
    IO CInt

{- |
Write /@nbits@/ bits of /@value@/ to 'GI.GstBase.Structs.BitWriter.BitWriter'.
-}
bitWriterPutBitsUint64 ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> Word64
    {- ^ /@value@/: value of @/guint64/@ to write -}
    -> Word32
    {- ^ /@nbits@/: number of bits to write -}
    -> m Bool
    {- ^ __Returns:__ 'True' if successful, 'False' otherwise. -}
bitWriterPutBitsUint64 bitwriter value nbits = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_put_bits_uint64 bitwriter' value nbits
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterPutBitsUint64MethodInfo
instance (signature ~ (Word64 -> Word32 -> m Bool), MonadIO m) => O.MethodInfo BitWriterPutBitsUint64MethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterPutBitsUint64

#endif

-- method BitWriter::put_bits_uint8
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUInt8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "value of #guint8 to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbits", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bits to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_put_bits_uint8" gst_bit_writer_put_bits_uint8 ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word8 ->                                -- value : TBasicType TUInt8
    Word32 ->                               -- nbits : TBasicType TUInt
    IO CInt

{- |
Write /@nbits@/ bits of /@value@/ to 'GI.GstBase.Structs.BitWriter.BitWriter'.
-}
bitWriterPutBitsUint8 ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> Word8
    {- ^ /@value@/: value of @/guint8/@ to write -}
    -> Word32
    {- ^ /@nbits@/: number of bits to write -}
    -> m Bool
    {- ^ __Returns:__ 'True' if successful, 'False' otherwise. -}
bitWriterPutBitsUint8 bitwriter value nbits = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_put_bits_uint8 bitwriter' value nbits
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterPutBitsUint8MethodInfo
instance (signature ~ (Word8 -> Word32 -> m Bool), MonadIO m) => O.MethodInfo BitWriterPutBitsUint8MethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterPutBitsUint8

#endif

-- method BitWriter::put_bytes
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TUInt8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer of data to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes to write", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_put_bytes" gst_bit_writer_put_bytes ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word8 ->                                -- data : TBasicType TUInt8
    Word32 ->                               -- nbytes : TBasicType TUInt
    IO CInt

{- |
Write /@nbytes@/ bytes of /@data@/ to 'GI.GstBase.Structs.BitWriter.BitWriter'.
-}
bitWriterPutBytes ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> Word8
    {- ^ /@data@/: pointer of data to write -}
    -> Word32
    {- ^ /@nbytes@/: number of bytes to write -}
    -> m Bool
    {- ^ __Returns:__ 'True' if successful, 'False' otherwise. -}
bitWriterPutBytes bitwriter data_ nbytes = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_put_bytes bitwriter' data_ nbytes
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterPutBytesMethodInfo
instance (signature ~ (Word8 -> Word32 -> m Bool), MonadIO m) => O.MethodInfo BitWriterPutBytesMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterPutBytes

#endif

-- method BitWriter::reset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "#GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_reset" gst_bit_writer_reset ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO ()

{- |
Resets /@bitwriter@/ and frees the data if it\'s owned by /@bitwriter@/.
-}
bitWriterReset ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> m ()
bitWriterReset bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    gst_bit_writer_reset bitwriter'
    touchManagedPtr bitwriter
    return ()

#if ENABLE_OVERLOADING
data BitWriterResetMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo BitWriterResetMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterReset

#endif

-- method BitWriter::reset_and_get_buffer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBitWriter instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Buffer"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_reset_and_get_buffer" gst_bit_writer_reset_and_get_buffer ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    IO (Ptr Gst.Buffer.Buffer)

{- |
Resets /@bitwriter@/ and returns the current data as 'GI.Gst.Structs.Buffer.Buffer'.

Free-function: gst_buffer_unref
-}
bitWriterResetAndGetBuffer ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    {- ^ /@bitwriter@/: a 'GI.GstBase.Structs.BitWriter.BitWriter' instance -}
    -> m Gst.Buffer.Buffer
    {- ^ __Returns:__ a new allocated 'GI.Gst.Structs.Buffer.Buffer' wrapping the
    current data. @/gst_buffer_unref()/@ after usage. -}
bitWriterResetAndGetBuffer bitwriter = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_reset_and_get_buffer bitwriter'
    checkUnexpectedReturnNULL "bitWriterResetAndGetBuffer" result
    result' <- (wrapBoxed Gst.Buffer.Buffer) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterResetAndGetBufferMethodInfo
instance (signature ~ (m Gst.Buffer.Buffer), MonadIO m) => O.MethodInfo BitWriterResetAndGetBufferMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterResetAndGetBuffer

#endif

-- XXX Could not generate method BitWriter::reset_and_get_data
-- Error was : Bad introspection data: "`TCArray False (-1) (-1) (TBasicType TUInt8)' is an array type, but contains no length information,\nso it cannot be unpacked."
-- method BitWriter::set_pos
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "bitwriter", argType = TInterface (Name {namespace = "GstBase", name = "BitWriter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pos", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_bit_writer_set_pos" gst_bit_writer_set_pos ::
    Ptr BitWriter ->                        -- bitwriter : TInterface (Name {namespace = "GstBase", name = "BitWriter"})
    Word32 ->                               -- pos : TBasicType TUInt
    IO CInt

{- |
/No description available in the introspection data./
-}
bitWriterSetPos ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    BitWriter
    -> Word32
    -> m Bool
bitWriterSetPos bitwriter pos = liftIO $ do
    bitwriter' <- unsafeManagedPtrGetPtr bitwriter
    result <- gst_bit_writer_set_pos bitwriter' pos
    let result' = (/= 0) result
    touchManagedPtr bitwriter
    return result'

#if ENABLE_OVERLOADING
data BitWriterSetPosMethodInfo
instance (signature ~ (Word32 -> m Bool), MonadIO m) => O.MethodInfo BitWriterSetPosMethodInfo BitWriter signature where
    overloadedMethod _ = bitWriterSetPos

#endif

#if ENABLE_OVERLOADING
type family ResolveBitWriterMethod (t :: Symbol) (o :: *) :: * where
    ResolveBitWriterMethod "alignBytes" o = BitWriterAlignBytesMethodInfo
    ResolveBitWriterMethod "free" o = BitWriterFreeMethodInfo
    ResolveBitWriterMethod "freeAndGetBuffer" o = BitWriterFreeAndGetBufferMethodInfo
    ResolveBitWriterMethod "putBitsUint16" o = BitWriterPutBitsUint16MethodInfo
    ResolveBitWriterMethod "putBitsUint32" o = BitWriterPutBitsUint32MethodInfo
    ResolveBitWriterMethod "putBitsUint64" o = BitWriterPutBitsUint64MethodInfo
    ResolveBitWriterMethod "putBitsUint8" o = BitWriterPutBitsUint8MethodInfo
    ResolveBitWriterMethod "putBytes" o = BitWriterPutBytesMethodInfo
    ResolveBitWriterMethod "reset" o = BitWriterResetMethodInfo
    ResolveBitWriterMethod "resetAndGetBuffer" o = BitWriterResetAndGetBufferMethodInfo
    ResolveBitWriterMethod "getData" o = BitWriterGetDataMethodInfo
    ResolveBitWriterMethod "getRemaining" o = BitWriterGetRemainingMethodInfo
    ResolveBitWriterMethod "getSize" o = BitWriterGetSizeMethodInfo
    ResolveBitWriterMethod "setPos" o = BitWriterSetPosMethodInfo
    ResolveBitWriterMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveBitWriterMethod t BitWriter, O.MethodInfo info BitWriter p) => OL.IsLabel t (BitWriter -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif