StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
|
Represents a network packet. More...
#include <packet.hxx>
Public Member Functions | |
Packet (const Packet &other)=default | |
Copy constructor. | |
Packet (Packet &&other) noexcept=default | |
Move constructor. | |
virtual | ~Packet () noexcept=default |
Destructor. | |
Packet & | operator= (const Packet &other)=default |
Copy assignment operator. | |
Packet & | operator= (Packet &&other) noexcept=default |
Move assignment operator. | |
const unsigned short & | Opcode () const noexcept |
Retrieves the opcode of the packet. | |
virtual Buffer::Consumer | Serialize () const noexcept |
Serializes the packet. | |
Static Public Member Functions | |
static ExpectedPacket | Read (const PacketInstanceFunction &pif, PacketReaderFunction reader) noexcept |
Reads a packet instance using the provided functions. | |
Protected Member Functions | |
Packet (const unsigned short &opcode) noexcept | |
Constructs a Packet with the specified opcode. | |
virtual Expected< void, PacketError > | Deserialize (PacketReaderFunction reader) noexcept=0 |
Deserializes the packet. | |
Represents a network packet.
This class serves as a base for implementing custom packets. To create a custom packet:
Deserialize
function to populate the data members using the reader
function.Serialize
function to populate the buffer. Ensure you call the base class Serialize
function to include the opcode.
|
default |
Copy constructor.
other | The other Packet to copy. |
|
defaultnoexcept |
Move constructor.
other | The other Packet to move. |
|
protectednoexcept |
Constructs a Packet with the specified opcode.
opcode | The opcode of the packet. |
|
protectedpure virtualnoexcept |
Deserializes the packet.
reader | The function to read the packet data. |
|
noexcept |
Retrieves the opcode of the packet.
|
staticnoexcept |
Reads a packet instance using the provided functions.
pif | The packet instance function. |
reader | The function to read the packet data. |
|
virtualnoexcept |
Serializes the packet.
Override this function in derived classes to produce a Buffer::Consumer
with custom data. Ensure the base class Serialize
function is called to include the opcode in the buffer and that you set the Consumer buffer to ReadOnly when finished so readers can detect EoF.