PoolByteArray.xml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="PoolByteArray" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. A pooled array of bytes.
  5. </brief_description>
  6. <description>
  7. An array specifically designed to hold bytes. Optimized for memory usage, does not fragment the memory.
  8. [b]Note:[/b] This type is passed by value and not by reference. This means that when [i]mutating[/i] a class property of type [PoolByteArray] or mutating a [PoolByteArray] within an [Array] or [Dictionary], changes will be lost:
  9. [codeblock]
  10. var array = [PoolByteArray()]
  11. array[0].push_back(123)
  12. print(array) # [[]] (empty PoolByteArray within an Array)
  13. [/codeblock]
  14. Instead, the entire [PoolByteArray] property must be [i]reassigned[/i] with [code]=[/code] for it to be changed:
  15. [codeblock]
  16. var array = [PoolByteArray()]
  17. var pool_array = array[0]
  18. pool_array.push_back(123)
  19. array[0] = pool_array
  20. print(array) # [[123]] (PoolByteArray with 1 element inside an Array)
  21. [/codeblock]
  22. </description>
  23. <tutorials>
  24. </tutorials>
  25. <methods>
  26. <method name="PoolByteArray">
  27. <return type="PoolByteArray" />
  28. <argument index="0" name="from" type="Array" />
  29. <description>
  30. Constructs a new [PoolByteArray]. Optionally, you can pass in a generic [Array] that will be converted.
  31. </description>
  32. </method>
  33. <method name="append">
  34. <argument index="0" name="byte" type="int" />
  35. <description>
  36. Appends an element at the end of the array (alias of [method push_back]).
  37. </description>
  38. </method>
  39. <method name="append_array">
  40. <argument index="0" name="array" type="PoolByteArray" />
  41. <description>
  42. Appends a [PoolByteArray] at the end of this array.
  43. </description>
  44. </method>
  45. <method name="clear">
  46. <description>
  47. Clears the array. This is equivalent to using [method resize] with a size of [code]0[/code].
  48. </description>
  49. </method>
  50. <method name="compress">
  51. <return type="PoolByteArray" />
  52. <argument index="0" name="compression_mode" type="int" default="0" />
  53. <description>
  54. Returns a new [PoolByteArray] with the data compressed. Set the compression mode using one of [enum File.CompressionMode]'s constants.
  55. </description>
  56. </method>
  57. <method name="count">
  58. <return type="int" />
  59. <argument index="0" name="value" type="int" />
  60. <description>
  61. Returns the number of times an element is in the array.
  62. </description>
  63. </method>
  64. <method name="decompress">
  65. <return type="PoolByteArray" />
  66. <argument index="0" name="buffer_size" type="int" />
  67. <argument index="1" name="compression_mode" type="int" default="0" />
  68. <description>
  69. Returns a new [PoolByteArray] with the data decompressed. Set [code]buffer_size[/code] to the size of the uncompressed data. Set the compression mode using one of [enum File.CompressionMode]'s constants.
  70. </description>
  71. </method>
  72. <method name="decompress_dynamic">
  73. <return type="PoolByteArray" />
  74. <argument index="0" name="max_output_size" type="int" />
  75. <argument index="1" name="compression_mode" type="int" default="0" />
  76. <description>
  77. Returns a new [PoolByteArray] with the data decompressed. Set the compression mode using one of [enum File.CompressionMode]'s constants. [b]This method only accepts gzip and deflate compression modes.[/b]
  78. This method is potentially slower than [code]decompress[/code], as it may have to re-allocate its output buffer multiple times while decompressing, where as [code]decompress[/code] knows its output buffer size from the beginning.
  79. 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 [code]max_output_size[/code]. 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.
  80. </description>
  81. </method>
  82. <method name="empty">
  83. <return type="bool" />
  84. <description>
  85. Returns [code]true[/code] if the array is empty.
  86. </description>
  87. </method>
  88. <method name="fill">
  89. <argument index="0" name="byte" type="int" />
  90. <description>
  91. Assigns the given value to all elements in the array. This can typically be used together with [method resize] to create an array with a given size and initialized elements.
  92. </description>
  93. </method>
  94. <method name="find">
  95. <return type="int" />
  96. <argument index="0" name="value" type="int" />
  97. <argument index="1" name="from" type="int" default="0" />
  98. <description>
  99. Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
  100. </description>
  101. </method>
  102. <method name="get">
  103. <return type="int" />
  104. <argument index="0" name="index" type="int" />
  105. <description>
  106. Returns the byte at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
  107. </description>
  108. </method>
  109. <method name="get_string_from_ascii">
  110. <return type="String" />
  111. <description>
  112. Returns a copy of the array's contents as [String]. Fast alternative to [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 [method get_string_from_utf8].
  113. </description>
  114. </method>
  115. <method name="get_string_from_utf8">
  116. <return type="String" />
  117. <description>
  118. Returns a copy of the array's contents as [String]. Slower than [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.
  119. </description>
  120. </method>
  121. <method name="has">
  122. <return type="bool" />
  123. <argument index="0" name="value" type="int" />
  124. <description>
  125. Returns [code]true[/code] if the array contains the given value.
  126. [b]Note:[/b] This is equivalent to using the [code]in[/code] operator.
  127. </description>
  128. </method>
  129. <method name="hex_encode">
  130. <return type="String" />
  131. <description>
  132. Returns a hexadecimal representation of this array as a [String].
  133. [codeblock]
  134. var array = PoolByteArray([11, 46, 255])
  135. print(array.hex_encode()) # Prints: 0b2eff
  136. [/codeblock]
  137. </description>
  138. </method>
  139. <method name="insert">
  140. <return type="int" />
  141. <argument index="0" name="idx" type="int" />
  142. <argument index="1" name="byte" type="int" />
  143. <description>
  144. Inserts a new element at a given position in the array. The position must be valid, or at the end of the array ([code]idx == size()[/code]).
  145. </description>
  146. </method>
  147. <method name="invert">
  148. <description>
  149. Reverses the order of the elements in the array.
  150. </description>
  151. </method>
  152. <method name="push_back">
  153. <argument index="0" name="byte" type="int" />
  154. <description>
  155. Appends an element at the end of the array.
  156. </description>
  157. </method>
  158. <method name="remove">
  159. <argument index="0" name="idx" type="int" />
  160. <description>
  161. Removes an element from the array by index.
  162. </description>
  163. </method>
  164. <method name="resize">
  165. <argument index="0" name="idx" type="int" />
  166. <description>
  167. 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.
  168. [b]Note:[/b] Added elements are not automatically initialized to 0 and will contain garbage, i.e. indeterminate values.
  169. </description>
  170. </method>
  171. <method name="rfind">
  172. <return type="int" />
  173. <argument index="0" name="value" type="int" />
  174. <argument index="1" name="from" type="int" default="-1" />
  175. <description>
  176. 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.
  177. </description>
  178. </method>
  179. <method name="set">
  180. <argument index="0" name="idx" type="int" />
  181. <argument index="1" name="byte" type="int" />
  182. <description>
  183. Changes the byte at the given index.
  184. </description>
  185. </method>
  186. <method name="size">
  187. <return type="int" />
  188. <description>
  189. Returns the number of elements in the array.
  190. </description>
  191. </method>
  192. <method name="sort">
  193. <description>
  194. Sorts the elements of the array in ascending order.
  195. </description>
  196. </method>
  197. <method name="subarray">
  198. <return type="PoolByteArray" />
  199. <argument index="0" name="from" type="int" />
  200. <argument index="1" name="to" type="int" />
  201. <description>
  202. 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.
  203. </description>
  204. </method>
  205. </methods>
  206. <constants>
  207. </constants>
  208. </class>