class_poolbytearray.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/PoolByteArray.xml.
  6. .. _class_PoolByteArray:
  7. PoolByteArray
  8. =============
  9. A pooled array of bytes.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. An array specifically designed to hold bytes. Optimized for memory usage, does not fragment the memory.
  14. \ **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 :ref:`Array<class_Array>` or :ref:`Dictionary<class_Dictionary>`, changes will be lost:
  15. ::
  16. var array = [PoolByteArray()]
  17. array[0].push_back(123)
  18. print(array) # [[]] (empty PoolByteArray within an Array)
  19. Instead, the entire **PoolByteArray** property must be *reassigned* with ``=`` for it to be changed:
  20. ::
  21. var array = [PoolByteArray()]
  22. var pool_array = array[0]
  23. pool_array.push_back(123)
  24. array[0] = pool_array
  25. print(array) # [[123]] (PoolByteArray with 1 element inside an Array)
  26. .. rst-class:: classref-reftable-group
  27. Methods
  28. -------
  29. .. table::
  30. :widths: auto
  31. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`PoolByteArray<class_PoolByteArray_method_PoolByteArray>` **(** :ref:`Array<class_Array>` from **)** |
  33. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`append<class_PoolByteArray_method_append>` **(** :ref:`int<class_int>` byte **)** |
  35. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`append_array<class_PoolByteArray_method_append_array>` **(** :ref:`PoolByteArray<class_PoolByteArray>` array **)** |
  37. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`clear<class_PoolByteArray_method_clear>` **(** **)** |
  39. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`compress<class_PoolByteArray_method_compress>` **(** :ref:`int<class_int>` compression_mode=0 **)** |
  41. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`int<class_int>` | :ref:`count<class_PoolByteArray_method_count>` **(** :ref:`int<class_int>` value **)** |
  43. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`decompress<class_PoolByteArray_method_decompress>` **(** :ref:`int<class_int>` buffer_size, :ref:`int<class_int>` compression_mode=0 **)** |
  45. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`decompress_dynamic<class_PoolByteArray_method_decompress_dynamic>` **(** :ref:`int<class_int>` max_output_size, :ref:`int<class_int>` compression_mode=0 **)** |
  47. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`empty<class_PoolByteArray_method_empty>` **(** **)** |
  49. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`fill<class_PoolByteArray_method_fill>` **(** :ref:`int<class_int>` byte **)** |
  51. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`find<class_PoolByteArray_method_find>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=0 **)** |
  53. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`String<class_String>` | :ref:`get_string_from_ascii<class_PoolByteArray_method_get_string_from_ascii>` **(** **)** |
  55. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`String<class_String>` | :ref:`get_string_from_utf8<class_PoolByteArray_method_get_string_from_utf8>` **(** **)** |
  57. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`has<class_PoolByteArray_method_has>` **(** :ref:`int<class_int>` value **)** |
  59. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`String<class_String>` | :ref:`hex_encode<class_PoolByteArray_method_hex_encode>` **(** **)** |
  61. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`int<class_int>` | :ref:`insert<class_PoolByteArray_method_insert>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)** |
  63. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`invert<class_PoolByteArray_method_invert>` **(** **)** |
  65. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`push_back<class_PoolByteArray_method_push_back>` **(** :ref:`int<class_int>` byte **)** |
  67. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`remove<class_PoolByteArray_method_remove>` **(** :ref:`int<class_int>` idx **)** |
  69. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`resize<class_PoolByteArray_method_resize>` **(** :ref:`int<class_int>` idx **)** |
  71. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`rfind<class_PoolByteArray_method_rfind>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=-1 **)** |
  73. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set<class_PoolByteArray_method_set>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)** |
  75. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`int<class_int>` | :ref:`size<class_PoolByteArray_method_size>` **(** **)** |
  77. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`sort<class_PoolByteArray_method_sort>` **(** **)** |
  79. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`subarray<class_PoolByteArray_method_subarray>` **(** :ref:`int<class_int>` from, :ref:`int<class_int>` to **)** |
  81. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. .. rst-class:: classref-section-separator
  83. ----
  84. .. rst-class:: classref-descriptions-group
  85. Method Descriptions
  86. -------------------
  87. .. _class_PoolByteArray_method_PoolByteArray:
  88. .. rst-class:: classref-method
  89. :ref:`PoolByteArray<class_PoolByteArray>` **PoolByteArray** **(** :ref:`Array<class_Array>` from **)**
  90. Constructs a new **PoolByteArray**. Optionally, you can pass in a generic :ref:`Array<class_Array>` that will be converted.
  91. .. rst-class:: classref-item-separator
  92. ----
  93. .. _class_PoolByteArray_method_append:
  94. .. rst-class:: classref-method
  95. void **append** **(** :ref:`int<class_int>` byte **)**
  96. Appends an element at the end of the array (alias of :ref:`push_back<class_PoolByteArray_method_push_back>`).
  97. .. rst-class:: classref-item-separator
  98. ----
  99. .. _class_PoolByteArray_method_append_array:
  100. .. rst-class:: classref-method
  101. void **append_array** **(** :ref:`PoolByteArray<class_PoolByteArray>` array **)**
  102. Appends a **PoolByteArray** at the end of this array.
  103. .. rst-class:: classref-item-separator
  104. ----
  105. .. _class_PoolByteArray_method_clear:
  106. .. rst-class:: classref-method
  107. void **clear** **(** **)**
  108. Clears the array. This is equivalent to using :ref:`resize<class_PoolByteArray_method_resize>` with a size of ``0``.
  109. .. rst-class:: classref-item-separator
  110. ----
  111. .. _class_PoolByteArray_method_compress:
  112. .. rst-class:: classref-method
  113. :ref:`PoolByteArray<class_PoolByteArray>` **compress** **(** :ref:`int<class_int>` compression_mode=0 **)**
  114. Returns a new **PoolByteArray** with the data compressed. Set the compression mode using one of :ref:`CompressionMode<enum_File_CompressionMode>`'s constants.
  115. .. rst-class:: classref-item-separator
  116. ----
  117. .. _class_PoolByteArray_method_count:
  118. .. rst-class:: classref-method
  119. :ref:`int<class_int>` **count** **(** :ref:`int<class_int>` value **)**
  120. Returns the number of times an element is in the array.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_PoolByteArray_method_decompress:
  124. .. rst-class:: classref-method
  125. :ref:`PoolByteArray<class_PoolByteArray>` **decompress** **(** :ref:`int<class_int>` buffer_size, :ref:`int<class_int>` compression_mode=0 **)**
  126. Returns a new **PoolByteArray** with the data decompressed. Set ``buffer_size`` to the size of the uncompressed data. Set the compression mode using one of :ref:`CompressionMode<enum_File_CompressionMode>`'s constants.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_PoolByteArray_method_decompress_dynamic:
  130. .. rst-class:: classref-method
  131. :ref:`PoolByteArray<class_PoolByteArray>` **decompress_dynamic** **(** :ref:`int<class_int>` max_output_size, :ref:`int<class_int>` compression_mode=0 **)**
  132. Returns a new **PoolByteArray** with the data decompressed. Set the compression mode using one of :ref:`CompressionMode<enum_File_CompressionMode>`'s constants. **This method only accepts gzip and deflate compression modes.**\
  133. This method is potentially slower than ``decompress``, as it may have to re-allocate its output buffer multiple times while decompressing, where as ``decompress`` knows its output buffer size from the beginning.
  134. GZIP has a maximal compression ratio of 1032:1, meaning it's very possible for a small compressed payload to decompress to a potentially very large output. To guard against this, you may provide a maximum size this function is allowed to allocate in bytes via ``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.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_PoolByteArray_method_empty:
  138. .. rst-class:: classref-method
  139. :ref:`bool<class_bool>` **empty** **(** **)**
  140. Returns ``true`` if the array is empty.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_PoolByteArray_method_fill:
  144. .. rst-class:: classref-method
  145. void **fill** **(** :ref:`int<class_int>` byte **)**
  146. Assigns the given value to all elements in the array. This can typically be used together with :ref:`resize<class_PoolByteArray_method_resize>` to create an array with a given size and initialized elements.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_PoolByteArray_method_find:
  150. .. rst-class:: classref-method
  151. :ref:`int<class_int>` **find** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=0 **)**
  152. Searches the array for a value and returns its index or ``-1`` if not found. Optionally, the initial search index can be passed. Returns ``-1`` if ``from`` is out of bounds.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_PoolByteArray_method_get_string_from_ascii:
  156. .. rst-class:: classref-method
  157. :ref:`String<class_String>` **get_string_from_ascii** **(** **)**
  158. Returns a copy of the array's contents as :ref:`String<class_String>`. Fast alternative to :ref:`get_string_from_utf8<class_PoolByteArray_method_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 :ref:`get_string_from_utf8<class_PoolByteArray_method_get_string_from_utf8>`.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. _class_PoolByteArray_method_get_string_from_utf8:
  162. .. rst-class:: classref-method
  163. :ref:`String<class_String>` **get_string_from_utf8** **(** **)**
  164. Returns a copy of the array's contents as :ref:`String<class_String>`. Slower than :ref:`get_string_from_ascii<class_PoolByteArray_method_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.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_PoolByteArray_method_has:
  168. .. rst-class:: classref-method
  169. :ref:`bool<class_bool>` **has** **(** :ref:`int<class_int>` value **)**
  170. Returns ``true`` if the array contains the given value.
  171. \ **Note:** This is equivalent to using the ``in`` operator.
  172. .. rst-class:: classref-item-separator
  173. ----
  174. .. _class_PoolByteArray_method_hex_encode:
  175. .. rst-class:: classref-method
  176. :ref:`String<class_String>` **hex_encode** **(** **)**
  177. Returns a hexadecimal representation of this array as a :ref:`String<class_String>`.
  178. ::
  179. var array = PoolByteArray([11, 46, 255])
  180. print(array.hex_encode()) # Prints: 0b2eff
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_PoolByteArray_method_insert:
  184. .. rst-class:: classref-method
  185. :ref:`int<class_int>` **insert** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)**
  186. 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()``).
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_PoolByteArray_method_invert:
  190. .. rst-class:: classref-method
  191. void **invert** **(** **)**
  192. Reverses the order of the elements in the array.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_PoolByteArray_method_push_back:
  196. .. rst-class:: classref-method
  197. void **push_back** **(** :ref:`int<class_int>` byte **)**
  198. Appends an element at the end of the array.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_PoolByteArray_method_remove:
  202. .. rst-class:: classref-method
  203. void **remove** **(** :ref:`int<class_int>` idx **)**
  204. Removes an element from the array by index.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_PoolByteArray_method_resize:
  208. .. rst-class:: classref-method
  209. void **resize** **(** :ref:`int<class_int>` idx **)**
  210. 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.
  211. \ **Note:** Added elements are not automatically initialized to 0 and will contain garbage, i.e. indeterminate values.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_PoolByteArray_method_rfind:
  215. .. rst-class:: classref-method
  216. :ref:`int<class_int>` **rfind** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=-1 **)**
  217. 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.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_PoolByteArray_method_set:
  221. .. rst-class:: classref-method
  222. void **set** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)**
  223. Changes the byte at the given index.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_PoolByteArray_method_size:
  227. .. rst-class:: classref-method
  228. :ref:`int<class_int>` **size** **(** **)**
  229. Returns the number of elements in the array.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_PoolByteArray_method_sort:
  233. .. rst-class:: classref-method
  234. void **sort** **(** **)**
  235. Sorts the elements of the array in ascending order.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_PoolByteArray_method_subarray:
  239. .. rst-class:: classref-method
  240. :ref:`PoolByteArray<class_PoolByteArray>` **subarray** **(** :ref:`int<class_int>` from, :ref:`int<class_int>` to **)**
  241. Returns the slice of the **PoolByteArray** between indices (inclusive) as a new **PoolByteArray**. Any negative index is considered to be from the end of the array.
  242. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  243. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  244. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  245. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`