Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
GI.GLib.Structs.ByteArray
Description
Contains the public fields of a GByteArray.
Synopsis
- newtype ByteArray = ByteArray (ManagedPtr ByteArray)
- newZeroByteArray :: MonadIO m => m ByteArray
- byteArrayAppend :: (HasCallStack, MonadIO m) => ByteString -> Word8 -> Word32 -> m ByteString
- byteArrayFree :: (HasCallStack, MonadIO m) => ByteString -> Bool -> m Word8
- byteArrayFreeToBytes :: (HasCallStack, MonadIO m) => ByteString -> m Bytes
- byteArrayNew :: (HasCallStack, MonadIO m) => m ByteString
- byteArrayNewTake :: (HasCallStack, MonadIO m) => ByteString -> m ByteString
- byteArrayPrepend :: (HasCallStack, MonadIO m) => ByteString -> Word8 -> Word32 -> m ByteString
- byteArrayRef :: (HasCallStack, MonadIO m) => ByteString -> m ByteString
- byteArrayRemoveIndex :: (HasCallStack, MonadIO m) => ByteString -> Word32 -> m ByteString
- byteArrayRemoveIndexFast :: (HasCallStack, MonadIO m) => ByteString -> Word32 -> m ByteString
- byteArrayRemoveRange :: (HasCallStack, MonadIO m) => ByteString -> Word32 -> Word32 -> m ByteString
- byteArraySetSize :: (HasCallStack, MonadIO m) => ByteString -> Word32 -> m ByteString
- byteArraySizedNew :: (HasCallStack, MonadIO m) => Word32 -> m ByteString
- byteArraySort :: (HasCallStack, MonadIO m) => ByteString -> CompareFunc -> m ()
- byteArraySortWithData :: (HasCallStack, MonadIO m) => ByteString -> CompareDataFunc -> m ()
- byteArraySteal :: (HasCallStack, MonadIO m) => ByteString -> m (Word8, CSize)
- byteArrayUnref :: (HasCallStack, MonadIO m) => ByteString -> m ()
- getByteArrayData :: MonadIO m => ByteArray -> m Word8
- setByteArrayData :: MonadIO m => ByteArray -> Word8 -> m ()
- getByteArrayLen :: MonadIO m => ByteArray -> m Word32
- setByteArrayLen :: MonadIO m => ByteArray -> Word32 -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq ByteArray Source # | |
GBoxed ByteArray Source # | |
Defined in GI.GLib.Structs.ByteArray | |
ManagedPtrNewtype ByteArray Source # | |
Defined in GI.GLib.Structs.ByteArray Methods toManagedPtr :: ByteArray -> ManagedPtr ByteArray | |
TypedObject ByteArray Source # | |
Defined in GI.GLib.Structs.ByteArray | |
HasParentTypes ByteArray Source # | |
Defined in GI.GLib.Structs.ByteArray | |
tag ~ 'AttrSet => Constructible ByteArray tag Source # | |
IsGValue (Maybe ByteArray) Source # | Convert |
Defined in GI.GLib.Structs.ByteArray Methods gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe ByteArray -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe ByteArray) | |
type ParentTypes ByteArray Source # | |
Defined in GI.GLib.Structs.ByteArray |
newZeroByteArray :: MonadIO m => m ByteArray Source #
Construct a ByteArray
struct initialized to zero.
Methods
append
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Word8 |
|
-> Word32 |
|
-> m ByteString | Returns: the |
Adds the given bytes to the end of the ByteArray
.
The array will grow in size automatically if necessary.
free
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Bool |
|
-> m Word8 | Returns: the element data if |
freeToBytes
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> m Bytes | Returns: a new immutable |
Transfers the data from the ByteArray
into a new immutable Bytes
.
The ByteArray
is freed unless the reference count of array
is greater
than one, the ByteArray
wrapper is preserved but the size of array
will be set to zero.
This is identical to using bytesNewTake
and byteArrayFree
together.
Since: 2.32
new
Arguments
:: (HasCallStack, MonadIO m) | |
=> m ByteString | Returns: the new |
Creates a new ByteArray
with a reference count of 1.
newTake
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> m ByteString | Returns: a new |
Creates a byte array containing the data
.
After this call, data
belongs to the ByteArray
and may no longer be
modified by the caller. The memory of data
has to be dynamically
allocated and will eventually be freed with free
.
Do not use it if len
is greater than G_MAXUINT
. ByteArray
stores the length of its data in guint
, which may be shorter than
gsize
.
Since: 2.32
prepend
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Word8 |
|
-> Word32 |
|
-> m ByteString | Returns: the |
Adds the given data to the start of the ByteArray
.
The array will grow in size automatically if necessary.
ref
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> m ByteString | Returns: The passed in |
Atomically increments the reference count of array
by one.
This function is thread-safe and may be called from any thread.
Since: 2.22
removeIndex
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Word32 |
|
-> m ByteString | Returns: the |
Removes the byte at the given index from a ByteArray
.
The following bytes are moved down one place.
removeIndexFast
byteArrayRemoveIndexFast Source #
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Word32 |
|
-> m ByteString | Returns: the |
Removes the byte at the given index from a ByteArray
. The last
element in the array is used to fill in the space, so this function
does not preserve the order of the ByteArray
. But it is faster
than byteArrayRemoveIndex
.
removeRange
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Word32 |
|
-> Word32 |
|
-> m ByteString | Returns: the |
Removes the given number of bytes starting at the given index from a
ByteArray
. The following elements are moved to close the gap.
Since: 2.4
setSize
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Word32 |
|
-> m ByteString | Returns: the |
Sets the size of the ByteArray
, expanding it if necessary.
sizedNew
Arguments
:: (HasCallStack, MonadIO m) | |
=> Word32 |
|
-> m ByteString | Returns: the new |
Creates a new ByteArray
with reservedSize
bytes preallocated.
This avoids frequent reallocation, if you are going to add many
bytes to the array. Note however that the size of the array is still
0.
sort
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> CompareFunc |
|
-> m () |
Sorts a byte array, using compareFunc
which should be a
qsort()
-style comparison function (returns less than zero for first
arg is less than second arg, zero for equal, greater than zero if
first arg is greater than second arg).
If two array elements compare equal, their order in the sorted array is undefined. If you want equal elements to keep their order (i.e. you want a stable sort) you can write a comparison function that, if two elements would otherwise compare equal, compares them by their addresses.
sortWithData
byteArraySortWithData Source #
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> CompareDataFunc |
|
-> m () |
Like byteArraySort
, but the comparison function takes an extra
user data argument.
steal
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> m (Word8, CSize) | Returns: the element data, which should be
freed using |
Frees the data in the array and resets the size to zero, while the underlying array is preserved for use elsewhere and returned to the caller.
Since: 2.64
unref
Arguments
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> m () |
Atomically decrements the reference count of array
by one. If the
reference count drops to 0, all memory allocated by the array is
released. This function is thread-safe and may be called from any
thread.
Since: 2.22
Properties
data
a pointer to the element data. The data may be moved as
elements are added to the ByteArray
getByteArrayData :: MonadIO m => ByteArray -> m Word8 Source #
Get the value of the “data
” field.
When overloading is enabled, this is equivalent to
get
byteArray #data
setByteArrayData :: MonadIO m => ByteArray -> Word8 -> m () Source #
Set the value of the “data
” field.
When overloading is enabled, this is equivalent to
set
byteArray [ #data:=
value ]
len
the number of elements in the ByteArray
getByteArrayLen :: MonadIO m => ByteArray -> m Word32 Source #
Get the value of the “len
” field.
When overloading is enabled, this is equivalent to
get
byteArray #len
setByteArrayLen :: MonadIO m => ByteArray -> Word32 -> m () Source #
Set the value of the “len
” field.
When overloading is enabled, this is equivalent to
set
byteArray [ #len:=
value ]