StormByte C++ Library: Network module 1.1.0
StormByte-Network is the C++26 networking module of the StormByte suite.
Loading...
Searching...
No Matches
packet.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Network.
5 *
6 * StormByte-Network is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Network is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Network. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <StormByte/buffer/fifo.hxx>
24#include <StormByte/serializable.hxx>
25
39 public:
40 using OpcodeType = unsigned short;
41
45 Packet(const Packet& other) = default;
46
50 Packet(Packet&& other) noexcept = default;
51
55 virtual ~Packet() noexcept = default;
56
60 Packet& operator=(const Packet& other) = default;
61
65 Packet& operator=(Packet&& other) noexcept = default;
66
71 inline const OpcodeType& Opcode() const noexcept {
72 return m_opcode;
73 }
74
79 Buffer::FIFO Serialize() const noexcept;
80
84 static constexpr unsigned short PROCESS_THRESHOLD = 10;
85
86 protected:
87 OpcodeType m_opcode;
88
93 constexpr Packet(const OpcodeType& opcode) noexcept:
94 m_opcode(opcode) {}
95
100 virtual Buffer::DataType DoSerialize() const noexcept = 0;
101 };
102}
Polymorphic wire packet: opcode + payload hook.
Definition packet.hxx:38
Packet(Packet &&other) noexcept=default
Move constructor.
Packet(const Packet &other)=default
Copy constructor.
Buffer::FIFO Serialize() const noexcept
Serialize opcode followed by DoSerialize() payload.
virtual ~Packet() noexcept=default
Destructor.
virtual Buffer::DataType DoSerialize() const noexcept=0
Payload-only serialization (no opcode).
unsigned short OpcodeType
Opcode storage type.
Definition packet.hxx:40
Transport types of the Network module.
Definition packet.hxx:29
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:28