gi-glib-0.2.46.13: GI/GLib/Structs/ByteArray.hs
{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
Contains the public fields of a GByteArray.
-}
module GI.GLib.Structs.ByteArray
(
-- * Exported types
ByteArray(..) ,
newZeroByteArray ,
noByteArray ,
-- * Methods
-- ** byteArrayFree
byteArrayFree ,
-- ** byteArrayFreeToBytes
byteArrayFreeToBytes ,
-- ** byteArrayNew
byteArrayNew ,
-- ** byteArrayNewTake
byteArrayNewTake ,
-- ** byteArrayUnref
byteArrayUnref ,
-- * Properties
-- ** Data
byteArrayReadData ,
-- ** Len
byteArrayReadLen ,
) where
import Prelude ()
import Data.GI.Base.ShortPrelude
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import GI.GLib.Types
import GI.GLib.Callbacks
newtype ByteArray = ByteArray (ForeignPtr ByteArray)
foreign import ccall "g_byte_array_get_type" c_g_byte_array_get_type ::
IO GType
instance BoxedObject ByteArray where
boxedType _ = c_g_byte_array_get_type
-- | Construct a `ByteArray` struct initialized to zero.
newZeroByteArray :: MonadIO m => m ByteArray
newZeroByteArray = liftIO $ callocBoxedBytes 16 >>= wrapBoxed ByteArray
noByteArray :: Maybe ByteArray
noByteArray = Nothing
byteArrayReadData :: ByteArray -> IO Word8
byteArrayReadData s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO Word8
return val
byteArrayReadLen :: ByteArray -> IO Word32
byteArrayReadLen s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 8) :: IO Word32
return val
-- method ByteArray::free
-- method type : MemberFunction
-- Args : [Arg {argCName = "array", argType = TByteArray, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "free_segment", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TUInt8
-- throws : False
-- Skip return : False
foreign import ccall "g_byte_array_free" g_byte_array_free ::
Ptr GByteArray -> -- array : TByteArray
CInt -> -- free_segment : TBasicType TBoolean
IO Word8
byteArrayFree ::
(MonadIO m) =>
ByteString -- array
-> Bool -- freeSegment
-> m Word8 -- result
byteArrayFree array freeSegment = liftIO $ do
array' <- packGByteArray array
let freeSegment' = (fromIntegral . fromEnum) freeSegment
result <- g_byte_array_free array' freeSegment'
unrefGByteArray array'
return result
-- method ByteArray::free_to_bytes
-- method type : MemberFunction
-- Args : [Arg {argCName = "array", argType = TByteArray, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : TInterface "GLib" "Bytes"
-- throws : False
-- Skip return : False
foreign import ccall "g_byte_array_free_to_bytes" g_byte_array_free_to_bytes ::
Ptr GByteArray -> -- array : TByteArray
IO (Ptr Bytes)
byteArrayFreeToBytes ::
(MonadIO m) =>
ByteString -- array
-> m Bytes -- result
byteArrayFreeToBytes array = liftIO $ do
array' <- packGByteArray array
result <- g_byte_array_free_to_bytes array'
checkUnexpectedReturnNULL "g_byte_array_free_to_bytes" result
result' <- (wrapBoxed Bytes) result
return result'
-- method ByteArray::new
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : TByteArray
-- throws : False
-- Skip return : False
foreign import ccall "g_byte_array_new" g_byte_array_new ::
IO (Ptr GByteArray)
byteArrayNew ::
(MonadIO m) =>
m ByteString -- result
byteArrayNew = liftIO $ do
result <- g_byte_array_new
checkUnexpectedReturnNULL "g_byte_array_new" result
result' <- unpackGByteArray result
unrefGByteArray result
return result'
-- method ByteArray::new_take
-- method type : MemberFunction
-- Args : [Arg {argCName = "data", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "len", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "len", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : TByteArray
-- throws : False
-- Skip return : False
foreign import ccall "g_byte_array_new_take" g_byte_array_new_take ::
Ptr Word8 -> -- data : TCArray False (-1) 1 (TBasicType TUInt8)
Word64 -> -- len : TBasicType TUInt64
IO (Ptr GByteArray)
byteArrayNewTake ::
(MonadIO m) =>
ByteString -- data_
-> m ByteString -- result
byteArrayNewTake data_ = liftIO $ do
let len = fromIntegral $ B.length data_
data_' <- packByteString data_
result <- g_byte_array_new_take data_' len
checkUnexpectedReturnNULL "g_byte_array_new_take" result
result' <- unpackGByteArray result
unrefGByteArray result
return result'
-- method ByteArray::unref
-- method type : MemberFunction
-- Args : [Arg {argCName = "array", argType = TByteArray, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "g_byte_array_unref" g_byte_array_unref ::
Ptr GByteArray -> -- array : TByteArray
IO ()
byteArrayUnref ::
(MonadIO m) =>
ByteString -- array
-> m () -- result
byteArrayUnref array = liftIO $ do
array' <- packGByteArray array
g_byte_array_unref array'
unrefGByteArray array'
return ()
type family ResolveByteArrayMethod (t :: Symbol) (o :: *) :: * where
ResolveByteArrayMethod l o = MethodResolutionFailed l o
instance (info ~ ResolveByteArrayMethod t ByteArray, MethodInfo info ByteArray p) => IsLabelProxy t (ByteArray -> p) where
fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)
#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveByteArrayMethod t ByteArray, MethodInfo info ByteArray p) => IsLabel t (ByteArray -> p) where
fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info)
#endif