class_poolbytearray.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/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. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`compress<class_PoolByteArray_method_compress>` **(** :ref:`int<class_int>` compression_mode=0 **)** |
  39. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`count<class_PoolByteArray_method_count>` **(** :ref:`int<class_int>` value **)** |
  41. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`decompress<class_PoolByteArray_method_decompress>` **(** :ref:`int<class_int>` buffer_size, :ref:`int<class_int>` compression_mode=0 **)** |
  43. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :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 **)** |
  45. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`empty<class_PoolByteArray_method_empty>` **(** **)** |
  47. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`fill<class_PoolByteArray_method_fill>` **(** :ref:`int<class_int>` byte **)** |
  49. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`find<class_PoolByteArray_method_find>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=0 **)** |
  51. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`String<class_String>` | :ref:`get_string_from_ascii<class_PoolByteArray_method_get_string_from_ascii>` **(** **)** |
  53. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`String<class_String>` | :ref:`get_string_from_utf8<class_PoolByteArray_method_get_string_from_utf8>` **(** **)** |
  55. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`bool<class_bool>` | :ref:`has<class_PoolByteArray_method_has>` **(** :ref:`int<class_int>` value **)** |
  57. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`String<class_String>` | :ref:`hex_encode<class_PoolByteArray_method_hex_encode>` **(** **)** |
  59. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`int<class_int>` | :ref:`insert<class_PoolByteArray_method_insert>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)** |
  61. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`invert<class_PoolByteArray_method_invert>` **(** **)** |
  63. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`push_back<class_PoolByteArray_method_push_back>` **(** :ref:`int<class_int>` byte **)** |
  65. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`remove<class_PoolByteArray_method_remove>` **(** :ref:`int<class_int>` idx **)** |
  67. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`resize<class_PoolByteArray_method_resize>` **(** :ref:`int<class_int>` idx **)** |
  69. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`int<class_int>` | :ref:`rfind<class_PoolByteArray_method_rfind>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=-1 **)** |
  71. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set<class_PoolByteArray_method_set>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)** |
  73. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`int<class_int>` | :ref:`size<class_PoolByteArray_method_size>` **(** **)** |
  75. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`sort<class_PoolByteArray_method_sort>` **(** **)** |
  77. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`subarray<class_PoolByteArray_method_subarray>` **(** :ref:`int<class_int>` from, :ref:`int<class_int>` to **)** |
  79. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. .. rst-class:: classref-section-separator
  81. ----
  82. .. rst-class:: classref-descriptions-group
  83. Method Descriptions
  84. -------------------
  85. .. _class_PoolByteArray_method_PoolByteArray:
  86. .. rst-class:: classref-method
  87. :ref:`PoolByteArray<class_PoolByteArray>` **PoolByteArray** **(** :ref:`Array<class_Array>` from **)**
  88. Constructs a new **PoolByteArray**. Optionally, you can pass in a generic :ref:`Array<class_Array>` that will be converted.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_PoolByteArray_method_append:
  92. .. rst-class:: classref-method
  93. void **append** **(** :ref:`int<class_int>` byte **)**
  94. Appends an element at the end of the array (alias of :ref:`push_back<class_PoolByteArray_method_push_back>`).
  95. .. rst-class:: classref-item-separator
  96. ----
  97. .. _class_PoolByteArray_method_append_array:
  98. .. rst-class:: classref-method
  99. void **append_array** **(** :ref:`PoolByteArray<class_PoolByteArray>` array **)**
  100. Appends a **PoolByteArray** at the end of this array.
  101. .. rst-class:: classref-item-separator
  102. ----
  103. .. _class_PoolByteArray_method_compress:
  104. .. rst-class:: classref-method
  105. :ref:`PoolByteArray<class_PoolByteArray>` **compress** **(** :ref:`int<class_int>` compression_mode=0 **)**
  106. Returns a new **PoolByteArray** with the data compressed. Set the compression mode using one of :ref:`CompressionMode<enum_File_CompressionMode>`'s constants.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_PoolByteArray_method_count:
  110. .. rst-class:: classref-method
  111. :ref:`int<class_int>` **count** **(** :ref:`int<class_int>` value **)**
  112. Returns the number of times an element is in the array.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_PoolByteArray_method_decompress:
  116. .. rst-class:: classref-method
  117. :ref:`PoolByteArray<class_PoolByteArray>` **decompress** **(** :ref:`int<class_int>` buffer_size, :ref:`int<class_int>` compression_mode=0 **)**
  118. 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.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_PoolByteArray_method_decompress_dynamic:
  122. .. rst-class:: classref-method
  123. :ref:`PoolByteArray<class_PoolByteArray>` **decompress_dynamic** **(** :ref:`int<class_int>` max_output_size, :ref:`int<class_int>` compression_mode=0 **)**
  124. 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.**\
  125. 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.
  126. 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.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_PoolByteArray_method_empty:
  130. .. rst-class:: classref-method
  131. :ref:`bool<class_bool>` **empty** **(** **)**
  132. Returns ``true`` if the array is empty.
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. _class_PoolByteArray_method_fill:
  136. .. rst-class:: classref-method
  137. void **fill** **(** :ref:`int<class_int>` byte **)**
  138. 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.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_PoolByteArray_method_find:
  142. .. rst-class:: classref-method
  143. :ref:`int<class_int>` **find** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=0 **)**
  144. 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.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_PoolByteArray_method_get_string_from_ascii:
  148. .. rst-class:: classref-method
  149. :ref:`String<class_String>` **get_string_from_ascii** **(** **)**
  150. 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>`.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_PoolByteArray_method_get_string_from_utf8:
  154. .. rst-class:: classref-method
  155. :ref:`String<class_String>` **get_string_from_utf8** **(** **)**
  156. 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.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_PoolByteArray_method_has:
  160. .. rst-class:: classref-method
  161. :ref:`bool<class_bool>` **has** **(** :ref:`int<class_int>` value **)**
  162. Returns ``true`` if the array contains the given value.
  163. \ **Note:** This is equivalent to using the ``in`` operator.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_PoolByteArray_method_hex_encode:
  167. .. rst-class:: classref-method
  168. :ref:`String<class_String>` **hex_encode** **(** **)**
  169. Returns a hexadecimal representation of this array as a :ref:`String<class_String>`.
  170. ::
  171. var array = PoolByteArray([11, 46, 255])
  172. print(array.hex_encode()) # Prints: 0b2eff
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_PoolByteArray_method_insert:
  176. .. rst-class:: classref-method
  177. :ref:`int<class_int>` **insert** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)**
  178. 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()``).
  179. .. rst-class:: classref-item-separator
  180. ----
  181. .. _class_PoolByteArray_method_invert:
  182. .. rst-class:: classref-method
  183. void **invert** **(** **)**
  184. Reverses the order of the elements in the array.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_PoolByteArray_method_push_back:
  188. .. rst-class:: classref-method
  189. void **push_back** **(** :ref:`int<class_int>` byte **)**
  190. Appends an element at the end of the array.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_PoolByteArray_method_remove:
  194. .. rst-class:: classref-method
  195. void **remove** **(** :ref:`int<class_int>` idx **)**
  196. Removes an element from the array by index.
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_PoolByteArray_method_resize:
  200. .. rst-class:: classref-method
  201. void **resize** **(** :ref:`int<class_int>` idx **)**
  202. 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.
  203. \ **Note:** Added elements are not automatically initialized to 0 and will contain garbage, i.e. indeterminate values.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_PoolByteArray_method_rfind:
  207. .. rst-class:: classref-method
  208. :ref:`int<class_int>` **rfind** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` from=-1 **)**
  209. 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.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_PoolByteArray_method_set:
  213. .. rst-class:: classref-method
  214. void **set** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` byte **)**
  215. Changes the byte at the given index.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_PoolByteArray_method_size:
  219. .. rst-class:: classref-method
  220. :ref:`int<class_int>` **size** **(** **)**
  221. Returns the number of elements in the array.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_PoolByteArray_method_sort:
  225. .. rst-class:: classref-method
  226. void **sort** **(** **)**
  227. Sorts the elements of the array in ascending order.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_PoolByteArray_method_subarray:
  231. .. rst-class:: classref-method
  232. :ref:`PoolByteArray<class_PoolByteArray>` **subarray** **(** :ref:`int<class_int>` from, :ref:`int<class_int>` to **)**
  233. 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.
  234. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  235. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  236. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  237. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`