R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ENetPacket.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** Created by IamSwan on 06/12/2025.
4** File description:
5** ENetPacket.hpp
6*/
7
8#pragma once
9
10#include <enet/enet.h>
11#include <cstdint>
12#include <vector>
13#include "IPacket.hpp"
14
15class ENetPacketWrapper final : public IPacket {
16 public:
17 explicit ENetPacketWrapper(ENetPacket *packet);
18 ENetPacketWrapper(const std::vector<uint8_t> &data, uint32_t flags);
19 ~ENetPacketWrapper() override;
20
23
24 ENetPacketWrapper(ENetPacketWrapper &&other) noexcept;
26
27 [[nodiscard]] const std::vector<uint8_t> &getData() const override;
28 [[nodiscard]] size_t getSize() const override;
29 [[nodiscard]] uint32_t getFlags() const override;
30 void setData(const std::vector<uint8_t> &data) override;
31
32 [[nodiscard]] ENetPacket *getNativePacket() const;
33
34 private:
35 ENetPacket *_packet;
36 mutable std::vector<uint8_t> _dataCache;
37 mutable bool _dataCacheValid;
38};
size_t getSize() const override
Get the size of the packet data in bytes.
const std::vector< uint8_t > & getData() const override
Get the packet data as a byte buffer.
std::vector< uint8_t > _dataCache
void setData(const std::vector< uint8_t > &data) override
Set new data for this packet.
ENetPacket * getNativePacket() const
~ENetPacketWrapper() override
ENetPacket * _packet
ENetPacketWrapper & operator=(const ENetPacketWrapper &)=delete
ENetPacketWrapper(const ENetPacketWrapper &)=delete
uint32_t getFlags() const override
Get the flags associated with this packet.
Interface representing a network packet.
Definition IPacket.hpp:35