R-Type  2
Doom but in better
Loading...
Searching...
No Matches
ProtocolHandler.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** ProtocolHandler.hpp
4** File description:
5** Serialisation & Deserialisation of binary protocol UDP
6*/
7
8
18#pragma once
19
20#include <vector>
21#include <string>
22#include <cstdint>
23#include <iostream>
24#include <stdexcept>
25
26#include "Log.hpp"
27#include "LogMacros.hpp"
28#include "Utilities.hpp"
31
32namespace GUI
33{
34 namespace Network
35 {
46 public:
53 Packet(MessageType type = MessageType::P_ERROR, const std::vector<uint8_t> &payload = {});
59 ~Packet() = default;
60
66 MessageType getType() const;
72 uint16_t getSize() const;
78 const std::vector<uint8_t> &getPayload() const;
79
92 static std::vector<uint8_t> serialize(const Packet &packet);
105 static Packet deserialize(const std::vector<uint8_t> &data);
106
107 /*// Debug part \\*/
115 const std::string print() const;
116 /*// Debug part \\*/
117
118 private:
119 MessageType type;
120 uint16_t size;
121 std::vector<uint8_t> payload;
122 };
123 }
124}
This is the file that links the EntityNode children.
Macro definitions for logging messages with varying levels of detail and formatting.
This is the file in charge of containing the Log class (the one in charge of outputing info only when...
Enum for the different types of messages that can be eschanged with the server.
Represents a packet for the custom binary UDP protocol.
const std::string print() const
Prints a string representation of the packet's contents, for debugging purposes.
uint16_t getSize() const
Gets the size of the packet's payload.
MessageType getType() const
Gets the message type of the packet.
static std::vector< uint8_t > serialize(const Packet &packet)
Serializes a Packet object into a vector of bytes suitable for network transmission.
~Packet()=default
Destructor for the Packet class.
static Packet deserialize(const std::vector< uint8_t > &data)
Deserializes a packet from a vector of bytes received over the network.
Packet(MessageType type=MessageType::P_ERROR, const std::vector< uint8_t > &payload={})
Constructs a Packet with a specified message type and payload.
const std::vector< uint8_t > & getPayload() const
Gets the payload of the packet.
MessageType
Enum for the different message types in the UDP protocol.