Files
godot-docs-l10n/classes/zh_Hans/class_packedbytearray.rst
Rémi Verschelde c3f2364c10 Sync classref with 4.6 branch
Lots of translations invalidated (fuzzied) as we just synced Weblate.
2025-12-19 16:39:51 +01:00

1204 lines
77 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. _class_PackedByteArray:
PackedByteArray
===============
字节紧缩数组。
.. rst-class:: classref-introduction-group
描述
----
专门设计用于保存字节的数组。紧缩数组紧密打包数据,因此可为大型数组节省内存。
\ **PackedByteArray** 还提供了将各种类型编码为字节/从字节解码的方法。值的编码方式是实现细节,在与外部应用程序交互时不应依赖它。
\ **注意:**\ 紧缩数组始终通过引用传递。要获取可以独立于原始数组进行修改的数组副本,请使用 :ref:`duplicate()<class_PackedByteArray_method_duplicate>`\ 。内置属性和方法\ *并非*\ 如此,它们返回的是紧缩数组的副本,对其进行修改\ *不会*\ 影响原值。更新此类内置属性请修改返回的数组,然后将其重新赋值给该属性。
.. note::
通过 C# 使用该 API 时会有显著不同,详见 :ref:`doc_c_sharp_differences`\ 。
.. rst-class:: classref-reftable-group
构造函数
--------
.. table::
:widths: auto
+-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`PackedByteArray<class_PackedByteArray_constructor_PackedByteArray>`\ (\ ) |
+-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`PackedByteArray<class_PackedByteArray_constructor_PackedByteArray>`\ (\ from\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`PackedByteArray<class_PackedByteArray_constructor_PackedByteArray>`\ (\ from\: :ref:`Array<class_Array>`\ ) |
+-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`append<class_PackedByteArray_method_append>`\ (\ value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`append_array<class_PackedByteArray_method_append_array>`\ (\ array\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`bsearch<class_PackedByteArray_method_bsearch>`\ (\ value\: :ref:`int<class_int>`, before\: :ref:`bool<class_bool>` = true\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`bswap16<class_PackedByteArray_method_bswap16>`\ (\ offset\: :ref:`int<class_int>` = 0, count\: :ref:`int<class_int>` = -1\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`bswap32<class_PackedByteArray_method_bswap32>`\ (\ offset\: :ref:`int<class_int>` = 0, count\: :ref:`int<class_int>` = -1\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`bswap64<class_PackedByteArray_method_bswap64>`\ (\ offset\: :ref:`int<class_int>` = 0, count\: :ref:`int<class_int>` = -1\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear<class_PackedByteArray_method_clear>`\ (\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`compress<class_PackedByteArray_method_compress>`\ (\ compression_mode\: :ref:`int<class_int>` = 0\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`count<class_PackedByteArray_method_count>`\ (\ value\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`decode_double<class_PackedByteArray_method_decode_double>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`decode_float<class_PackedByteArray_method_decode_float>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`decode_half<class_PackedByteArray_method_decode_half>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_s8<class_PackedByteArray_method_decode_s8>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_s16<class_PackedByteArray_method_decode_s16>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_s32<class_PackedByteArray_method_decode_s32>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_s64<class_PackedByteArray_method_decode_s64>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_u8<class_PackedByteArray_method_decode_u8>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_u16<class_PackedByteArray_method_decode_u16>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_u32<class_PackedByteArray_method_decode_u32>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_u64<class_PackedByteArray_method_decode_u64>`\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Variant<class_Variant>` | :ref:`decode_var<class_PackedByteArray_method_decode_var>`\ (\ byte_offset\: :ref:`int<class_int>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`decode_var_size<class_PackedByteArray_method_decode_var_size>`\ (\ byte_offset\: :ref:`int<class_int>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`decompress<class_PackedByteArray_method_decompress>`\ (\ buffer_size\: :ref:`int<class_int>`, compression_mode\: :ref:`int<class_int>` = 0\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`decompress_dynamic<class_PackedByteArray_method_decompress_dynamic>`\ (\ max_output_size\: :ref:`int<class_int>`, compression_mode\: :ref:`int<class_int>` = 0\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`duplicate<class_PackedByteArray_method_duplicate>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_double<class_PackedByteArray_method_encode_double>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`float<class_float>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_float<class_PackedByteArray_method_encode_float>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`float<class_float>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_half<class_PackedByteArray_method_encode_half>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`float<class_float>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_s8<class_PackedByteArray_method_encode_s8>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_s16<class_PackedByteArray_method_encode_s16>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_s32<class_PackedByteArray_method_encode_s32>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_s64<class_PackedByteArray_method_encode_s64>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_u8<class_PackedByteArray_method_encode_u8>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_u16<class_PackedByteArray_method_encode_u16>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_u32<class_PackedByteArray_method_encode_u32>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`encode_u64<class_PackedByteArray_method_encode_u64>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`encode_var<class_PackedByteArray_method_encode_var>`\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`Variant<class_Variant>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`erase<class_PackedByteArray_method_erase>`\ (\ value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`fill<class_PackedByteArray_method_fill>`\ (\ value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`find<class_PackedByteArray_method_find>`\ (\ value\: :ref:`int<class_int>`, from\: :ref:`int<class_int>` = 0\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get<class_PackedByteArray_method_get>`\ (\ index\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_string_from_ascii<class_PackedByteArray_method_get_string_from_ascii>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_string_from_multibyte_char<class_PackedByteArray_method_get_string_from_multibyte_char>`\ (\ encoding\: :ref:`String<class_String>` = ""\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_string_from_utf8<class_PackedByteArray_method_get_string_from_utf8>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_string_from_utf16<class_PackedByteArray_method_get_string_from_utf16>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_string_from_utf32<class_PackedByteArray_method_get_string_from_utf32>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_string_from_wchar<class_PackedByteArray_method_get_string_from_wchar>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has<class_PackedByteArray_method_has>`\ (\ value\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_encoded_var<class_PackedByteArray_method_has_encoded_var>`\ (\ byte_offset\: :ref:`int<class_int>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`hex_encode<class_PackedByteArray_method_hex_encode>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`insert<class_PackedByteArray_method_insert>`\ (\ at_index\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_empty<class_PackedByteArray_method_is_empty>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`push_back<class_PackedByteArray_method_push_back>`\ (\ value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_at<class_PackedByteArray_method_remove_at>`\ (\ index\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`resize<class_PackedByteArray_method_resize>`\ (\ new_size\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`reverse<class_PackedByteArray_method_reverse>`\ (\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`rfind<class_PackedByteArray_method_rfind>`\ (\ value\: :ref:`int<class_int>`, from\: :ref:`int<class_int>` = -1\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set<class_PackedByteArray_method_set>`\ (\ index\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`size<class_PackedByteArray_method_size>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`slice<class_PackedByteArray_method_slice>`\ (\ begin\: :ref:`int<class_int>`, end\: :ref:`int<class_int>` = 2147483647\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`sort<class_PackedByteArray_method_sort>`\ (\ ) |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`to_color_array<class_PackedByteArray_method_to_color_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedFloat32Array<class_PackedFloat32Array>` | :ref:`to_float32_array<class_PackedByteArray_method_to_float32_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedFloat64Array<class_PackedFloat64Array>` | :ref:`to_float64_array<class_PackedByteArray_method_to_float64_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`to_int32_array<class_PackedByteArray_method_to_int32_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`to_int64_array<class_PackedByteArray_method_to_int64_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`to_vector2_array<class_PackedByteArray_method_to_vector2_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedVector3Array<class_PackedVector3Array>` | :ref:`to_vector3_array<class_PackedByteArray_method_to_vector3_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedVector4Array<class_PackedVector4Array>` | :ref:`to_vector4_array<class_PackedByteArray_method_to_vector4_array>`\ (\ ) |const| |
+-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-reftable-group
运算符
------
.. table::
:widths: auto
+-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`operator !=<class_PackedByteArray_operator_neq_PackedByteArray>`\ (\ right\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`operator +<class_PackedByteArray_operator_sum_PackedByteArray>`\ (\ right\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`operator ==<class_PackedByteArray_operator_eq_PackedByteArray>`\ (\ right\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`operator []<class_PackedByteArray_operator_idx_int>`\ (\ index\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
构造函数说明
------------
.. _class_PackedByteArray_constructor_PackedByteArray:
.. rst-class:: classref-constructor
:ref:`PackedByteArray<class_PackedByteArray>` **PackedByteArray**\ (\ ) :ref:`🔗<class_PackedByteArray_constructor_PackedByteArray>`
构造空的 **PackedByteArray**\ 。
.. rst-class:: classref-item-separator
----
.. rst-class:: classref-constructor
:ref:`PackedByteArray<class_PackedByteArray>` **PackedByteArray**\ (\ from\: :ref:`PackedByteArray<class_PackedByteArray>`\ )
构造给定 **PackedByteArray** 的副本。
.. rst-class:: classref-item-separator
----
.. rst-class:: classref-constructor
:ref:`PackedByteArray<class_PackedByteArray>` **PackedByteArray**\ (\ from\: :ref:`Array<class_Array>`\ )
构造新 **PackedByteArray**\ 。你还可以传入通用 :ref:`Array<class_Array>` 进行转换。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法说明
--------
.. _class_PackedByteArray_method_append:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **append**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_append>`
向数组末尾追加一个元素(\ :ref:`push_back()<class_PackedByteArray_method_push_back>` 的别名)。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_append_array:
.. rst-class:: classref-method
|void| **append_array**\ (\ array\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_PackedByteArray_method_append_array>`
在该数组的末尾追加一个 **PackedByteArray**\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_bsearch:
.. rst-class:: classref-method
:ref:`int<class_int>` **bsearch**\ (\ value\: :ref:`int<class_int>`, before\: :ref:`bool<class_bool>` = true\ ) |const| :ref:`🔗<class_PackedByteArray_method_bsearch>`
使用二进法查找已有值的索引(如果该值尚未存在于数组中,则为保持排序顺序的插入索引)。传递 ``before`` 说明符是可选的。如果该参数为 ``false``\ ,则返回的索引位于数组中该值的所有已有的条目之后。
\ **注意:**\ 在未排序的数组上调用 :ref:`bsearch()<class_PackedByteArray_method_bsearch>` 会产生预料之外的行为。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_bswap16:
.. rst-class:: classref-method
|void| **bswap16**\ (\ offset\: :ref:`int<class_int>` = 0, count\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_PackedByteArray_method_bswap16>`
对数组中从偏移量为 ``offset`` 处开始的 ``count`` 个 16 位段落进行字节顺序交换的操作。交换是原地进行的。如果 ``count`` 小于零,则会处理到数组结尾为止,如果处理的数据大小不是 2 的倍数,则处理的最后一个 16 位段落之后的字节不会发生修改。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_bswap32:
.. rst-class:: classref-method
|void| **bswap32**\ (\ offset\: :ref:`int<class_int>` = 0, count\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_PackedByteArray_method_bswap32>`
对数组中从偏移量为 ``offset`` 处开始的 ``count`` 个 32 位段落进行字节顺序交换的操作。交换是原地进行的。如果 ``count`` 小于零,则会处理到数组结尾为止,如果处理的数据大小不是 4 的倍数,则处理的最后一个 32 位段落之后的字节不会发生修改。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_bswap64:
.. rst-class:: classref-method
|void| **bswap64**\ (\ offset\: :ref:`int<class_int>` = 0, count\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_PackedByteArray_method_bswap64>`
对数组中从偏移量为 ``offset`` 处开始的 ``count`` 个 64 位段落进行字节顺序交换的操作。交换是原地进行的。如果 ``count`` 小于零,则会处理到数组结尾为止,如果处理的数据大小不是 8 的倍数,则处理的最后一个 64 位段落之后的字节不会发生修改。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_clear:
.. rst-class:: classref-method
|void| **clear**\ (\ ) :ref:`🔗<class_PackedByteArray_method_clear>`
清空数组。相当于调用 :ref:`resize()<class_PackedByteArray_method_resize>` 时指定大小为 ``0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_compress:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **compress**\ (\ compression_mode\: :ref:`int<class_int>` = 0\ ) |const| :ref:`🔗<class_PackedByteArray_method_compress>`
返回新的 **PackedByteArray**\ ,其中的数据已压缩。请将压缩模式设置为 :ref:`CompressionMode<enum_FileAccess_CompressionMode>` 常量。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **count**\ (\ value\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_count>`
返回元素在数组中出现的次数。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_double:
.. rst-class:: classref-method
:ref:`float<class_float>` **decode_double**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_double>`
将字节序列解码为 64 位浮点数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_float:
.. rst-class:: classref-method
:ref:`float<class_float>` **decode_float**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_float>`
将字节序列解码为 32 位浮点数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_half:
.. rst-class:: classref-method
:ref:`float<class_float>` **decode_half**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_half>`
将字节序列解码为 16 位浮点数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_s8:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_s8**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_s8>`
将字节序列解码为 8 位有符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_s16:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_s16**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_s16>`
将字节序列解码为 16 位有符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_s32:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_s32**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_s32>`
将字节序列解码为 32 位有符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_s64:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_s64**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_s64>`
将字节序列解码为 64 位有符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_u8:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_u8**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_u8>`
将字节序列解码为 8 位无符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_u16:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_u16**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_u16>`
将字节序列解码为 16 位无符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_u32:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_u32**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_u32>`
将字节序列解码为 32 位无符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_u64:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_u64**\ (\ byte_offset\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_u64>`
将字节序列解码为 64 位无符号整数,起始位置字节偏移量为 ``byte_offset``\ 。字节数不足时会失败。如果无法解码有效的数字,则返回 ``0.0``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_var:
.. rst-class:: classref-method
:ref:`Variant<class_Variant>` **decode_var**\ (\ byte_offset\: :ref:`int<class_int>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_var>`
将字节序列解码为 :ref:`Variant<class_Variant>`\ ,起始位置字节偏移量为 ``byte_offset``\ 。如果无法解码有效的变体,或者其值派生自 :ref:`Object<class_Object>```allow_objects````false``\ ,则返回 ``null``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decode_var_size:
.. rst-class:: classref-method
:ref:`int<class_int>` **decode_var_size**\ (\ byte_offset\: :ref:`int<class_int>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_PackedByteArray_method_decode_var_size>`
将字节序列解码为 :ref:`Variant<class_Variant>` 的大小,起始位置字节偏移量为 ``byte_offset``\ 。要求起始位置后至少有 4 个字节的数据,否则会失败。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decompress:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **decompress**\ (\ buffer_size\: :ref:`int<class_int>`, compression_mode\: :ref:`int<class_int>` = 0\ ) |const| :ref:`🔗<class_PackedByteArray_method_decompress>`
返回新的 **PackedByteArray**\ ,其中的数据已解压。请将 ``buffer_size`` 设置为数据解压后的大小。请将压缩模式设置为 :ref:`CompressionMode<enum_FileAccess_CompressionMode>` 常量。
\ **注意:**\ 不保证解压缩可以处理未经 Godot 压缩的数据,例如,如果使用 deflate 压缩模式压缩的数据缺少校验和或标头。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_decompress_dynamic:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **decompress_dynamic**\ (\ max_output_size\: :ref:`int<class_int>`, compression_mode\: :ref:`int<class_int>` = 0\ ) |const| :ref:`🔗<class_PackedByteArray_method_decompress_dynamic>`
返回新的 **PackedByteArray**\ ,其中的数据已解压。请将压缩模式设置为 :ref:`CompressionMode<enum_FileAccess_CompressionMode>` 常量。\ **这个方法只接受 brotli、gzip 和 deflate 压缩模式。**\
这个方法可能比 :ref:`decompress()<class_PackedByteArray_method_decompress>` 慢,因为在解压时可能需要多次重新分配输出缓冲区,而 :ref:`decompress()<class_PackedByteArray_method_decompress>` 则在一开始就知道输出缓冲区的大小。
GZIP 的最大压缩率为 1032:1这意味着较小的压缩后负载很有可能解压出非常巨大的输出。为了防止这种情况你可以通过 ``max_output_size`` 提供允许这个函数分配的最大字节数。传入 -1 则不限制输出。传入正数且解压超过该字节数时,会返回错误。
\ **注意:**\ 不保证解压缩可以处理未经 Godot 压缩的数据,例如,如果使用 deflate 压缩模式压缩的数据缺少校验和或标头。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_duplicate:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **duplicate**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_duplicate>`
创建该数组的副本,并将该副本返回。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_double:
.. rst-class:: classref-method
|void| **encode_double**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_double>`
将 64 位浮点数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 8 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_float:
.. rst-class:: classref-method
|void| **encode_float**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_float>`
将 32 位浮点数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 4 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_half:
.. rst-class:: classref-method
|void| **encode_half**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_half>`
将 16 位浮点数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 2 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_s8:
.. rst-class:: classref-method
|void| **encode_s8**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_s8>`
将 8 位有符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 1 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_s16:
.. rst-class:: classref-method
|void| **encode_s16**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_s16>`
将 16 位有符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 2 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_s32:
.. rst-class:: classref-method
|void| **encode_s32**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_s32>`
将 32 位无符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 4 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_s64:
.. rst-class:: classref-method
|void| **encode_s64**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_s64>`
将 64 位有符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 8 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_u8:
.. rst-class:: classref-method
|void| **encode_u8**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_u8>`
将 8 位无符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 1 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_u16:
.. rst-class:: classref-method
|void| **encode_u16**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_u16>`
将 16 位无符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 2 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_u32:
.. rst-class:: classref-method
|void| **encode_u32**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_u32>`
将 32 位无符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 4 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_u64:
.. rst-class:: classref-method
|void| **encode_u64**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_encode_u64>`
将 64 位无符号整数编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。从偏移量位置开始,该数组必须还分配有至少 8 个字节的空间。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_encode_var:
.. rst-class:: classref-method
:ref:`int<class_int>` **encode_var**\ (\ byte_offset\: :ref:`int<class_int>`, value\: :ref:`Variant<class_Variant>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_PackedByteArray_method_encode_var>`
将 :ref:`Variant<class_Variant>` 编码为字节序列,起始位置字节偏移量为 ``byte_offset``\ 。必须分配有足够的空间,空间大小取决于编码后变体的大小。如果 ``allow_objects````false``\ ,则不允许派生自 :ref:`Object<class_Object>` 的值,只会将其 ID 进行序列化。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_erase:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **erase**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_erase>`
在数组中移除首次出现的某个值并返回 ``true``\ 。如果数组中不存在该值,则不会发生任何事情,返回 ``false``\ 。要按照索引移除元素,请改用 :ref:`remove_at()<class_PackedByteArray_method_remove_at>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_fill:
.. rst-class:: classref-method
|void| **fill**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_fill>`
将数组中的所有元素都设为给定的值。通常与 :ref:`resize()<class_PackedByteArray_method_resize>` 一起使用,创建给定大小的数组并初始化元素。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_find:
.. rst-class:: classref-method
:ref:`int<class_int>` **find**\ (\ value\: :ref:`int<class_int>`, from\: :ref:`int<class_int>` = 0\ ) |const| :ref:`🔗<class_PackedByteArray_method_find>`
在数组中搜索值并返回其索引,如果未找到则返回 ``-1`` 。可选地,可以传递起始搜索索引。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get:
.. rst-class:: classref-method
:ref:`int<class_int>` **get**\ (\ index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_get>`
Returns the byte at the given ``index`` in the array. If ``index`` is out-of-bounds or negative, this method fails and returns ``0``.
This method is similar (but not identical) to the ``[]`` operator. Most notably, when this method fails, it doesn't pause project execution if run from the editor.
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get_string_from_ascii:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_string_from_ascii**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_get_string_from_ascii>`
将 ASCII/Latin-1 编码的数组转换为 :ref:`String<class_String>`\ 。如果内容仅为 ASCII/Latin-1则是比 :ref:`get_string_from_utf8()<class_PackedByteArray_method_get_string_from_utf8>` 更快的选择。与 UTF-8 函数不同,这个函数会将数组中的每个字节都映射到一个字符。多字节序列无法正确解析。要解析用户的输入内容,请始终使用 :ref:`get_string_from_utf8()<class_PackedByteArray_method_get_string_from_utf8>`\ 。这是 :ref:`String.to_ascii_buffer()<class_String_method_to_ascii_buffer>` 的逆运算。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get_string_from_multibyte_char:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_string_from_multibyte_char**\ (\ encoding\: :ref:`String<class_String>` = ""\ ) |const| :ref:`🔗<class_PackedByteArray_method_get_string_from_multibyte_char>`
将使用系统多字节代码页编码的数组转换为 :ref:`String<class_String>`\ 。如果转换失败,则会返回空字符串。这是 :ref:`String.to_multibyte_char_buffer()<class_String_method_to_multibyte_char_buffer>` 的逆运算。
\ ``encoding`` 的有效值由系统决定。如果 ``encoding`` 为空字符串,则会使用系统默认的编码。
- 对于 Windows见\ `代码页标识符 <https://learn.microsoft.com/en-us/windows/win32/Intl/code-page-identifiers>`__ .NET 名称。
- 对于 macOS 和 Linux/BSD支持的编码列表见 ``libiconv`` 库文档及 ``iconv --list``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get_string_from_utf8:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_string_from_utf8**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_get_string_from_utf8>`
将 UTF-8 编码的数组转换为 :ref:`String<class_String>`\ 。比 :ref:`get_string_from_ascii()<class_PackedByteArray_method_get_string_from_ascii>` 慢,但支持 UTF-8 编码的数据。不确定数据来源时请使用此函数。对于用户的输入内容,应始终首选此函数。如果源数组不是有效的 UTF-8 字符串,则返回空字符串。这是 :ref:`String.to_utf8_buffer()<class_String_method_to_utf8_buffer>` 的逆运算。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get_string_from_utf16:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_string_from_utf16**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_get_string_from_utf16>`
将 UTF-16 编码的数组转换为 :ref:`String<class_String>`\ 。如果缺少 BOM则假定为小端字节序。如果源数组不是有效的 UTF-16 字符串,则返回空字符串。这是 :ref:`String.to_utf16_buffer()<class_String_method_to_utf16_buffer>` 的逆运算。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get_string_from_utf32:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_string_from_utf32**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_get_string_from_utf32>`
将 UTF-32 编码的数组转换为 :ref:`String<class_String>`\ 。如果源数组不是有效的 UTF-32 字符串则返回空字符串。这是 :ref:`String.to_utf32_buffer()<class_String_method_to_utf32_buffer>` 的逆运算。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_get_string_from_wchar:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_string_from_wchar**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_get_string_from_wchar>`
将宽字符(\ ``wchar_t``\ ,在 Windows 上为 UTF-16在其他平台上为 UTF-32编码的数组转换为 :ref:`String<class_String>`\ 。如果源数组不是有效的宽字符串,则返回空字符串。这是 :ref:`String.to_wchar_buffer()<class_String_method_to_wchar_buffer>` 的逆运算。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_has:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has**\ (\ value\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_PackedByteArray_method_has>`
如果该数组包含 ``value``\ ,则返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_has_encoded_var:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_encoded_var**\ (\ byte_offset\: :ref:`int<class_int>`, allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_PackedByteArray_method_has_encoded_var>`
如果可以从字节偏移量 ``byte_offset`` 处解码出有效的 :ref:`Variant<class_Variant>`\ ,则返回 ``true``\ 。其他情况,或者当该值派生自 :ref:`Object<class_Object>```allow_objects````false`` 时,则返回 ``false``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_hex_encode:
.. rst-class:: classref-method
:ref:`String<class_String>` **hex_encode**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_hex_encode>`
返回该数组的十六进制表示,类型为 :ref:`String<class_String>`\ 。
.. tabs::
.. code-tab:: gdscript
var array = PackedByteArray([11, 46, 255])
print(array.hex_encode()) # 输出“0b2eff”
.. code-tab:: csharp
byte[] array = [11, 46, 255];
GD.Print(array.HexEncode()); // 输出“0b2eff”
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_insert:
.. rst-class:: classref-method
:ref:`int<class_int>` **insert**\ (\ at_index\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_insert>`
在数组中给定的位置插入一个新元素。这个位置必须是有效的,或者是在数组的末端(\ ``idx == size()``\ )。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_is_empty:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_empty**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_is_empty>`
该数组为空时,返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_push_back:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **push_back**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_push_back>`
在数组的末尾追加一个元素。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_remove_at:
.. rst-class:: classref-method
|void| **remove_at**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_remove_at>`
从数组中删除位于索引的元素。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_resize:
.. rst-class:: classref-method
:ref:`int<class_int>` **resize**\ (\ new_size\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_resize>`
设置数组的大小。如果数组增大,则预留数组末端的元素。如果数组缩小,则将数组截断到新的大小。调用一次 :ref:`resize()<class_PackedByteArray_method_resize>` 然后赋值比逐个添加新元素要快。
成功时返回 :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`\ ,失败时返回下列 :ref:`Error<enum_@GlobalScope_Error>` 常量:大小为负数则返回 :ref:`@GlobalScope.ERR_INVALID_PARAMETER<class_@GlobalScope_constant_ERR_INVALID_PARAMETER>`\ ,分配失败则返回 :ref:`@GlobalScope.ERR_OUT_OF_MEMORY<class_@GlobalScope_constant_ERR_OUT_OF_MEMORY>`\ 。请使用 :ref:`size()<class_PackedByteArray_method_size>` 获取调整后的实际大小。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_reverse:
.. rst-class:: classref-method
|void| **reverse**\ (\ ) :ref:`🔗<class_PackedByteArray_method_reverse>`
将数组中的元素逆序排列。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_rfind:
.. rst-class:: classref-method
:ref:`int<class_int>` **rfind**\ (\ value\: :ref:`int<class_int>`, from\: :ref:`int<class_int>` = -1\ ) |const| :ref:`🔗<class_PackedByteArray_method_rfind>`
逆序搜索数组。还可以传递起始搜索位置索引。如果为负,则起始索引被视为相对于数组的结尾。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_set:
.. rst-class:: classref-method
|void| **set**\ (\ index\: :ref:`int<class_int>`, value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_method_set>`
改变给定索引处的字节。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_size:
.. rst-class:: classref-method
:ref:`int<class_int>` **size**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_size>`
返回数组中元素的个数。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_slice:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **slice**\ (\ begin\: :ref:`int<class_int>`, end\: :ref:`int<class_int>` = 2147483647\ ) |const| :ref:`🔗<class_PackedByteArray_method_slice>`
返回该 **PackedByteArray** 的切片,是从 ``begin``\ (含)到 ``end``\ (不含)的全新 **PackedByteArray**\ 。
\ ``begin````end`` 的绝对值会按数组大小进行限制,所以 ``end`` 的默认值会切到数组大小为止(即 ``arr.slice(1)````arr.slice(1, arr.size())`` 的简写)。
如果 ``begin````end`` 为负,则表示相对于数组的末尾(即 ``arr.slice(0, -2)````arr.slice(0, arr.size() - 2)`` 的简写)。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_sort:
.. rst-class:: classref-method
|void| **sort**\ (\ ) :ref:`🔗<class_PackedByteArray_method_sort>`
将该数组中的元素按升序排列。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_color_array:
.. rst-class:: classref-method
:ref:`PackedColorArray<class_PackedColorArray>` **to_color_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_color_array>`
返回数据副本转换得到的 :ref:`PackedColorArray<class_PackedColorArray>`\ ,会将每 16 个字节的数据块会转换为一个 :ref:`Color<class_Color>` 变体。
\ **注意:**\ 输入数组的大小必须为 16四个 32 位 float 变量的大小)的倍数。新数组的大小是 ``byte_array.size() / 16``\ 。如果原数据无法转换为 :ref:`Color<class_Color>` 变体,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_float32_array:
.. rst-class:: classref-method
:ref:`PackedFloat32Array<class_PackedFloat32Array>` **to_float32_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_float32_array>`
返回将数据转换为 :ref:`PackedFloat32Array<class_PackedFloat32Array>` 的副本,每 4 个字节块转换为一个 32 位浮点数C++ 的 ``float``\ )。
输入数组的大小必须为 4 的倍数32 位浮点数的大小)。新数组的大小为 ``byte_array.size() / 4``\ 。
如果原始数据无法转换为 32 位浮点数,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_float64_array:
.. rst-class:: classref-method
:ref:`PackedFloat64Array<class_PackedFloat64Array>` **to_float64_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_float64_array>`
返回将数据转换为 :ref:`PackedFloat64Array<class_PackedFloat64Array>` 的副本,每 8 个字节块转换为一个 64 位浮点数C++ 的 ``double``\ )。
输入数组的大小必须为 8 的倍数64 位浮点数的大小)。新数组的大小为 ``byte_array.size() / 8``\ 。
如果原始数据无法转换为 64 位浮点数,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_int32_array:
.. rst-class:: classref-method
:ref:`PackedInt32Array<class_PackedInt32Array>` **to_int32_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_int32_array>`
返回将数据转换为 :ref:`PackedInt32Array<class_PackedInt32Array>` 的副本,每 4 个字节块转换为一个 32 位有符号整数C++ 的 ``int32_t``\ )。
输入数组的大小必须为 4 的倍数32 位整数的大小)。新数组的大小为 ``byte_array.size() / 4``\ 。
如果原始数据无法转换为 32 位有符号整数,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_int64_array:
.. rst-class:: classref-method
:ref:`PackedInt64Array<class_PackedInt64Array>` **to_int64_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_int64_array>`
返回将数据转换为 :ref:`PackedInt64Array<class_PackedInt64Array>` 的副本,每 8 个字节块转换为一个 64 位有符号整数C++ 的 ``int64_t``\ )。
输入数组的大小必须为 8 的倍数64 位整数的大小)。新数组的大小为 ``byte_array.size() / 8``\ 。
如果原始数据无法转换为 64 位有符号整数,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_vector2_array:
.. rst-class:: classref-method
:ref:`PackedVector2Array<class_PackedVector2Array>` **to_vector2_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_vector2_array>`
返回数据副本转换得到的 :ref:`PackedVector2Array<class_PackedVector2Array>`\ ,会将每 8 个字节32 位)或每 16 个字节64 位)的数据块会转换为一个 :ref:`Vector2<class_Vector2>` 变体。
\ **注意:**\ 输入数组的大小必须为 8 或 16取决于构建设置详见 :ref:`Vector2<class_Vector2>`\ )的倍数。新数组的大小是 ``byte_array.size() / (8 或 16)``\ 。如果原数据无法转换为 :ref:`Vector2<class_Vector2>` 变体,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_vector3_array:
.. rst-class:: classref-method
:ref:`PackedVector3Array<class_PackedVector3Array>` **to_vector3_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_vector3_array>`
返回数据副本转换得到的 :ref:`PackedVector3Array<class_PackedVector3Array>`\ ,会将每 12 个字节32 位)或每 24 个字节64 位)的数据块会转换为一个 :ref:`Vector3<class_Vector3>` 变体。
\ **注意:**\ 输入数组的大小必须为 12 或 24取决于构建设置详见 :ref:`Vector3<class_Vector3>`\ )的倍数。新数组的大小是 ``byte_array.size() / (12 或 24)``\ 。如果原数据无法转换为 :ref:`Vector3<class_Vector3>` 变体,则最终的数据未定义。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_method_to_vector4_array:
.. rst-class:: classref-method
:ref:`PackedVector4Array<class_PackedVector4Array>` **to_vector4_array**\ (\ ) |const| :ref:`🔗<class_PackedByteArray_method_to_vector4_array>`
返回数据副本转换得到的 :ref:`PackedVector4Array<class_PackedVector4Array>`\ ,会将每 16 个字节32 位)或每 32 个字节64 位)的数据块会转换为一个 :ref:`Vector4<class_Vector4>` 变体。
\ **注意:**\ 输入数组的大小必须为 16 或 32取决于构建设置详见 :ref:`Vector4<class_Vector4>`\ )的倍数。新数组的大小是 ``byte_array.size() / (16 或 32)``\ 。如果原数据无法转换为 :ref:`Vector4<class_Vector4>` 变体,则最终的数据未定义。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
运算符说明
----------
.. _class_PackedByteArray_operator_neq_PackedByteArray:
.. rst-class:: classref-operator
:ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_PackedByteArray_operator_neq_PackedByteArray>`
如果数组内容不同,则返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_operator_sum_PackedByteArray:
.. rst-class:: classref-operator
:ref:`PackedByteArray<class_PackedByteArray>` **operator +**\ (\ right\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_PackedByteArray_operator_sum_PackedByteArray>`
返回新的 **PackedByteArray**\ ,新数组的内容为此数组在末尾加上 ``right``\ 。为了提高性能,请考虑改用 :ref:`append_array()<class_PackedByteArray_method_append_array>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_operator_eq_PackedByteArray:
.. rst-class:: classref-operator
:ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_PackedByteArray_operator_eq_PackedByteArray>`
如果两个数组的内容相同,即对应索引号的字节相等,则返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_PackedByteArray_operator_idx_int:
.. rst-class:: classref-operator
:ref:`int<class_int>` **operator []**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_PackedByteArray_operator_idx_int>`
返回索引 ``index`` 处的字节。负数索引可以从末尾开始访问元素。使用越界的索引会报错。
请注意,返回的字节是 64 位 :ref:`int<class_int>`\ 。
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
.. |void| replace:: :abbr:`void (无返回值。)`