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/network/typedefs.hxx>
4
5#include <memory>
6
11namespace StormByte::Network {
21 class STORMBYTE_NETWORK_PUBLIC Packet {
22 public:
27 Packet(const Packet& other) = default;
28
33 Packet(Packet&& other) noexcept = default;
34
38 virtual ~Packet() noexcept = default;
39
45 Packet& operator=(const Packet& other) = default;
46
52 Packet& operator=(Packet&& other) noexcept = default;
53
58 const unsigned short& Opcode() const noexcept;
59
67
75 virtual Buffer::Consumer Serialize() const noexcept;
76
77 protected:
82 Packet(const unsigned short& opcode) noexcept;
83
89 virtual Expected<void, PacketError> Deserialize(PacketReaderFunction reader) noexcept = 0;
90
91 private:
92 const unsigned short m_opcode;
93 };
94}
The class representing an error in the packet.
Definition exception.hxx:51
Represents a network packet.
Definition packet.hxx:21
Packet(const Packet &other)=default
Copy constructor.
virtual ~Packet() noexcept=default
Destructor.
Packet(Packet &&other) noexcept=default
Move constructor.
The namespace containing read items.
Contains all the network-related classes and utilities.
Definition client.hxx:10
StormByte::Expected< std::shared_ptr< Packet >, PacketError > ExpectedPacket
The expected packet type.
Definition typedefs.hxx:38
std::function< ExpectedBuffer(const size_t &)> PacketReaderFunction
The packet reader function type.
Definition typedefs.hxx:40
std::function< std::shared_ptr< Packet >(const unsigned short &)> PacketInstanceFunction
The packet instance function type.
Definition typedefs.hxx:39