:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/PacketPeer.xml. .. _class_PacketPeer: PacketPeer ========== **Inherits:** :ref:`Reference` **<** :ref:`Object` **Inherited By:** :ref:`NetworkedMultiplayerPeer`, :ref:`PacketPeerDTLS`, :ref:`PacketPeerGDNative`, :ref:`PacketPeerStream`, :ref:`PacketPeerUDP`, :ref:`WebRTCDataChannel`, :ref:`WebSocketPeer` Abstraction and base class for packet-based protocols. .. rst-class:: classref-introduction-group Description ----------- 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. .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-------------------------+---------------------------------------------------------------------------------+-------------+ | :ref:`bool` | :ref:`allow_object_decoding` | ``false`` | +-------------------------+---------------------------------------------------------------------------------+-------------+ | :ref:`int` | :ref:`encode_buffer_max_size` | ``8388608`` | +-------------------------+---------------------------------------------------------------------------------+-------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_available_packet_count` **(** **)** |const| | +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PoolByteArray` | :ref:`get_packet` **(** **)** | +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`get_packet_error` **(** **)** |const| | +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_var` **(** :ref:`bool` allow_objects=false **)** | +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`put_packet` **(** :ref:`PoolByteArray` buffer **)** | +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`put_var` **(** :ref:`Variant` var, :ref:`bool` full_objects=false **)** | +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_PacketPeer_property_allow_object_decoding: .. rst-class:: classref-property :ref:`bool` **allow_object_decoding** = ``false`` .. rst-class:: classref-property-setget - void **set_allow_object_decoding** **(** :ref:`bool` value **)** - :ref:`bool` **is_object_decoding_allowed** **(** **)** *Deprecated.* Use ``get_var`` and ``put_var`` parameters instead. If ``true``, the PacketPeer will allow encoding and decoding of object via :ref:`get_var` and :ref:`put_var`. \ **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. .. rst-class:: classref-item-separator ---- .. _class_PacketPeer_property_encode_buffer_max_size: .. rst-class:: classref-property :ref:`int` **encode_buffer_max_size** = ``8388608`` .. rst-class:: classref-property-setget - void **set_encode_buffer_max_size** **(** :ref:`int` value **)** - :ref:`int` **get_encode_buffer_max_size** **(** **)** Maximum buffer size allowed when encoding :ref:`Variant`\ s. Raise this value to support heavier memory allocations. The :ref:`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`. If the :ref:`Variant` is bigger than ``encode_buffer_max_size``, the method will error out with :ref:`@GlobalScope.ERR_OUT_OF_MEMORY`. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_PacketPeer_method_get_available_packet_count: .. rst-class:: classref-method :ref:`int` **get_available_packet_count** **(** **)** |const| Returns the number of packets currently available in the ring-buffer. .. rst-class:: classref-item-separator ---- .. _class_PacketPeer_method_get_packet: .. rst-class:: classref-method :ref:`PoolByteArray` **get_packet** **(** **)** Gets a raw packet. .. rst-class:: classref-item-separator ---- .. _class_PacketPeer_method_get_packet_error: .. rst-class:: classref-method :ref:`Error` **get_packet_error** **(** **)** |const| Returns the error state of the last packet received (via :ref:`get_packet` and :ref:`get_var`). .. rst-class:: classref-item-separator ---- .. _class_PacketPeer_method_get_var: .. rst-class:: classref-method :ref:`Variant` **get_var** **(** :ref:`bool` allow_objects=false **)** Gets a Variant. If ``allow_objects`` (or :ref:`allow_object_decoding`) is ``true``, decoding objects is allowed. \ **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. .. rst-class:: classref-item-separator ---- .. _class_PacketPeer_method_put_packet: .. rst-class:: classref-method :ref:`Error` **put_packet** **(** :ref:`PoolByteArray` buffer **)** Sends a raw packet. .. rst-class:: classref-item-separator ---- .. _class_PacketPeer_method_put_var: .. rst-class:: classref-method :ref:`Error` **put_var** **(** :ref:`Variant` var, :ref:`bool` full_objects=false **)** Sends a :ref:`Variant` as a packet. If ``full_objects`` (or :ref:`allow_object_decoding`) is ``true``, encoding objects is allowed (and can potentially include code). .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`