mal-packet-weaver
C++20 packet serialization/deserialization library.
|
A templated class representing a derived packet from the base Packet class. More...
#include "packet.hpp"
Public Member Functions | |
DerivedPacket () | |
Constructor for the DerivedPacket class. | |
virtual | ~DerivedPacket ()=default |
Virtual destructor for the DerivedPacket class. | |
void | serialize_to_bytearray (ByteArray &buffer) const override |
Serialize the derived packet data into a ByteArray. | |
virtual const char * | packet_name () const =0 |
float | timestamp () const noexcept |
Get the timestamp when the packet was received. | |
float | get_packet_time_alive () const noexcept |
Get the time elapsed since the packet was received. | |
bool | expired () const noexcept |
Check if the packet has expired based on its time-to-live. | |
Static Public Member Functions | |
static std::unique_ptr< Packet > | deserialize (const ByteView buffer) |
Deserialize a byte view into a unique pointer of the specified packet type. | |
Public Attributes | |
const UniquePacketID | type |
Unique packet ID. | |
const float | time_to_live |
Time-to-live for the packet. | |
const float | timestamp_ |
Timestamp when the packet was received. | |
Private Member Functions | |
template<class Archive > | |
void | serialize (Archive &, const unsigned int) |
Static Private Attributes | |
static Measurer< std::chrono::steady_clock > | measurer |
Measurer for packet timestamps. | |
A templated class representing a derived packet from the base Packet class.
Derived packets are specialized implementations of Packet that define specific packet types.
They inherit serialization and deserialization functionality from the base Packet class and can be used to encapsulate and manage different types of data for communication.
The template parameter PacketType
specifies the concrete derived packet type.
PacketType | The specific derived packet type. |
Definition at line 113 of file packet.hpp.
|
inline |
Constructor for the DerivedPacket class.
Initializes the packet with the static_unique_id and time_to_live of the PacketType.
Definition at line 121 of file packet.hpp.
|
virtualdefault |
Virtual destructor for the DerivedPacket class.
|
inlinestaticnodiscard |
Deserialize a byte view into a unique pointer of the specified packet type.
This static function is responsible for deserializing the binary data from a ByteView and reconstructing a unique pointer to a PacketType instance.
buffer | The ByteView containing the binary serialized data. |
Definition at line 155 of file packet.hpp.
|
inlinenodiscardnoexceptinherited |
Check if the packet has expired based on its time-to-live.
Definition at line 77 of file packet.hpp.
|
inlinenodiscardnoexceptinherited |
Get the time elapsed since the packet was received.
Definition at line 74 of file packet.hpp.
|
pure virtualinherited |
|
inlineprivateinherited |
Definition at line 89 of file packet.hpp.
|
inlineoverridevirtual |
Serialize the derived packet data into a ByteArray.
This function uses Boost's binary serialization to convert the packet's contents into a binary representation and appends it to the provided buffer.
buffer | The ByteArray to which the serialized data is appended. |
Implements mal_packet_weaver::Packet.
Definition at line 136 of file packet.hpp.
|
inlinenodiscardnoexceptinherited |
Get the timestamp when the packet was received.
Definition at line 71 of file packet.hpp.
|
staticprivateinherited |
Measurer for packet timestamps.
Definition at line 49 of file packet.hpp.
|
inherited |
Time-to-live for the packet.
Definition at line 80 of file packet.hpp.
|
inherited |
Timestamp when the packet was received.
Definition at line 81 of file packet.hpp.
|
inherited |
Unique packet ID.
Definition at line 79 of file packet.hpp.