class_streampeer.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the StreamPeer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_StreamPeer:
  6. StreamPeer
  7. ==========
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`StreamPeerBuffer<class_StreamPeerBuffer>`, :ref:`StreamPeerGDNative<class_StreamPeerGDNative>`, :ref:`StreamPeerSSL<class_StreamPeerSSL>`, :ref:`StreamPeerTCP<class_StreamPeerTCP>`
  10. Abstraction and base class for stream-based protocols.
  11. Description
  12. -----------
  13. 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.
  14. Properties
  15. ----------
  16. +-------------------------+---------------------------------------------------------+-----------+
  17. | :ref:`bool<class_bool>` | :ref:`big_endian<class_StreamPeer_property_big_endian>` | ``false`` |
  18. +-------------------------+---------------------------------------------------------+-----------+
  19. Methods
  20. -------
  21. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`get_16<class_StreamPeer_method_get_16>` **(** **)** |
  23. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`int<class_int>` | :ref:`get_32<class_StreamPeer_method_get_32>` **(** **)** |
  25. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`int<class_int>` | :ref:`get_64<class_StreamPeer_method_get_64>` **(** **)** |
  27. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`get_8<class_StreamPeer_method_get_8>` **(** **)** |
  29. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`int<class_int>` | :ref:`get_available_bytes<class_StreamPeer_method_get_available_bytes>` **(** **)** |const| |
  31. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Array<class_Array>` | :ref:`get_data<class_StreamPeer_method_get_data>` **(** :ref:`int<class_int>` bytes **)** |
  33. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`get_double<class_StreamPeer_method_get_double>` **(** **)** |
  35. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_float<class_StreamPeer_method_get_float>` **(** **)** |
  37. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Array<class_Array>` | :ref:`get_partial_data<class_StreamPeer_method_get_partial_data>` **(** :ref:`int<class_int>` bytes **)** |
  39. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`String<class_String>` | :ref:`get_string<class_StreamPeer_method_get_string>` **(** :ref:`int<class_int>` bytes=-1 **)** |
  41. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`int<class_int>` | :ref:`get_u16<class_StreamPeer_method_get_u16>` **(** **)** |
  43. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`int<class_int>` | :ref:`get_u32<class_StreamPeer_method_get_u32>` **(** **)** |
  45. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`get_u64<class_StreamPeer_method_get_u64>` **(** **)** |
  47. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`get_u8<class_StreamPeer_method_get_u8>` **(** **)** |
  49. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`String<class_String>` | :ref:`get_utf8_string<class_StreamPeer_method_get_utf8_string>` **(** :ref:`int<class_int>` bytes=-1 **)** |
  51. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_StreamPeer_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |
  53. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`put_16<class_StreamPeer_method_put_16>` **(** :ref:`int<class_int>` value **)** |
  55. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`put_32<class_StreamPeer_method_put_32>` **(** :ref:`int<class_int>` value **)** |
  57. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`put_64<class_StreamPeer_method_put_64>` **(** :ref:`int<class_int>` value **)** |
  59. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`put_8<class_StreamPeer_method_put_8>` **(** :ref:`int<class_int>` value **)** |
  61. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_data<class_StreamPeer_method_put_data>` **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  63. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`put_double<class_StreamPeer_method_put_double>` **(** :ref:`float<class_float>` value **)** |
  65. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`put_float<class_StreamPeer_method_put_float>` **(** :ref:`float<class_float>` value **)** |
  67. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Array<class_Array>` | :ref:`put_partial_data<class_StreamPeer_method_put_partial_data>` **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  69. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`put_string<class_StreamPeer_method_put_string>` **(** :ref:`String<class_String>` value **)** |
  71. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`put_u16<class_StreamPeer_method_put_u16>` **(** :ref:`int<class_int>` value **)** |
  73. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`put_u32<class_StreamPeer_method_put_u32>` **(** :ref:`int<class_int>` value **)** |
  75. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`put_u64<class_StreamPeer_method_put_u64>` **(** :ref:`int<class_int>` value **)** |
  77. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`put_u8<class_StreamPeer_method_put_u8>` **(** :ref:`int<class_int>` value **)** |
  79. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`put_utf8_string<class_StreamPeer_method_put_utf8_string>` **(** :ref:`String<class_String>` value **)** |
  81. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`put_var<class_StreamPeer_method_put_var>` **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)** |
  83. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  84. Property Descriptions
  85. ---------------------
  86. .. _class_StreamPeer_property_big_endian:
  87. - :ref:`bool<class_bool>` **big_endian**
  88. +-----------+-------------------------+
  89. | *Default* | ``false`` |
  90. +-----------+-------------------------+
  91. | *Setter* | set_big_endian(value) |
  92. +-----------+-------------------------+
  93. | *Getter* | is_big_endian_enabled() |
  94. +-----------+-------------------------+
  95. If ``true``, this ``StreamPeer`` will using big-endian format for encoding and decoding.
  96. Method Descriptions
  97. -------------------
  98. .. _class_StreamPeer_method_get_16:
  99. - :ref:`int<class_int>` **get_16** **(** **)**
  100. Gets a signed 16-bit value from the stream.
  101. ----
  102. .. _class_StreamPeer_method_get_32:
  103. - :ref:`int<class_int>` **get_32** **(** **)**
  104. Gets a signed 32-bit value from the stream.
  105. ----
  106. .. _class_StreamPeer_method_get_64:
  107. - :ref:`int<class_int>` **get_64** **(** **)**
  108. Gets a signed 64-bit value from the stream.
  109. ----
  110. .. _class_StreamPeer_method_get_8:
  111. - :ref:`int<class_int>` **get_8** **(** **)**
  112. Gets a signed byte from the stream.
  113. ----
  114. .. _class_StreamPeer_method_get_available_bytes:
  115. - :ref:`int<class_int>` **get_available_bytes** **(** **)** |const|
  116. Returns the amount of bytes this ``StreamPeer`` has available.
  117. ----
  118. .. _class_StreamPeer_method_get_data:
  119. - :ref:`Array<class_Array>` **get_data** **(** :ref:`int<class_int>` bytes **)**
  120. 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.
  121. ----
  122. .. _class_StreamPeer_method_get_double:
  123. - :ref:`float<class_float>` **get_double** **(** **)**
  124. Gets a double-precision float from the stream.
  125. ----
  126. .. _class_StreamPeer_method_get_float:
  127. - :ref:`float<class_float>` **get_float** **(** **)**
  128. Gets a single-precision float from the stream.
  129. ----
  130. .. _class_StreamPeer_method_get_partial_data:
  131. - :ref:`Array<class_Array>` **get_partial_data** **(** :ref:`int<class_int>` bytes **)**
  132. 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.
  133. ----
  134. .. _class_StreamPeer_method_get_string:
  135. - :ref:`String<class_String>` **get_string** **(** :ref:`int<class_int>` bytes=-1 **)**
  136. 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>`.
  137. ----
  138. .. _class_StreamPeer_method_get_u16:
  139. - :ref:`int<class_int>` **get_u16** **(** **)**
  140. Gets an unsigned 16-bit value from the stream.
  141. ----
  142. .. _class_StreamPeer_method_get_u32:
  143. - :ref:`int<class_int>` **get_u32** **(** **)**
  144. Gets an unsigned 32-bit value from the stream.
  145. ----
  146. .. _class_StreamPeer_method_get_u64:
  147. - :ref:`int<class_int>` **get_u64** **(** **)**
  148. Gets an unsigned 64-bit value from the stream.
  149. ----
  150. .. _class_StreamPeer_method_get_u8:
  151. - :ref:`int<class_int>` **get_u8** **(** **)**
  152. Gets an unsigned byte from the stream.
  153. ----
  154. .. _class_StreamPeer_method_get_utf8_string:
  155. - :ref:`String<class_String>` **get_utf8_string** **(** :ref:`int<class_int>` bytes=-1 **)**
  156. 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>`.
  157. ----
  158. .. _class_StreamPeer_method_get_var:
  159. - :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)**
  160. Gets a Variant from the stream. If ``allow_objects`` is ``true``, decoding objects is allowed.
  161. **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.
  162. ----
  163. .. _class_StreamPeer_method_put_16:
  164. - void **put_16** **(** :ref:`int<class_int>` value **)**
  165. Puts a signed 16-bit value into the stream.
  166. ----
  167. .. _class_StreamPeer_method_put_32:
  168. - void **put_32** **(** :ref:`int<class_int>` value **)**
  169. Puts a signed 32-bit value into the stream.
  170. ----
  171. .. _class_StreamPeer_method_put_64:
  172. - void **put_64** **(** :ref:`int<class_int>` value **)**
  173. Puts a signed 64-bit value into the stream.
  174. ----
  175. .. _class_StreamPeer_method_put_8:
  176. - void **put_8** **(** :ref:`int<class_int>` value **)**
  177. Puts a signed byte into the stream.
  178. ----
  179. .. _class_StreamPeer_method_put_data:
  180. - :ref:`Error<enum_@GlobalScope_Error>` **put_data** **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  181. 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.
  182. ----
  183. .. _class_StreamPeer_method_put_double:
  184. - void **put_double** **(** :ref:`float<class_float>` value **)**
  185. Puts a double-precision float into the stream.
  186. ----
  187. .. _class_StreamPeer_method_put_float:
  188. - void **put_float** **(** :ref:`float<class_float>` value **)**
  189. Puts a single-precision float into the stream.
  190. ----
  191. .. _class_StreamPeer_method_put_partial_data:
  192. - :ref:`Array<class_Array>` **put_partial_data** **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  193. 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.
  194. ----
  195. .. _class_StreamPeer_method_put_string:
  196. - void **put_string** **(** :ref:`String<class_String>` value **)**
  197. Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.
  198. **Note:** To put an ASCII string without prepending its size, you can use :ref:`put_data<class_StreamPeer_method_put_data>`:
  199. ::
  200. put_data("Hello world".to_ascii())
  201. ----
  202. .. _class_StreamPeer_method_put_u16:
  203. - void **put_u16** **(** :ref:`int<class_int>` value **)**
  204. Puts an unsigned 16-bit value into the stream.
  205. ----
  206. .. _class_StreamPeer_method_put_u32:
  207. - void **put_u32** **(** :ref:`int<class_int>` value **)**
  208. Puts an unsigned 32-bit value into the stream.
  209. ----
  210. .. _class_StreamPeer_method_put_u64:
  211. - void **put_u64** **(** :ref:`int<class_int>` value **)**
  212. Puts an unsigned 64-bit value into the stream.
  213. ----
  214. .. _class_StreamPeer_method_put_u8:
  215. - void **put_u8** **(** :ref:`int<class_int>` value **)**
  216. Puts an unsigned byte into the stream.
  217. ----
  218. .. _class_StreamPeer_method_put_utf8_string:
  219. - void **put_utf8_string** **(** :ref:`String<class_String>` value **)**
  220. Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.
  221. **Note:** To put an UTF-8 string without prepending its size, you can use :ref:`put_data<class_StreamPeer_method_put_data>`:
  222. ::
  223. put_data("Hello world".to_utf8())
  224. ----
  225. .. _class_StreamPeer_method_put_var:
  226. - void **put_var** **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)**
  227. Puts a Variant into the stream. If ``full_objects`` is ``true`` encoding objects is allowed (and can potentially include code).
  228. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  229. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  230. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`