GLib.ByteArray¶
Fields¶
Name |
Type |
Access |
Description |
|---|---|---|---|
data |
r/w |
a pointer to the element data. The data may be moved as elements are added to the |
|
len |
r/w |
the number of elements in the |
Methods¶
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
Details¶
- class GLib.ByteArray¶
Contains the public fields of a
GByteArray.- classmethod append(array, data)[source]¶
- Parameters:
- Returns:
The
GByteArray- Return type:
Adds the given bytes to the end of the
GByteArray. The array will grow in size automatically if necessary.
- classmethod free(array, free_segment)[source]¶
- Parameters:
- Returns:
The allocated element data if free_segment is false, otherwise
NULL.- Return type:
Frees the memory allocated by the
GByteArray. If free_segment is true it frees the actual byte data. If the reference count of array is greater than one, theGByteArraywrapper is preserved but the size of array will be set to zero.
- classmethod free_to_bytes(array)[source]¶
- Parameters:
array (
bytes) – a byte array- Returns:
The new immutable [struct`GLib`.Bytes] representing same byte data that was in the array
- Return type:
Transfers the data from the
GByteArrayinto a new immutable [struct`GLib`.Bytes].The
GByteArrayis freed unless the reference count of array is greater than one, in which theGByteArraywrapper is preserved but the size of array will be set to zero.This is identical to using [ctor`GLib`.Bytes.new_take] and [func`GLib`.ByteArray.free] together.
New in version 2.32.
- classmethod new()[source]¶
- Returns:
The new
GByteArray- Return type:
Creates a new
GByteArraywith a reference count of 1.
- classmethod new_take(data)[source]¶
- Parameters:
data (
bytes) – the byte data for the array- Returns:
The new
GByteArray- Return type:
Creates a byte array containing the data. After this call, data belongs to the
GByteArrayand may no longer be modified by the caller. The memory of data has to be dynamically allocated and will eventually be freed with [func`GLib`.free].Do not use it if len is greater than G_MAXUINT.
GByteArraystores the length of its data inguint, which may be shorter thangsize.New in version 2.32.
- classmethod prepend(array, data)[source]¶
- Parameters:
- Returns:
The
GByteArray- Return type:
Adds the given data to the start of the
GByteArray. The array will grow in size automatically if necessary.
- classmethod ref(array)[source]¶
-
Atomically increments the reference count of array by one. This function is thread-safe and may be called from any thread.
New in version 2.22.
- classmethod remove_index(array, index_)[source]¶
- Parameters:
- Returns:
The
GByteArray- Return type:
Removes the byte at the given index from a
GByteArray. The following bytes are moved down one place.
- classmethod remove_index_fast(array, index_)[source]¶
- Parameters:
- Returns:
The
GByteArray- Return type:
Removes the byte at the given index from a
GByteArray. The last element in the array is used to fill in the space, so this function does not preserve the order of theGByteArray. But it is faster than [func`GLib`.ByteArray.remove_index].
- classmethod remove_range(array, index_, length)[source]¶
- Parameters:
- Returns:
The
GByteArray- Return type:
Removes the given number of bytes starting at the given index from a
GByteArray. The following elements are moved to close the gap.New in version 2.4.
- classmethod set_size(array, length)[source]¶
- Parameters:
- Returns:
The
GByteArray- Return type:
Sets the size of the
GByteArray, expanding it if necessary.
- classmethod sized_new(reserved_size)[source]¶
- Parameters:
reserved_size (
int) – the number of bytes preallocated- Returns:
The new
GByteArray- Return type:
Creates a new
GByteArraywith reserved_size 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.
- classmethod sort(array, compare_func)[source]¶
- Parameters:
array (
bytes) – a byte arraycompare_func (
GLib.CompareFunc) – the comparison function
Sorts a byte array, using compare_func 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.
- classmethod sort_with_data(array, compare_func, *user_data)[source]¶
- Parameters:
array (
bytes) – a byte arraycompare_func (
GLib.CompareDataFunc) – the comparison functionuser_data (
objectorNone) – the data to pass to compare_func
Like [func`GLib`.ByteArray.sort], but the comparison function takes an extra user data argument.
- classmethod steal(array)[source]¶
-
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.
New in version 2.64.
- classmethod unref(array)[source]¶
- Parameters:
array (
bytes) – a byte array
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.
New in version 2.22.