class_packetpeer.rst 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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/PacketPeer.xml.
  6. .. _class_PacketPeer:
  7. PacketPeer
  8. ==========
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>`, :ref:`PacketPeerDTLS<class_PacketPeerDTLS>`, :ref:`PacketPeerGDNative<class_PacketPeerGDNative>`, :ref:`PacketPeerStream<class_PacketPeerStream>`, :ref:`PacketPeerUDP<class_PacketPeerUDP>`, :ref:`WebRTCDataChannel<class_WebRTCDataChannel>`, :ref:`WebSocketPeer<class_WebSocketPeer>`
  11. Abstraction and base class for packet-based protocols.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. PacketPeer is an abstraction and base class for packet-based protocols (such as UDP). It provides an API for sending and receiving packets both as raw data or variables. This makes it easy to transfer data over a protocol, without having to encode data as low-level bytes or having to worry about network ordering.
  16. .. rst-class:: classref-reftable-group
  17. Properties
  18. ----------
  19. .. table::
  20. :widths: auto
  21. +-------------------------+---------------------------------------------------------------------------------+-------------+
  22. | :ref:`bool<class_bool>` | :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>` | ``false`` |
  23. +-------------------------+---------------------------------------------------------------------------------+-------------+
  24. | :ref:`int<class_int>` | :ref:`encode_buffer_max_size<class_PacketPeer_property_encode_buffer_max_size>` | ``8388608`` |
  25. +-------------------------+---------------------------------------------------------------------------------+-------------+
  26. .. rst-class:: classref-reftable-group
  27. Methods
  28. -------
  29. .. table::
  30. :widths: auto
  31. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_available_packet_count<class_PacketPeer_method_get_available_packet_count>` **(** **)** |const| |
  33. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_packet<class_PacketPeer_method_get_packet>` **(** **)** |
  35. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_packet_error<class_PacketPeer_method_get_packet_error>` **(** **)** |const| |
  37. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_PacketPeer_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |
  39. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_packet<class_PacketPeer_method_put_packet>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  41. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_var<class_PacketPeer_method_put_var>` **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)** |
  43. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  44. .. rst-class:: classref-section-separator
  45. ----
  46. .. rst-class:: classref-descriptions-group
  47. Property Descriptions
  48. ---------------------
  49. .. _class_PacketPeer_property_allow_object_decoding:
  50. .. rst-class:: classref-property
  51. :ref:`bool<class_bool>` **allow_object_decoding** = ``false``
  52. .. rst-class:: classref-property-setget
  53. - void **set_allow_object_decoding** **(** :ref:`bool<class_bool>` value **)**
  54. - :ref:`bool<class_bool>` **is_object_decoding_allowed** **(** **)**
  55. *Deprecated.* Use ``get_var`` and ``put_var`` parameters instead.
  56. If ``true``, the PacketPeer will allow encoding and decoding of object via :ref:`get_var<class_PacketPeer_method_get_var>` and :ref:`put_var<class_PacketPeer_method_put_var>`.
  57. \ **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.
  58. .. rst-class:: classref-item-separator
  59. ----
  60. .. _class_PacketPeer_property_encode_buffer_max_size:
  61. .. rst-class:: classref-property
  62. :ref:`int<class_int>` **encode_buffer_max_size** = ``8388608``
  63. .. rst-class:: classref-property-setget
  64. - void **set_encode_buffer_max_size** **(** :ref:`int<class_int>` value **)**
  65. - :ref:`int<class_int>` **get_encode_buffer_max_size** **(** **)**
  66. Maximum buffer size allowed when encoding :ref:`Variant<class_Variant>`\ s. Raise this value to support heavier memory allocations.
  67. The :ref:`put_var<class_PacketPeer_method_put_var>` method allocates memory on the stack, and the buffer used will grow automatically to the closest power of two to match the size of the :ref:`Variant<class_Variant>`. If the :ref:`Variant<class_Variant>` is bigger than ``encode_buffer_max_size``, the method will error out with :ref:`@GlobalScope.ERR_OUT_OF_MEMORY<class_@GlobalScope_constant_ERR_OUT_OF_MEMORY>`.
  68. .. rst-class:: classref-section-separator
  69. ----
  70. .. rst-class:: classref-descriptions-group
  71. Method Descriptions
  72. -------------------
  73. .. _class_PacketPeer_method_get_available_packet_count:
  74. .. rst-class:: classref-method
  75. :ref:`int<class_int>` **get_available_packet_count** **(** **)** |const|
  76. Returns the number of packets currently available in the ring-buffer.
  77. .. rst-class:: classref-item-separator
  78. ----
  79. .. _class_PacketPeer_method_get_packet:
  80. .. rst-class:: classref-method
  81. :ref:`PoolByteArray<class_PoolByteArray>` **get_packet** **(** **)**
  82. Gets a raw packet.
  83. .. rst-class:: classref-item-separator
  84. ----
  85. .. _class_PacketPeer_method_get_packet_error:
  86. .. rst-class:: classref-method
  87. :ref:`Error<enum_@GlobalScope_Error>` **get_packet_error** **(** **)** |const|
  88. Returns the error state of the last packet received (via :ref:`get_packet<class_PacketPeer_method_get_packet>` and :ref:`get_var<class_PacketPeer_method_get_var>`).
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_PacketPeer_method_get_var:
  92. .. rst-class:: classref-method
  93. :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)**
  94. Gets a Variant. If ``allow_objects`` (or :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>`) is ``true``, decoding objects is allowed.
  95. \ **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.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_PacketPeer_method_put_packet:
  99. .. rst-class:: classref-method
  100. :ref:`Error<enum_@GlobalScope_Error>` **put_packet** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  101. Sends a raw packet.
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_PacketPeer_method_put_var:
  105. .. rst-class:: classref-method
  106. :ref:`Error<enum_@GlobalScope_Error>` **put_var** **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)**
  107. Sends a :ref:`Variant<class_Variant>` as a packet. If ``full_objects`` (or :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>`) is ``true``, encoding objects is allowed (and can potentially include code).
  108. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  109. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  110. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  111. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`