PoolByteArray
A pooled array of bytes.
Description
An array specifically designed to hold bytes. Optimized for memory usage, does not fragment the memory.
Note: This type is passed by value and not by reference. This means that when mutating a class property of type PoolByteArray or mutating a PoolByteArray within an Array or Dictionary, changes will be lost:
var array = [PoolByteArray()]array[0].push_back(123)print(array) # [[]] (empty PoolByteArray within an Array)
PoolByteArray property must be reassigned with = for it to be changed:
var array = [PoolByteArray()]var pool_array = array[0]pool_array.push_back(123)array[0] = pool_arrayprint(array) # [[123]] (PoolByteArray with 1 element inside an Array)
Methods
Method Descriptions
- PoolByteArray PoolByteArray ( Array from )
PoolByteArray. Optionally, you can pass in a generic Array that will be converted.
- append ( int byte ) push_back).
- append_array ( PoolByteArray array )
PoolByteArrayat the end of this array.
- PoolByteArray compress ( int compression_mode=0 )
PoolByteArraywith the data compressed. Set the compression mode using one of CompressionMode‘s constants.
- int count ( int value ) Returns the number of times an element is in the array.
- PoolByteArray decompress ( int buffer_size, int compression_mode=0 )
PoolByteArraywith the data decompressed. Setbuffer_sizeto the size of the uncompressed data. Set the compression mode using one of CompressionMode‘s constants.
- PoolByteArray decompress_dynamic ( int max_output_size, int compression_mode=0 )
PoolByteArraywith the data decompressed. Set the compression mode using one of CompressionMode‘s constants. This method only accepts gzip and deflate compression modes.decompress, as it may have to re-allocate its output buffer multiple times while decompressing, where asdecompressknows its output buffer size from the beginning.max_output_size. Passing -1 will allow for unbounded output. If any positive value is passed, and the decompression exceeds that amount in bytes, then an error will be returned.
- bool empty ( )
trueif the array is empty.
- fill ( int byte ) resize to create an array with a given size and initialized elements.
- int find ( int value, int from=0 )
-1if not found. Optionally, the initial search index can be passed. Returns-1iffromis out of bounds.
- String get_string_from_ascii ( ) String. Fast alternative to get_string_from_utf8 if the content is ASCII-only. Unlike the UTF-8 function this function maps every byte to a character in the array. Multibyte sequences will not be interpreted correctly. For parsing user input always use get_string_from_utf8.
- String get_string_from_utf8 ( ) String. Slower than get_string_from_ascii but supports UTF-8 encoded data. Use this function if you are unsure about the source of the data. For user input this function should always be preferred.
- bool has ( int value )
trueif the array contains the given value. Note: This is equivalent to using theinoperator.
- String hex_encode ( )
String.
var array = PoolByteArray([11, 46, 255])print(array.hex_encode()) # Prints: 0b2eff
- int insert ( int idx, int byte )
idx == size()).
- invert ( ) Reverses the order of the elements in the array.
- push_back ( int byte ) Appends an element at the end of the array.
- remove ( int idx ) Removes an element from the array by index.
- resize ( int idx ) Sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Note: Added elements are not automatically initialized to 0 and will contain garbage, i.e. indeterminate values.
- int rfind ( int value, int from=-1 ) Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array. If the adjusted start index is out of bounds, this method searches from the end of the array.
- set ( int idx, int byte ) Changes the byte at the given index.
- int size ( ) Returns the number of elements in the array.
- sort ( ) Sorts the elements of the array in ascending order.
- PoolByteArray subarray ( int from, int to )
PoolByteArraybetween indices (inclusive) as a newPoolByteArray. Any negative index is considered to be from the end of the array.
