class_streampeer.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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/StreamPeer.xml.
  6. .. _class_StreamPeer:
  7. StreamPeer
  8. ==========
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`StreamPeerBuffer<class_StreamPeerBuffer>`, :ref:`StreamPeerGDNative<class_StreamPeerGDNative>`, :ref:`StreamPeerSSL<class_StreamPeerSSL>`, :ref:`StreamPeerTCP<class_StreamPeerTCP>`
  11. Abstraction and base class for stream-based protocols.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. StreamPeer is an abstraction and base class for stream-based protocols (such as TCP). It provides an API for sending and receiving data through streams as raw data or strings.
  16. .. rst-class:: classref-reftable-group
  17. Properties
  18. ----------
  19. .. table::
  20. :widths: auto
  21. +-------------------------+---------------------------------------------------------+-----------+
  22. | :ref:`bool<class_bool>` | :ref:`big_endian<class_StreamPeer_property_big_endian>` | ``false`` |
  23. +-------------------------+---------------------------------------------------------+-----------+
  24. .. rst-class:: classref-reftable-group
  25. Methods
  26. -------
  27. .. table::
  28. :widths: auto
  29. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`int<class_int>` | :ref:`get_16<class_StreamPeer_method_get_16>` **(** **)** |
  31. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_32<class_StreamPeer_method_get_32>` **(** **)** |
  33. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_64<class_StreamPeer_method_get_64>` **(** **)** |
  35. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`get_8<class_StreamPeer_method_get_8>` **(** **)** |
  37. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`get_available_bytes<class_StreamPeer_method_get_available_bytes>` **(** **)** |const| |
  39. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Array<class_Array>` | :ref:`get_data<class_StreamPeer_method_get_data>` **(** :ref:`int<class_int>` bytes **)** |
  41. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`float<class_float>` | :ref:`get_double<class_StreamPeer_method_get_double>` **(** **)** |
  43. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`get_float<class_StreamPeer_method_get_float>` **(** **)** |
  45. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Array<class_Array>` | :ref:`get_partial_data<class_StreamPeer_method_get_partial_data>` **(** :ref:`int<class_int>` bytes **)** |
  47. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`get_string<class_StreamPeer_method_get_string>` **(** :ref:`int<class_int>` bytes=-1 **)** |
  49. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`get_u16<class_StreamPeer_method_get_u16>` **(** **)** |
  51. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`get_u32<class_StreamPeer_method_get_u32>` **(** **)** |
  53. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`get_u64<class_StreamPeer_method_get_u64>` **(** **)** |
  55. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`get_u8<class_StreamPeer_method_get_u8>` **(** **)** |
  57. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`String<class_String>` | :ref:`get_utf8_string<class_StreamPeer_method_get_utf8_string>` **(** :ref:`int<class_int>` bytes=-1 **)** |
  59. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_StreamPeer_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |
  61. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`put_16<class_StreamPeer_method_put_16>` **(** :ref:`int<class_int>` value **)** |
  63. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`put_32<class_StreamPeer_method_put_32>` **(** :ref:`int<class_int>` value **)** |
  65. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`put_64<class_StreamPeer_method_put_64>` **(** :ref:`int<class_int>` value **)** |
  67. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`put_8<class_StreamPeer_method_put_8>` **(** :ref:`int<class_int>` value **)** |
  69. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_data<class_StreamPeer_method_put_data>` **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  71. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`put_double<class_StreamPeer_method_put_double>` **(** :ref:`float<class_float>` value **)** |
  73. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`put_float<class_StreamPeer_method_put_float>` **(** :ref:`float<class_float>` value **)** |
  75. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Array<class_Array>` | :ref:`put_partial_data<class_StreamPeer_method_put_partial_data>` **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  77. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`put_string<class_StreamPeer_method_put_string>` **(** :ref:`String<class_String>` value **)** |
  79. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`put_u16<class_StreamPeer_method_put_u16>` **(** :ref:`int<class_int>` value **)** |
  81. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`put_u32<class_StreamPeer_method_put_u32>` **(** :ref:`int<class_int>` value **)** |
  83. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`put_u64<class_StreamPeer_method_put_u64>` **(** :ref:`int<class_int>` value **)** |
  85. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`put_u8<class_StreamPeer_method_put_u8>` **(** :ref:`int<class_int>` value **)** |
  87. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  88. | void | :ref:`put_utf8_string<class_StreamPeer_method_put_utf8_string>` **(** :ref:`String<class_String>` value **)** |
  89. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`put_var<class_StreamPeer_method_put_var>` **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)** |
  91. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  92. .. rst-class:: classref-section-separator
  93. ----
  94. .. rst-class:: classref-descriptions-group
  95. Property Descriptions
  96. ---------------------
  97. .. _class_StreamPeer_property_big_endian:
  98. .. rst-class:: classref-property
  99. :ref:`bool<class_bool>` **big_endian** = ``false``
  100. .. rst-class:: classref-property-setget
  101. - void **set_big_endian** **(** :ref:`bool<class_bool>` value **)**
  102. - :ref:`bool<class_bool>` **is_big_endian_enabled** **(** **)**
  103. If ``true``, this **StreamPeer** will using big-endian format for encoding and decoding.
  104. .. rst-class:: classref-section-separator
  105. ----
  106. .. rst-class:: classref-descriptions-group
  107. Method Descriptions
  108. -------------------
  109. .. _class_StreamPeer_method_get_16:
  110. .. rst-class:: classref-method
  111. :ref:`int<class_int>` **get_16** **(** **)**
  112. Gets a signed 16-bit value from the stream.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_StreamPeer_method_get_32:
  116. .. rst-class:: classref-method
  117. :ref:`int<class_int>` **get_32** **(** **)**
  118. Gets a signed 32-bit value from the stream.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_StreamPeer_method_get_64:
  122. .. rst-class:: classref-method
  123. :ref:`int<class_int>` **get_64** **(** **)**
  124. Gets a signed 64-bit value from the stream.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_StreamPeer_method_get_8:
  128. .. rst-class:: classref-method
  129. :ref:`int<class_int>` **get_8** **(** **)**
  130. Gets a signed byte from the stream.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_StreamPeer_method_get_available_bytes:
  134. .. rst-class:: classref-method
  135. :ref:`int<class_int>` **get_available_bytes** **(** **)** |const|
  136. Returns the amount of bytes this **StreamPeer** has available.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_StreamPeer_method_get_data:
  140. .. rst-class:: classref-method
  141. :ref:`Array<class_Array>` **get_data** **(** :ref:`int<class_int>` bytes **)**
  142. Returns a chunk data with the received bytes. The amount of bytes to be received can be requested in the ``bytes`` argument. If not enough bytes are available, the function will block until the desired amount is received. This function returns two values, an :ref:`Error<enum_@GlobalScope_Error>` code and a data array.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_StreamPeer_method_get_double:
  146. .. rst-class:: classref-method
  147. :ref:`float<class_float>` **get_double** **(** **)**
  148. Gets a double-precision float from the stream.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_StreamPeer_method_get_float:
  152. .. rst-class:: classref-method
  153. :ref:`float<class_float>` **get_float** **(** **)**
  154. Gets a single-precision float from the stream.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_StreamPeer_method_get_partial_data:
  158. .. rst-class:: classref-method
  159. :ref:`Array<class_Array>` **get_partial_data** **(** :ref:`int<class_int>` bytes **)**
  160. Returns a chunk data with the received bytes. The amount of bytes to be received can be requested in the "bytes" argument. If not enough bytes are available, the function will return how many were actually received. This function returns two values, an :ref:`Error<enum_@GlobalScope_Error>` code, and a data array.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_StreamPeer_method_get_string:
  164. .. rst-class:: classref-method
  165. :ref:`String<class_String>` **get_string** **(** :ref:`int<class_int>` bytes=-1 **)**
  166. Gets an ASCII string with byte-length ``bytes`` from the stream. If ``bytes`` is negative (default) the length will be read from the stream using the reverse process of :ref:`put_string<class_StreamPeer_method_put_string>`.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_StreamPeer_method_get_u16:
  170. .. rst-class:: classref-method
  171. :ref:`int<class_int>` **get_u16** **(** **)**
  172. Gets an unsigned 16-bit value from the stream.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_StreamPeer_method_get_u32:
  176. .. rst-class:: classref-method
  177. :ref:`int<class_int>` **get_u32** **(** **)**
  178. Gets an unsigned 32-bit value from the stream.
  179. .. rst-class:: classref-item-separator
  180. ----
  181. .. _class_StreamPeer_method_get_u64:
  182. .. rst-class:: classref-method
  183. :ref:`int<class_int>` **get_u64** **(** **)**
  184. Gets an unsigned 64-bit value from the stream.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_StreamPeer_method_get_u8:
  188. .. rst-class:: classref-method
  189. :ref:`int<class_int>` **get_u8** **(** **)**
  190. Gets an unsigned byte from the stream.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_StreamPeer_method_get_utf8_string:
  194. .. rst-class:: classref-method
  195. :ref:`String<class_String>` **get_utf8_string** **(** :ref:`int<class_int>` bytes=-1 **)**
  196. Gets an UTF-8 string with byte-length ``bytes`` from the stream (this decodes the string sent as UTF-8). If ``bytes`` is negative (default) the length will be read from the stream using the reverse process of :ref:`put_utf8_string<class_StreamPeer_method_put_utf8_string>`.
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_StreamPeer_method_get_var:
  200. .. rst-class:: classref-method
  201. :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)**
  202. Gets a Variant from the stream. If ``allow_objects`` is ``true``, decoding objects is allowed.
  203. \ **Warning:** Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_StreamPeer_method_put_16:
  207. .. rst-class:: classref-method
  208. void **put_16** **(** :ref:`int<class_int>` value **)**
  209. Puts a signed 16-bit value into the stream.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_StreamPeer_method_put_32:
  213. .. rst-class:: classref-method
  214. void **put_32** **(** :ref:`int<class_int>` value **)**
  215. Puts a signed 32-bit value into the stream.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_StreamPeer_method_put_64:
  219. .. rst-class:: classref-method
  220. void **put_64** **(** :ref:`int<class_int>` value **)**
  221. Puts a signed 64-bit value into the stream.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_StreamPeer_method_put_8:
  225. .. rst-class:: classref-method
  226. void **put_8** **(** :ref:`int<class_int>` value **)**
  227. Puts a signed byte into the stream.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_StreamPeer_method_put_data:
  231. .. rst-class:: classref-method
  232. :ref:`Error<enum_@GlobalScope_Error>` **put_data** **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  233. Sends a chunk of data through the connection, blocking if necessary until the data is done sending. This function returns an :ref:`Error<enum_@GlobalScope_Error>` code.
  234. .. rst-class:: classref-item-separator
  235. ----
  236. .. _class_StreamPeer_method_put_double:
  237. .. rst-class:: classref-method
  238. void **put_double** **(** :ref:`float<class_float>` value **)**
  239. Puts a double-precision float into the stream.
  240. .. rst-class:: classref-item-separator
  241. ----
  242. .. _class_StreamPeer_method_put_float:
  243. .. rst-class:: classref-method
  244. void **put_float** **(** :ref:`float<class_float>` value **)**
  245. Puts a single-precision float into the stream.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_StreamPeer_method_put_partial_data:
  249. .. rst-class:: classref-method
  250. :ref:`Array<class_Array>` **put_partial_data** **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  251. Sends a chunk of data through the connection. If all the data could not be sent at once, only part of it will. This function returns two values, an :ref:`Error<enum_@GlobalScope_Error>` code and an integer, describing how much data was actually sent.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_StreamPeer_method_put_string:
  255. .. rst-class:: classref-method
  256. void **put_string** **(** :ref:`String<class_String>` value **)**
  257. Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.
  258. \ **Note:** To put an ASCII string without prepending its size, you can use :ref:`put_data<class_StreamPeer_method_put_data>`:
  259. ::
  260. put_data("Hello world".to_ascii())
  261. .. rst-class:: classref-item-separator
  262. ----
  263. .. _class_StreamPeer_method_put_u16:
  264. .. rst-class:: classref-method
  265. void **put_u16** **(** :ref:`int<class_int>` value **)**
  266. Puts an unsigned 16-bit value into the stream.
  267. .. rst-class:: classref-item-separator
  268. ----
  269. .. _class_StreamPeer_method_put_u32:
  270. .. rst-class:: classref-method
  271. void **put_u32** **(** :ref:`int<class_int>` value **)**
  272. Puts an unsigned 32-bit value into the stream.
  273. .. rst-class:: classref-item-separator
  274. ----
  275. .. _class_StreamPeer_method_put_u64:
  276. .. rst-class:: classref-method
  277. void **put_u64** **(** :ref:`int<class_int>` value **)**
  278. Puts an unsigned 64-bit value into the stream.
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_StreamPeer_method_put_u8:
  282. .. rst-class:: classref-method
  283. void **put_u8** **(** :ref:`int<class_int>` value **)**
  284. Puts an unsigned byte into the stream.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_StreamPeer_method_put_utf8_string:
  288. .. rst-class:: classref-method
  289. void **put_utf8_string** **(** :ref:`String<class_String>` value **)**
  290. Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.
  291. \ **Note:** To put an UTF-8 string without prepending its size, you can use :ref:`put_data<class_StreamPeer_method_put_data>`:
  292. ::
  293. put_data("Hello world".to_utf8())
  294. .. rst-class:: classref-item-separator
  295. ----
  296. .. _class_StreamPeer_method_put_var:
  297. .. rst-class:: classref-method
  298. void **put_var** **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)**
  299. Puts a Variant into the stream. If ``full_objects`` is ``true`` encoding objects is allowed (and can potentially include code).
  300. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  301. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  302. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  303. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`