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
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
StormByte::Network::Packet Class Referenceabstract

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.
 
Packetoperator= (const Packet &other)=default
 Copy assignment operator.
 
Packetoperator= (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, PacketErrorDeserialize (PacketReaderFunction reader) noexcept=0
 Deserializes the packet.
 

Detailed Description

Represents a network packet.

This class serves as a base for implementing custom packets. To create a custom packet:

Constructor & Destructor Documentation

◆ Packet() [1/3]

StormByte::Network::Packet::Packet ( const Packet other)
default

Copy constructor.

Parameters
otherThe other Packet to copy.

◆ Packet() [2/3]

StormByte::Network::Packet::Packet ( Packet &&  other)
defaultnoexcept

Move constructor.

Parameters
otherThe other Packet to move.

◆ Packet() [3/3]

StormByte::Network::Packet::Packet ( const unsigned short &  opcode)
protectednoexcept

Constructs a Packet with the specified opcode.

Parameters
opcodeThe opcode of the packet.

Member Function Documentation

◆ Deserialize()

virtual Expected< void, PacketError > StormByte::Network::Packet::Deserialize ( PacketReaderFunction  reader)
protectedpure virtualnoexcept

Deserializes the packet.

Parameters
readerThe function to read the packet data.
Returns
An expected result or an error.

◆ Opcode()

const unsigned short & StormByte::Network::Packet::Opcode ( ) const
noexcept

Retrieves the opcode of the packet.

Returns
A constant reference to the packet's opcode.

◆ operator=() [1/2]

Packet & StormByte::Network::Packet::operator= ( const Packet other)
default

Copy assignment operator.

Parameters
otherThe other Packet to assign.
Returns
A reference to the assigned Packet.

◆ operator=() [2/2]

Packet & StormByte::Network::Packet::operator= ( Packet &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherThe other Packet to assign.
Returns
A reference to the assigned Packet.

◆ Read()

static ExpectedPacket StormByte::Network::Packet::Read ( const PacketInstanceFunction pif,
PacketReaderFunction  reader 
)
staticnoexcept

Reads a packet instance using the provided functions.

Parameters
pifThe packet instance function.
readerThe function to read the packet data.
Returns
An expected packet or an error.

◆ Serialize()

virtual Buffer::Consumer StormByte::Network::Packet::Serialize ( ) const
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.


The documentation for this class was generated from the following file: