Instance Methodmigueldeicaza.swiftgodot 0.45.0SwiftGodot
append(_:)
Appends an element at the end of the array
Packed.swift:117func append(_ value: UInt8)
Other members in extension
Typealiases
Type members
init(
) Constructs an empty
PackedByteArray
.init([UInt8]
) Initializes a PackedByteArray from an array of UInt8 values.
init(alreadyOwnedContent: ContentType
) init(content: ContentType
) init(from: PackedByteArray
) Constructs a
PackedByteArray
as a copy of the givenPackedByteArray
.init(from: GArray
) Constructs a new
PackedByteArray
. Optionally, you can pass in a genericGArray
that will be converted.static var godotType: Variant.GType
static let zero: ContentType
static func != (lhs: PackedByteArray, rhs: PackedByteArray
) -> Bool Returns
true
if contents of the arrays differ.static func + (lhs: PackedByteArray, rhs: PackedByteArray
) -> PackedByteArray Returns a new
PackedByteArray
with contents ofright
added at the end of this array. For better performance, consider usingappendArray(array:)
instead.static func == (lhs: PackedByteArray, rhs: PackedByteArray
) -> Bool Returns
true
if contents of both arrays are the same, i.e. they have all equal bytes at the corresponding indices.
Instance members
var content: ContentType
var count: Int
The number of elements in the array
var endIndex: Int
var startIndex: Int
subscript(Int
) -> UInt8 Accesses a specific element in the
PackedByteArray
func append(value: Int64
) -> Bool Appends an element at the end of the array (alias of
pushBack(value:)
).func appendArray(PackedByteArray
) Appends a
PackedByteArray
at the end of this array.func asBytes(
) -> [UInt8] Returns the underlying storage as an array of bytes
func bsearch(value: Int64, before: Bool
) -> Int64 Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search. Optionally, a
before
specifier can be passed. Iffalse
, the returned index comes after all existing entries of the value in the array.func clear(
) Clears the array. This is equivalent to using
resize(newSize:)
with a size of0
.func compress(compressionMode: Int64
) -> PackedByteArray Returns a new
PackedByteArray
with the data compressed. Set the compression mode using one ofFileAccess.CompressionMode
’s constants.func count(value: Int64
) -> Int64 Returns the number of times an element is in the array.
func decodeDouble(byteOffset: Int64
) -> Double Decodes a 64-bit floating point number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0.0
if a valid number can’t be decoded.func decodeFloat(byteOffset: Int64
) -> Double Decodes a 32-bit floating point number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0.0
if a valid number can’t be decoded.func decodeHalf(byteOffset: Int64
) -> Double Decodes a 16-bit floating point number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0.0
if a valid number can’t be decoded.func decodeS16(byteOffset: Int64
) -> Int64 Decodes a 16-bit signed integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeS32(byteOffset: Int64
) -> Int64 Decodes a 32-bit signed integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeS64(byteOffset: Int64
) -> Int64 Decodes a 64-bit signed integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeS8(byteOffset: Int64
) -> Int64 Decodes a 8-bit signed integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeU16(byteOffset: Int64
) -> Int64 Decodes a 16-bit unsigned integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeU32(byteOffset: Int64
) -> Int64 Decodes a 32-bit unsigned integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeU64(byteOffset: Int64
) -> Int64 Decodes a 64-bit unsigned integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeU8(byteOffset: Int64
) -> Int64 Decodes a 8-bit unsigned integer number from the bytes starting at
byteOffset
. Fails if the byte count is insufficient. Returns0
if a valid number can’t be decoded.func decodeVar(byteOffset: Int64, allowObjects: Bool
) -> Variant Decodes a
Variant
from the bytes starting atbyteOffset
. Returnsnull
if a valid variant can’t be decoded or the value isObject
-derived andallowObjects
isfalse
.func decodeVarSize(byteOffset: Int64, allowObjects: Bool
) -> Int64 Decodes a size of a
Variant
from the bytes starting atbyteOffset
. Requires at least 4 bytes of data starting at the offset, otherwise fails.func decompress(bufferSize: Int64, compressionMode: Int64
) -> PackedByteArray Returns a new
PackedByteArray
with the data decompressed. SetbufferSize
to the size of the uncompressed data. Set the compression mode using one ofFileAccess.CompressionMode
’s constants.func decompressDynamic(maxOutputSize: Int64, compressionMode: Int64
) -> PackedByteArray Returns a new
PackedByteArray
with the data decompressed. Set the compression mode using one ofFileAccess.CompressionMode
’s constants. This method only accepts brotli, gzip, and deflate compression modes.func duplicate(
) -> PackedByteArray Creates a copy of the array, and returns it.
func encodeDouble(byteOffset: Int64, value: Double
) Encodes a 64-bit floating point number as bytes at the index of
byteOffset
bytes. The array must have at least 8 bytes of allocated space, starting at the offset.func encodeFloat(byteOffset: Int64, value: Double
) Encodes a 32-bit floating point number as bytes at the index of
byteOffset
bytes. The array must have at least 4 bytes of space, starting at the offset.func encodeHalf(byteOffset: Int64, value: Double
) Encodes a 16-bit floating point number as bytes at the index of
byteOffset
bytes. The array must have at least 2 bytes of space, starting at the offset.func encodeS16(byteOffset: Int64, value: Int64
) Encodes a 16-bit signed integer number as bytes at the index of
byteOffset
bytes. The array must have at least 2 bytes of space, starting at the offset.func encodeS32(byteOffset: Int64, value: Int64
) Encodes a 32-bit signed integer number as bytes at the index of
byteOffset
bytes. The array must have at least 4 bytes of space, starting at the offset.func encodeS64(byteOffset: Int64, value: Int64
) Encodes a 64-bit signed integer number as bytes at the index of
byteOffset
bytes. The array must have at least 8 bytes of space, starting at the offset.func encodeS8(byteOffset: Int64, value: Int64
) Encodes a 8-bit signed integer number (signed byte) at the index of
byteOffset
bytes. The array must have at least 1 byte of space, starting at the offset.func encodeU16(byteOffset: Int64, value: Int64
) Encodes a 16-bit unsigned integer number as bytes at the index of
byteOffset
bytes. The array must have at least 2 bytes of space, starting at the offset.func encodeU32(byteOffset: Int64, value: Int64
) Encodes a 32-bit unsigned integer number as bytes at the index of
byteOffset
bytes. The array must have at least 4 bytes of space, starting at the offset.func encodeU64(byteOffset: Int64, value: Int64
) Encodes a 64-bit unsigned integer number as bytes at the index of
byteOffset
bytes. The array must have at least 8 bytes of space, starting at the offset.func encodeU8(byteOffset: Int64, value: Int64
) Encodes a 8-bit unsigned integer number (byte) at the index of
byteOffset
bytes. The array must have at least 1 byte of space, starting at the offset.func encodeVar(byteOffset: Int64, value: Variant, allowObjects: Bool
) -> Int64 Encodes a
Variant
at the index ofbyteOffset
bytes. A sufficient space must be allocated, depending on the encoded variant’s size. IfallowObjects
isfalse
,Object
-derived values are not permitted and will instead be serialized as ID-only.func fill(value: Int64
) Assigns the given value to all elements in the array. This can typically be used together with
resize(newSize:)
to create an array with a given size and initialized elements.func find(value: Int64, from: Int64
) -> Int64 Searches the array for a value and returns its index or
-1
if not found. Optionally, the initial search index can be passed.func getStringFromAscii(
) -> String Converts ASCII/Latin-1 encoded array to
String
. Fast alternative togetStringFromUtf8
if the content is ASCII/Latin-1 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 usegetStringFromUtf8
. This is the inverse ofString/toAsciiBuffer()
.func getStringFromUtf16(
) -> String Converts UTF-16 encoded array to
String
. If the BOM is missing, system endianness is assumed. Returns empty string if source array is not valid UTF-16 string. This is the inverse ofString/toUtf16Buffer()
.func getStringFromUtf32(
) -> String Converts UTF-32 encoded array to
String
. System endianness is assumed. Returns empty string if source array is not valid UTF-32 string. This is the inverse ofString/toUtf32Buffer()
.func getStringFromUtf8(
) -> String Converts UTF-8 encoded array to
String
. Slower thangetStringFromAscii
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. Returns empty string if source array is not valid UTF-8 string. This is the inverse ofString/toUtf8Buffer()
.func getStringFromWchar(
) -> String Converts wide character (
wchar_t
, UTF-16 on Windows, UTF-32 on other platforms) encoded array toString
. Returns empty string if source array is not valid wide string. This is the inverse ofString/toWcharBuffer()
.func has(value: Int64
) -> Bool Returns
true
if the array containsvalue
.func hasEncodedVar(byteOffset: Int64, allowObjects: Bool
) -> Bool Returns
true
if a validVariant
value can be decoded at thebyteOffset
. Returnsfalse
otherwise or when the value isObject
-derived andallowObjects
isfalse
.func hexEncode(
) -> String Returns a hexadecimal representation of this array as a
String
.func index(after: Int
) -> Int func index(before: Int
) -> Int func insert(atIndex: Int64, value: Int64
) -> Int64 Inserts a new element at a given position in the array. The position must be valid, or at the end of the array (
idx == size()
).func isEmpty(
) -> Bool Returns
true
if the array is empty.func pushBack(value: Int64
) -> Bool Appends an element at the end of the array.
func removeAt(index: Int64
) Removes an element from the array by index.
func resize(newSize: Int64
) -> Int64 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.
func reverse(
) Reverses the order of the elements in the array.
func rfind(value: Int64, from: Int64
) -> Int64 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.
func set(index: Int64, value: Int64
) Changes the byte at the given index.
func size(
) -> Int64 Returns the number of elements in the array.
func slice(begin: Int64, end: Int64
) -> PackedByteArray Returns the slice of the
PackedByteArray
, frombegin
(inclusive) toend
(exclusive), as a newPackedByteArray
.func sort(
) Sorts the elements of the array in ascending order.
func toFloat32Array(
) -> PackedFloat32Array Returns a copy of the data converted to a
PackedFloat32Array
, where each block of 4 bytes has been converted to a 32-bit float (C++ [code skip-lint]float`).func toFloat64Array(
) -> PackedFloat64Array Returns a copy of the data converted to a
PackedFloat64Array
, where each block of 8 bytes has been converted to a 64-bit float (C++double
, Godot float).func toInt32Array(
) -> PackedInt32Array Returns a copy of the data converted to a
PackedInt32Array
, where each block of 4 bytes has been converted to a signed 32-bit integer (C++int32_t
).func toInt64Array(
) -> PackedInt64Array Returns a copy of the data converted to a
PackedInt64Array
, where each block of 8 bytes has been converted to a signed 64-bit integer (C++int64_t
, Godot integer).func withUnsafeAccessToData<T>((_ pointer: UnsafeRawPointer, _ count: Int) -> T?
) -> T? Provides a mechanism to access the underlying data for the packed byte array
func withUnsafeConstAccessToData<T>((_ pointer: UnsafeRawPointer, _ count: Int) -> T?
) -> T? Read-only access the underlying data for this packed byte array
func withUnsafeMutableAccessToData<T>((_ pointer: UnsafeMutableRawPointer, _ count: Int) -> T?
) -> T? Provides a mechanism to access the underlying data for the packed byte array for mutation