|
R-Type
2
Doom but in better
|
Represents a packet for the custom binary UDP protocol. More...
#include <ProtocolHandler.hpp>


Public Member Functions | |
| Packet (MessageType type=MessageType::P_ERROR, const std::vector< uint8_t > &payload={}) | |
Constructs a Packet with a specified message type and payload. | |
| ~Packet ()=default | |
Destructor for the Packet class. | |
| MessageType | getType () const |
| Gets the message type of the packet. | |
| uint16_t | getSize () const |
| Gets the size of the packet's payload. | |
| const std::vector< uint8_t > & | getPayload () const |
| Gets the payload of the packet. | |
| const std::string | print () const |
| Prints a string representation of the packet's contents, for debugging purposes. | |
Public Member Functions inherited from GUI::ECS::EntityNode | |
| EntityNode (const size_t entityId=0) | |
| virtual | ~EntityNode ()=default |
| virtual size_t | getEntityNodeId () const |
Static Public Member Functions | |
| static std::vector< uint8_t > | serialize (const Packet &packet) |
Serializes a Packet object into a vector of bytes suitable for network transmission. | |
| static Packet | deserialize (const std::vector< uint8_t > &data) |
| Deserializes a packet from a vector of bytes received over the network. | |
Additional Inherited Members | |
Protected Attributes inherited from GUI::ECS::EntityNode | |
| size_t | _entityID |
Represents a packet for the custom binary UDP protocol.
The Packet class defines a network packet with a message type, payload, and size. It offers functions to serialize and deserialize packets to and from a byte array for easy transmission over UDP. The supported message types include connection, disconnection, movement, shooting, entity spawning, updates, and error messages.
Definition at line 45 of file ProtocolHandler.hpp.
| GUI::Network::Packet::Packet | ( | MessageType | type = MessageType::P_ERROR, |
| const std::vector< uint8_t > & | payload = {} ) |
Constructs a Packet with a specified message type and payload.
| type | The type of message for the packet (default is ERROR). |
| payload | The data to be included in the packet as the payload (optional, defaults to empty). |
Definition at line 15 of file ProtocolHandler.cpp.
|
default |
Destructor for the Packet class.
The destructor is defined as default, as there is no dynamic memory allocation needing special cleanup.
|
static |
Deserializes a packet from a vector of bytes received over the network.
This method reconstructs a Packet object from its binary representation, extracting the type, size, and payload from the byte array.
| data | The vector of bytes representing a serialized packet. |
Packet object constructed from the deserialized data.| std::runtime_error | If the packet is invalid (e.g., incorrect size). |
Definition at line 46 of file ProtocolHandler.cpp.
| const std::vector< uint8_t > & GUI::Network::Packet::getPayload | ( | ) | const |
Gets the payload of the packet.
Definition at line 30 of file ProtocolHandler.cpp.
| uint16_t GUI::Network::Packet::getSize | ( | ) | const |
Gets the size of the packet's payload.
Definition at line 25 of file ProtocolHandler.cpp.
| GUI::Network::MessageType GUI::Network::Packet::getType | ( | ) | const |
Gets the message type of the packet.
CONNECT, DISCONNECT, etc.). Definition at line 20 of file ProtocolHandler.cpp.
| const std::string GUI::Network::Packet::print | ( | ) | const |
Prints a string representation of the packet's contents, for debugging purposes.
The printed output includes the packet's type, size, and a list of the payload bytes.
Definition at line 62 of file ProtocolHandler.cpp.
|
static |
Serializes a Packet object into a vector of bytes suitable for network transmission.
The serialized format includes:
| packet | The packet to serialize. |
Definition at line 35 of file ProtocolHandler.cpp.