StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
Loading...
Searching...
No Matches
packet.hxx
1#pragma once
2
3#include <StormByte/buffer/fifo.hxx>
4#include <StormByte/network/visibility.h>
5#include <StormByte/serializable.hxx>
6
19namespace StormByte::Network::Transport {
55 class STORMBYTE_NETWORK_PUBLIC Packet {
56 public:
57 using OpcodeType = unsigned short;
58
66 Packet(const Packet& other) = default;
67
75 Packet(Packet&& other) noexcept = default;
76
84 virtual ~Packet() noexcept = default;
85
93 Packet& operator=(const Packet& other) = default;
94
101 Packet& operator=(Packet&& other) noexcept = default;
102
111 inline const OpcodeType& Opcode() const noexcept {
112 return m_opcode;
113 }
114
123 Buffer::FIFO Serialize() const noexcept;
124
133 static constexpr unsigned short PROCESS_THRESHOLD = 10;
134
135 protected:
136 OpcodeType m_opcode;
137
146 constexpr Packet(const OpcodeType& opcode) noexcept:
147 m_opcode(opcode) {}
148
159 virtual Buffer::DataType DoSerialize() const noexcept = 0;
160 };
161}
Base class for wire-level packets.
Definition packet.hxx:55
Packet(Packet &&other) noexcept=default
Move constructor.
Packet(const Packet &other)=default
Copy constructor.
Buffer::FIFO Serialize() const noexcept
Serialize the packet to a byte buffer.
virtual ~Packet() noexcept=default
Virtual destructor.
virtual Buffer::DataType DoSerialize() const noexcept=0
Packet-specific serialization hook.
unsigned short OpcodeType
The type of the opcode.
Definition packet.hxx:57