|
StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
|
Base class for wire-level packets. More...
#include <packet.hxx>
Public Types | |
| using | OpcodeType = unsigned short |
| The type of the opcode. | |
Public Member Functions | |
| Packet (const Packet &other)=default | |
| Copy constructor. | |
| Packet (Packet &&other) noexcept=default | |
| Move constructor. | |
| virtual | ~Packet () noexcept=default |
| Virtual destructor. | |
| Packet & | operator= (const Packet &other)=default |
| Copy assignment operator. | |
| Packet & | operator= (Packet &&other) noexcept=default |
| Move assignment operator. | |
| const OpcodeType & | Opcode () const noexcept |
| Retrieve the packet opcode. | |
| Buffer::FIFO | Serialize () const noexcept |
| Serialize the packet to a byte buffer. | |
Static Public Attributes | |
| static constexpr unsigned short | PROCESS_THRESHOLD = 10 |
| Threshold for processing packets. | |
Protected Member Functions | |
| constexpr | Packet (const OpcodeType &opcode) noexcept |
| Protected ctor. | |
| virtual Buffer::DataType | DoSerialize () const noexcept=0 |
| Packet-specific serialization hook. | |
Protected Attributes | |
| OpcodeType | m_opcode |
| The opcode of the packet. | |
Base class for wire-level packets.
Packet provides a minimal, polymorphic representation of an application protocol packet. It stores an opcode value (see OpcodeType) and exposes a protected serialization hook that derived classes override to append their payload bytes. The base Serialize() implementation serializes the opcode and then appends the result of DoSerialize().
DoSerialize() to return the on-wire representation of the packet payload (excluding the opcode).Serialize() to obtain the complete byte buffer for transport.OpcodeType is the integral type used to store opcode values (currently unsigned short). When constructing derived packets you may use your own enum types, provided their values are convertible to OpcodeType and fall within its non-negative representable range (no negative values and not greater than the maximum representable value of OpcodeType, e.g. 65535 for unsigned short). Avoid targeting this base's OpcodeType with signed enums that may contain negative values.PacketBase interface in your project and have your Packet-derived types inherit from it. That interface should declare the non-templated virtual API you need (for example Serialize() / DoSerialize() returning Buffer::FIFO).
|
default |
Copy constructor.
Performs a member-wise copy of the opcode and any other members provided by derived classes. If a derived class contains non-copyable resources it should provide its own copy constructor.
|
defaultnoexcept |
Move constructor.
Move-constructs members. Marked noexcept to allow efficient moves in containers; override this if derived classes require different move semantics.
|
virtualdefaultnoexcept |
Virtual destructor.
Virtual to allow derived types to be destroyed through base pointers. The class remains abstract because DoSerialize() is pure virtual.
|
inlineconstexprprotectednoexcept |
Protected ctor.
Construct a packet with the given opcode. Protected so that only derived classes may create concrete packets.
| opcode | The packet opcode. |
|
protectedpure virtualnoexcept |
Packet-specific serialization hook.
Derived classes must override this method to provide their specific on-wire payload serialization (excluding the opcode). The base Serialize() implementation calls this method and appends its result after serializing the opcode.
Buffer::DataType containing the serialized payload.
|
inlinenoexcept |
Retrieve the packet opcode.
Returns a reference to the stored opcode. The value is stable for the lifetime of the object.
Copy assignment operator.
Defaulted; performs member-wise assignment. Derived types that manage non-copyable state should provide their own assignment operator.
Move assignment operator.
Defaulted and marked noexcept; moves member state where possible. Override in derived classes if different semantics are required.
|
noexcept |
Serialize the packet to a byte buffer.
Serializes the packet by first writing the opcode as OpcodeType, followed by the result of DoSerialize().
Buffer::FIFO containing the serialized packet.
|
staticconstexpr |
Threshold for processing packets.
Packets with payload sizes equal to or above this threshold will be processed (e.g., compressed/encrypted) when being serialized into frames. Packets with smaller payloads will be transmitted unprocessed. The threshold for processing packets.