mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
mal_packet_weaver::DerivedPacket< PacketType > Class Template Referenceabstract

A templated class representing a derived packet from the base Packet class. More...

#include "packet.hpp"

Inheritance diagram for mal_packet_weaver::DerivedPacket< PacketType >:
[legend]
Collaboration diagram for mal_packet_weaver::DerivedPacket< PacketType >:
[legend]

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< Packetdeserialize (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.
 

Detailed Description

template<typename PacketType>
class mal_packet_weaver::DerivedPacket< PacketType >

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.

Note
We cannot check within this class if requirements for packet type are satisfied, but IsPacket concept is used thoroughly within the library. It requires that the class should be final, declared time_to_live, static_unique_id and deserialize functions.
Template Parameters
PacketTypeThe specific derived packet type.

Definition at line 113 of file packet.hpp.

Constructor & Destructor Documentation

◆ DerivedPacket()

template<typename PacketType >
mal_packet_weaver::DerivedPacket< PacketType >::DerivedPacket ( )
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.

◆ ~DerivedPacket()

template<typename PacketType >
virtual mal_packet_weaver::DerivedPacket< PacketType >::~DerivedPacket ( )
virtualdefault

Virtual destructor for the DerivedPacket class.

Member Function Documentation

◆ deserialize()

template<typename PacketType >
static std::unique_ptr< Packet > mal_packet_weaver::DerivedPacket< PacketType >::deserialize ( const ByteView buffer)
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.

Parameters
bufferThe ByteView containing the binary serialized data.
Returns
A unique pointer to the deserialized PacketType instance.
Todo
: add an ability to choose the archive type.

Definition at line 155 of file packet.hpp.

Here is the call graph for this function:

◆ expired()

bool mal_packet_weaver::Packet::expired ( ) const
inlinenodiscardnoexceptinherited

Check if the packet has expired based on its time-to-live.

Definition at line 77 of file packet.hpp.

Here is the call graph for this function:

◆ get_packet_time_alive()

float mal_packet_weaver::Packet::get_packet_time_alive ( ) const
inlinenodiscardnoexceptinherited

Get the time elapsed since the packet was received.

Definition at line 74 of file packet.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ packet_name()

virtual const char * mal_packet_weaver::Packet::packet_name ( ) const
pure virtualinherited

◆ serialize()

template<class Archive >
void mal_packet_weaver::Packet::serialize ( Archive & ,
const unsigned int  )
inlineprivateinherited

Definition at line 89 of file packet.hpp.

◆ serialize_to_bytearray()

template<typename PacketType >
void mal_packet_weaver::DerivedPacket< PacketType >::serialize_to_bytearray ( ByteArray & buffer) const
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.

Parameters
bufferThe ByteArray to which the serialized data is appended.
Todo
: add an ability to choose the archive type.

Implements mal_packet_weaver::Packet.

Definition at line 136 of file packet.hpp.

Here is the call graph for this function:

◆ timestamp()

float mal_packet_weaver::Packet::timestamp ( ) const
inlinenodiscardnoexceptinherited

Get the timestamp when the packet was received.

Definition at line 71 of file packet.hpp.

Member Data Documentation

◆ measurer

Measurer< std::chrono::steady_clock > mal_packet_weaver::Packet::measurer
staticprivateinherited

Measurer for packet timestamps.

Definition at line 49 of file packet.hpp.

◆ time_to_live

const float mal_packet_weaver::Packet::time_to_live
inherited

Time-to-live for the packet.

Definition at line 80 of file packet.hpp.

◆ timestamp_

const float mal_packet_weaver::Packet::timestamp_
inherited

Timestamp when the packet was received.

Definition at line 81 of file packet.hpp.

◆ type

const UniquePacketID mal_packet_weaver::Packet::type
inherited

Unique packet ID.

Definition at line 79 of file packet.hpp.


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