ByteArray#
- class ByteArray(*args, **kwargs)#
Contains the public fields of a GByteArray.
Methods#
- class ByteArray
- classmethod append(data: int, len: int) list[int]#
Adds the given bytes to the end of the
GByteArray. The array will grow in size automatically if necessary.- Parameters:
data – the byte data to be added
len – the number of bytes to add
- classmethod free(free_segment: bool) int#
Frees the memory allocated by the
GByteArray. Iffree_segmentisTrueit frees the actual byte data. If the reference count ofarrayis greater than one, theGByteArraywrapper is preserved but the size ofarraywill be set to zero.- Parameters:
free_segment – if
Truethe actual byte data is freed as well
- classmethod free_to_bytes() Bytes#
Transfers the data from the
GByteArrayinto a new immutableBytes.The
GByteArrayis freed unless the reference count ofarrayis greater than one, theGByteArraywrapper is preserved but the size ofarraywill be set to zero.This is identical to using
new_take()andfree()together.Added in version 2.32.
- classmethod new_take() list[int]#
Creates a byte array containing the
data. After this call,databelongs to theGByteArrayand may no longer be modified by the caller. The memory ofdatahas to be dynamically allocated and will eventually be freed withfree().Do not use it if
lenis greater than %G_MAXUINT.GByteArraystores the length of its data inint, which may be shorter thangsize.Added in version 2.32.
- classmethod prepend(data: int, len: int) list[int]#
Adds the given data to the start of the
GByteArray. The array will grow in size automatically if necessary.- Parameters:
data – the byte data to be added
len – the number of bytes to add
- classmethod remove_index(index_: int) list[int]#
Removes the byte at the given index from a
GByteArray. The following bytes are moved down one place.- Parameters:
index – the index of the byte to remove
- classmethod remove_index_fast(index_: int) list[int]#
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 thanremove_index().- Parameters:
index – the index of the byte to remove
- classmethod remove_range(index_: int, length: int) list[int]#
Removes the given number of bytes starting at the given index from a
GByteArray. The following elements are moved to close the gap.Added in version 2.4.
- Parameters:
index – the index of the first byte to remove
length – the number of bytes to remove
- classmethod set_size(length: int) list[int]#
Sets the size of the
GByteArray, expanding it if necessary.- Parameters:
length – the new size of the
GByteArray
- classmethod sized_new() list[int]#
Creates a new
GByteArraywithreserved_sizebytes 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(compare_func: Callable[[Any, Any], int]) None#
Sorts a byte array, using
compare_funcwhich 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.
- Parameters:
compare_func – comparison function