module GI.GLib.Structs.ByteArray
(
ByteArray(..) ,
newZeroByteArray ,
noByteArray ,
byteArrayFree ,
byteArrayFreeToBytes ,
byteArrayNew ,
byteArrayNewTake ,
byteArrayUnref ,
#ifdef ENABLE_OVERLOADING
byteArray_data ,
#endif
getByteArrayData ,
setByteArrayData ,
#ifdef ENABLE_OVERLOADING
byteArray_len ,
#endif
getByteArrayLen ,
setByteArrayLen ,
) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 GI.GLib.Structs.Bytes as GLib.Bytes
newtype ByteArray = ByteArray (ManagedPtr 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
newZeroByteArray :: MonadIO m => m ByteArray
newZeroByteArray = liftIO $ callocBoxedBytes 16 >>= wrapBoxed ByteArray
instance tag ~ 'AttrSet => Constructible ByteArray tag where
new _ attrs = do
o <- newZeroByteArray
GI.Attributes.set o attrs
return o
noByteArray :: Maybe ByteArray
noByteArray = Nothing
getByteArrayData :: MonadIO m => ByteArray -> m Word8
getByteArrayData s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO Word8
return val
setByteArrayData :: MonadIO m => ByteArray -> Word8 -> m ()
setByteArrayData s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (val :: Word8)
#ifdef ENABLE_OVERLOADING
data ByteArrayDataFieldInfo
instance AttrInfo ByteArrayDataFieldInfo where
type AttrAllowedOps ByteArrayDataFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint ByteArrayDataFieldInfo = (~) Word8
type AttrBaseTypeConstraint ByteArrayDataFieldInfo = (~) ByteArray
type AttrGetType ByteArrayDataFieldInfo = Word8
type AttrLabel ByteArrayDataFieldInfo = "data"
type AttrOrigin ByteArrayDataFieldInfo = ByteArray
attrGet _ = getByteArrayData
attrSet _ = setByteArrayData
attrConstruct = undefined
attrClear _ = undefined
byteArray_data :: AttrLabelProxy "data"
byteArray_data = AttrLabelProxy
#endif
getByteArrayLen :: MonadIO m => ByteArray -> m Word32
getByteArrayLen s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 8) :: IO Word32
return val
setByteArrayLen :: MonadIO m => ByteArray -> Word32 -> m ()
setByteArrayLen s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 8) (val :: Word32)
#ifdef ENABLE_OVERLOADING
data ByteArrayLenFieldInfo
instance AttrInfo ByteArrayLenFieldInfo where
type AttrAllowedOps ByteArrayLenFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint ByteArrayLenFieldInfo = (~) Word32
type AttrBaseTypeConstraint ByteArrayLenFieldInfo = (~) ByteArray
type AttrGetType ByteArrayLenFieldInfo = Word32
type AttrLabel ByteArrayLenFieldInfo = "len"
type AttrOrigin ByteArrayLenFieldInfo = ByteArray
attrGet _ = getByteArrayLen
attrSet _ = setByteArrayLen
attrConstruct = undefined
attrClear _ = undefined
byteArray_len :: AttrLabelProxy "len"
byteArray_len = AttrLabelProxy
#endif
#ifdef ENABLE_OVERLOADING
instance O.HasAttributeList ByteArray
type instance O.AttributeList ByteArray = ByteArrayAttributeList
type ByteArrayAttributeList = ('[ '("data", ByteArrayDataFieldInfo), '("len", ByteArrayLenFieldInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "g_byte_array_free" g_byte_array_free ::
Ptr GByteArray ->
CInt ->
IO Word8
byteArrayFree ::
(B.CallStack.HasCallStack, MonadIO m) =>
ByteString
-> Bool
-> m Word8
byteArrayFree array freeSegment = liftIO $ do
array' <- packGByteArray array
let freeSegment' = (fromIntegral . fromEnum) freeSegment
result <- g_byte_array_free array' freeSegment'
unrefGByteArray array'
return result
#ifdef ENABLE_OVERLOADING
#endif
foreign import ccall "g_byte_array_free_to_bytes" g_byte_array_free_to_bytes ::
Ptr GByteArray ->
IO (Ptr GLib.Bytes.Bytes)
byteArrayFreeToBytes ::
(B.CallStack.HasCallStack, MonadIO m) =>
ByteString
-> m GLib.Bytes.Bytes
byteArrayFreeToBytes array = liftIO $ do
array' <- packGByteArray array
result <- g_byte_array_free_to_bytes array'
checkUnexpectedReturnNULL "byteArrayFreeToBytes" result
result' <- (wrapBoxed GLib.Bytes.Bytes) result
return result'
#ifdef ENABLE_OVERLOADING
#endif
foreign import ccall "g_byte_array_new" g_byte_array_new ::
IO (Ptr GByteArray)
byteArrayNew ::
(B.CallStack.HasCallStack, MonadIO m) =>
m ByteString
byteArrayNew = liftIO $ do
result <- g_byte_array_new
checkUnexpectedReturnNULL "byteArrayNew" result
result' <- unpackGByteArray result
unrefGByteArray result
return result'
#ifdef ENABLE_OVERLOADING
#endif
foreign import ccall "g_byte_array_new_take" g_byte_array_new_take ::
Ptr Word8 ->
Word64 ->
IO (Ptr GByteArray)
byteArrayNewTake ::
(B.CallStack.HasCallStack, MonadIO m) =>
ByteString
-> m ByteString
byteArrayNewTake data_ = liftIO $ do
let len = fromIntegral $ B.length data_
data_' <- packByteString data_
result <- g_byte_array_new_take data_' len
checkUnexpectedReturnNULL "byteArrayNewTake" result
result' <- unpackGByteArray result
unrefGByteArray result
return result'
#ifdef ENABLE_OVERLOADING
#endif
foreign import ccall "g_byte_array_unref" g_byte_array_unref ::
Ptr GByteArray ->
IO ()
byteArrayUnref ::
(B.CallStack.HasCallStack, MonadIO m) =>
ByteString
-> m ()
byteArrayUnref array = liftIO $ do
array' <- packGByteArray array
g_byte_array_unref array'
unrefGByteArray array'
return ()
#ifdef ENABLE_OVERLOADING
#endif
#ifdef ENABLE_OVERLOADING
type family ResolveByteArrayMethod (t :: Symbol) (o :: *) :: * where
ResolveByteArrayMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveByteArrayMethod t ByteArray, O.MethodInfo info ByteArray p) => O.IsLabelProxy t (ByteArray -> p) where
fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveByteArrayMethod t ByteArray, O.MethodInfo info ByteArray p) => O.IsLabel t (ByteArray -> 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
#endif