R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
IPacket.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** IPacket.hpp
6*/
7
8#pragma once
9
10#include <cstddef>
11#include <cstdint>
12#include <vector>
13
18enum class PacketFlag : uint32_t {
19 RELIABLE = 1 << 0,
20 UNSEQUENCED = 1 << 1,
21 NO_ALLOCATE = 1 << 2,
22 UNRELIABLE_FRAGMENT = 1 << 3,
23 SENT = 1 << 8
24};
25
35class IPacket {
36 public:
37 virtual ~IPacket() = default;
38
43 [[nodiscard]] virtual const std::vector<uint8_t> &getData() const = 0;
44
49 [[nodiscard]] virtual size_t getSize() const = 0;
50
55 [[nodiscard]] virtual uint32_t getFlags() const = 0;
56
61 virtual void setData(const std::vector<uint8_t> &data) = 0;
62};
PacketFlag
Flags that control packet behavior and delivery guarantees.
Definition IPacket.hpp:18
@ SENT
Flag indicating packet has been sent from peer.
@ UNSEQUENCED
Packet will not be sequenced with other packets.
@ NO_ALLOCATE
Packet will not allocate data, and user must supply it.
@ RELIABLE
Packet must be received by the target peer and resent if dropped.
@ UNRELIABLE_FRAGMENT
Packet will be fragmented using unreliable (default) sends.
Interface representing a network packet.
Definition IPacket.hpp:35
virtual size_t getSize() const =0
Get the size of the packet data in bytes.
virtual uint32_t getFlags() const =0
Get the flags associated with this packet.
virtual void setData(const std::vector< uint8_t > &data)=0
Set new data for this packet.
virtual ~IPacket()=default
virtual const std::vector< uint8_t > & getData() const =0
Get the packet data as a byte buffer.