class_streampeer.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/StreamPeer.xml.
  6. .. _class_StreamPeer:
  7. StreamPeer
  8. ==========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`StreamPeerBuffer<class_StreamPeerBuffer>`, :ref:`StreamPeerExtension<class_StreamPeerExtension>`, :ref:`StreamPeerGZIP<class_StreamPeerGZIP>`, :ref:`StreamPeerTCP<class_StreamPeerTCP>`, :ref:`StreamPeerTLS<class_StreamPeerTLS>`
  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. \ **Note:** When exporting to Android, make sure to enable the ``INTERNET`` permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.
  17. .. rst-class:: classref-reftable-group
  18. Properties
  19. ----------
  20. .. table::
  21. :widths: auto
  22. +-------------------------+---------------------------------------------------------+-----------+
  23. | :ref:`bool<class_bool>` | :ref:`big_endian<class_StreamPeer_property_big_endian>` | ``false`` |
  24. +-------------------------+---------------------------------------------------------+-----------+
  25. .. rst-class:: classref-reftable-group
  26. Methods
  27. -------
  28. .. table::
  29. :widths: auto
  30. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_16<class_StreamPeer_method_get_16>` **(** **)** |
  32. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_32<class_StreamPeer_method_get_32>` **(** **)** |
  34. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_64<class_StreamPeer_method_get_64>` **(** **)** |
  36. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`int<class_int>` | :ref:`get_8<class_StreamPeer_method_get_8>` **(** **)** |
  38. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`get_available_bytes<class_StreamPeer_method_get_available_bytes>` **(** **)** |const| |
  40. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Array<class_Array>` | :ref:`get_data<class_StreamPeer_method_get_data>` **(** :ref:`int<class_int>` bytes **)** |
  42. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_double<class_StreamPeer_method_get_double>` **(** **)** |
  44. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_float<class_StreamPeer_method_get_float>` **(** **)** |
  46. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Array<class_Array>` | :ref:`get_partial_data<class_StreamPeer_method_get_partial_data>` **(** :ref:`int<class_int>` bytes **)** |
  48. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`String<class_String>` | :ref:`get_string<class_StreamPeer_method_get_string>` **(** :ref:`int<class_int>` bytes=-1 **)** |
  50. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_u16<class_StreamPeer_method_get_u16>` **(** **)** |
  52. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_u32<class_StreamPeer_method_get_u32>` **(** **)** |
  54. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`int<class_int>` | :ref:`get_u64<class_StreamPeer_method_get_u64>` **(** **)** |
  56. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_u8<class_StreamPeer_method_get_u8>` **(** **)** |
  58. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`String<class_String>` | :ref:`get_utf8_string<class_StreamPeer_method_get_utf8_string>` **(** :ref:`int<class_int>` bytes=-1 **)** |
  60. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_StreamPeer_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |
  62. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`put_16<class_StreamPeer_method_put_16>` **(** :ref:`int<class_int>` value **)** |
  64. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`put_32<class_StreamPeer_method_put_32>` **(** :ref:`int<class_int>` value **)** |
  66. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`put_64<class_StreamPeer_method_put_64>` **(** :ref:`int<class_int>` value **)** |
  68. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`put_8<class_StreamPeer_method_put_8>` **(** :ref:`int<class_int>` value **)** |
  70. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_data<class_StreamPeer_method_put_data>` **(** :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
  72. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`put_double<class_StreamPeer_method_put_double>` **(** :ref:`float<class_float>` value **)** |
  74. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`put_float<class_StreamPeer_method_put_float>` **(** :ref:`float<class_float>` value **)** |
  76. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Array<class_Array>` | :ref:`put_partial_data<class_StreamPeer_method_put_partial_data>` **(** :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
  78. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`put_string<class_StreamPeer_method_put_string>` **(** :ref:`String<class_String>` value **)** |
  80. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`put_u16<class_StreamPeer_method_put_u16>` **(** :ref:`int<class_int>` value **)** |
  82. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`put_u32<class_StreamPeer_method_put_u32>` **(** :ref:`int<class_int>` value **)** |
  84. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`put_u64<class_StreamPeer_method_put_u64>` **(** :ref:`int<class_int>` value **)** |
  86. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`put_u8<class_StreamPeer_method_put_u8>` **(** :ref:`int<class_int>` value **)** |
  88. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`put_utf8_string<class_StreamPeer_method_put_utf8_string>` **(** :ref:`String<class_String>` value **)** |
  90. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`put_var<class_StreamPeer_method_put_var>` **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)** |
  92. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  93. .. rst-class:: classref-section-separator
  94. ----
  95. .. rst-class:: classref-descriptions-group
  96. Property Descriptions
  97. ---------------------
  98. .. _class_StreamPeer_property_big_endian:
  99. .. rst-class:: classref-property
  100. :ref:`bool<class_bool>` **big_endian** = ``false``
  101. .. rst-class:: classref-property-setget
  102. - void **set_big_endian** **(** :ref:`bool<class_bool>` value **)**
  103. - :ref:`bool<class_bool>` **is_big_endian_enabled** **(** **)**
  104. If ``true``, this **StreamPeer** will using big-endian format for encoding and decoding.
  105. .. rst-class:: classref-section-separator
  106. ----
  107. .. rst-class:: classref-descriptions-group
  108. Method Descriptions
  109. -------------------
  110. .. _class_StreamPeer_method_get_16:
  111. .. rst-class:: classref-method
  112. :ref:`int<class_int>` **get_16** **(** **)**
  113. Gets a signed 16-bit value from the stream.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_StreamPeer_method_get_32:
  117. .. rst-class:: classref-method
  118. :ref:`int<class_int>` **get_32** **(** **)**
  119. Gets a signed 32-bit value from the stream.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_StreamPeer_method_get_64:
  123. .. rst-class:: classref-method
  124. :ref:`int<class_int>` **get_64** **(** **)**
  125. Gets a signed 64-bit value from the stream.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_StreamPeer_method_get_8:
  129. .. rst-class:: classref-method
  130. :ref:`int<class_int>` **get_8** **(** **)**
  131. Gets a signed byte from the stream.
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. _class_StreamPeer_method_get_available_bytes:
  135. .. rst-class:: classref-method
  136. :ref:`int<class_int>` **get_available_bytes** **(** **)** |const|
  137. Returns the number of bytes this **StreamPeer** has available.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_StreamPeer_method_get_data:
  141. .. rst-class:: classref-method
  142. :ref:`Array<class_Array>` **get_data** **(** :ref:`int<class_int>` bytes **)**
  143. Returns a chunk data with the received bytes. The number 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.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. _class_StreamPeer_method_get_double:
  147. .. rst-class:: classref-method
  148. :ref:`float<class_float>` **get_double** **(** **)**
  149. Gets a double-precision float from the stream.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_StreamPeer_method_get_float:
  153. .. rst-class:: classref-method
  154. :ref:`float<class_float>` **get_float** **(** **)**
  155. Gets a single-precision float from the stream.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_StreamPeer_method_get_partial_data:
  159. .. rst-class:: classref-method
  160. :ref:`Array<class_Array>` **get_partial_data** **(** :ref:`int<class_int>` bytes **)**
  161. Returns a chunk data with the received bytes. The number 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.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_StreamPeer_method_get_string:
  165. .. rst-class:: classref-method
  166. :ref:`String<class_String>` **get_string** **(** :ref:`int<class_int>` bytes=-1 **)**
  167. 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>`.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_StreamPeer_method_get_u16:
  171. .. rst-class:: classref-method
  172. :ref:`int<class_int>` **get_u16** **(** **)**
  173. Gets an unsigned 16-bit value from the stream.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_StreamPeer_method_get_u32:
  177. .. rst-class:: classref-method
  178. :ref:`int<class_int>` **get_u32** **(** **)**
  179. Gets an unsigned 32-bit value from the stream.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_StreamPeer_method_get_u64:
  183. .. rst-class:: classref-method
  184. :ref:`int<class_int>` **get_u64** **(** **)**
  185. Gets an unsigned 64-bit value from the stream.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_StreamPeer_method_get_u8:
  189. .. rst-class:: classref-method
  190. :ref:`int<class_int>` **get_u8** **(** **)**
  191. Gets an unsigned byte from the stream.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_StreamPeer_method_get_utf8_string:
  195. .. rst-class:: classref-method
  196. :ref:`String<class_String>` **get_utf8_string** **(** :ref:`int<class_int>` bytes=-1 **)**
  197. 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>`.
  198. .. rst-class:: classref-item-separator
  199. ----
  200. .. _class_StreamPeer_method_get_var:
  201. .. rst-class:: classref-method
  202. :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)**
  203. Gets a Variant from the stream. If ``allow_objects`` is ``true``, decoding objects is allowed.
  204. \ **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.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_StreamPeer_method_put_16:
  208. .. rst-class:: classref-method
  209. void **put_16** **(** :ref:`int<class_int>` value **)**
  210. Puts a signed 16-bit value into the stream.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_StreamPeer_method_put_32:
  214. .. rst-class:: classref-method
  215. void **put_32** **(** :ref:`int<class_int>` value **)**
  216. Puts a signed 32-bit value into the stream.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_StreamPeer_method_put_64:
  220. .. rst-class:: classref-method
  221. void **put_64** **(** :ref:`int<class_int>` value **)**
  222. Puts a signed 64-bit value into the stream.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_StreamPeer_method_put_8:
  226. .. rst-class:: classref-method
  227. void **put_8** **(** :ref:`int<class_int>` value **)**
  228. Puts a signed byte into the stream.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_StreamPeer_method_put_data:
  232. .. rst-class:: classref-method
  233. :ref:`Error<enum_@GlobalScope_Error>` **put_data** **(** :ref:`PackedByteArray<class_PackedByteArray>` data **)**
  234. 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.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_StreamPeer_method_put_double:
  238. .. rst-class:: classref-method
  239. void **put_double** **(** :ref:`float<class_float>` value **)**
  240. Puts a double-precision float into the stream.
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_StreamPeer_method_put_float:
  244. .. rst-class:: classref-method
  245. void **put_float** **(** :ref:`float<class_float>` value **)**
  246. Puts a single-precision float into the stream.
  247. .. rst-class:: classref-item-separator
  248. ----
  249. .. _class_StreamPeer_method_put_partial_data:
  250. .. rst-class:: classref-method
  251. :ref:`Array<class_Array>` **put_partial_data** **(** :ref:`PackedByteArray<class_PackedByteArray>` data **)**
  252. 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.
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_StreamPeer_method_put_string:
  256. .. rst-class:: classref-method
  257. void **put_string** **(** :ref:`String<class_String>` value **)**
  258. Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.
  259. \ **Note:** To put an ASCII string without prepending its size, you can use :ref:`put_data<class_StreamPeer_method_put_data>`:
  260. .. tabs::
  261. .. code-tab:: gdscript
  262. put_data("Hello world".to_ascii())
  263. .. code-tab:: csharp
  264. PutData("Hello World".ToAscii());
  265. .. rst-class:: classref-item-separator
  266. ----
  267. .. _class_StreamPeer_method_put_u16:
  268. .. rst-class:: classref-method
  269. void **put_u16** **(** :ref:`int<class_int>` value **)**
  270. Puts an unsigned 16-bit value into the stream.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_StreamPeer_method_put_u32:
  274. .. rst-class:: classref-method
  275. void **put_u32** **(** :ref:`int<class_int>` value **)**
  276. Puts an unsigned 32-bit value into the stream.
  277. .. rst-class:: classref-item-separator
  278. ----
  279. .. _class_StreamPeer_method_put_u64:
  280. .. rst-class:: classref-method
  281. void **put_u64** **(** :ref:`int<class_int>` value **)**
  282. Puts an unsigned 64-bit value into the stream.
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_StreamPeer_method_put_u8:
  286. .. rst-class:: classref-method
  287. void **put_u8** **(** :ref:`int<class_int>` value **)**
  288. Puts an unsigned byte into the stream.
  289. .. rst-class:: classref-item-separator
  290. ----
  291. .. _class_StreamPeer_method_put_utf8_string:
  292. .. rst-class:: classref-method
  293. void **put_utf8_string** **(** :ref:`String<class_String>` value **)**
  294. Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.
  295. \ **Note:** To put an UTF-8 string without prepending its size, you can use :ref:`put_data<class_StreamPeer_method_put_data>`:
  296. .. tabs::
  297. .. code-tab:: gdscript
  298. put_data("Hello world".to_utf8())
  299. .. code-tab:: csharp
  300. PutData("Hello World".ToUTF8());
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_StreamPeer_method_put_var:
  304. .. rst-class:: classref-method
  305. void **put_var** **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)**
  306. Puts a Variant into the stream. If ``full_objects`` is ``true`` encoding objects is allowed (and can potentially include code).
  307. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  308. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  309. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  310. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  311. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  312. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`