mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
mal_packet_weaver::PacketFactory Class Reference

A class responsible for registering and creating packet deserializers. More...

#include "packet-factory.hpp"

Collaboration diagram for mal_packet_weaver::PacketFactory:
[legend]

Static Public Member Functions

template<IsPacket PacketType>
static void RegisterDeserializer ()
 Register a packet deserializer function for a specific PacketType.
 
static void RegisterDeserializer (UniquePacketID packet_id, PacketDeserializeFunc factory)
 Register a packet deserializer function for a specific packet ID.
 
static std::unique_ptr< PacketDeserialize (const ByteView &bytearray, UniquePacketID packet_type)
 Deserialize a byte view into a unique pointer of the specified packet type.
 
static PacketFactoryinstance ()
 Instance of the Packet Factory.
 

Private Member Functions

 PacketFactory ()=default
 

Private Attributes

std::unordered_map< UniquePacketID, PacketDeserializeFuncpacket_deserializers_
 Map storing registered packet deserializer functions.
 

Static Private Attributes

static std::unique_ptr< PacketFactoryinstance_
 

Detailed Description

A class responsible for registering and creating packet deserializers.

Definition at line 12 of file packet-factory.hpp.

Constructor & Destructor Documentation

◆ PacketFactory()

mal_packet_weaver::PacketFactory::PacketFactory ( )
privatedefault

Member Function Documentation

◆ Deserialize()

static std::unique_ptr< Packet > mal_packet_weaver::PacketFactory::Deserialize ( const ByteView & bytearray,
UniquePacketID packet_type )
inlinestaticnodiscard

Deserialize a byte view into a unique pointer of the specified packet type.

This function uses the registered packet deserializer functions to deserialize the binary data from a ByteView and reconstruct a unique pointer to a packet instance.

Parameters
bytearrayThe ByteView containing the binary serialized data.
packet_typeThe unique packet ID specifying the packet type.
Returns
A unique pointer to the deserialized packet instance.

Definition at line 101 of file packet-factory.hpp.

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

◆ instance()

static PacketFactory & mal_packet_weaver::PacketFactory::instance ( )
inlinestatic

Instance of the Packet Factory.

Definition at line 115 of file packet-factory.hpp.

Here is the caller graph for this function:

◆ RegisterDeserializer() [1/2]

template<IsPacket PacketType>
static void mal_packet_weaver::PacketFactory::RegisterDeserializer ( )
inlinestatic

Register a packet deserializer function for a specific PacketType.

This template function allows registration of deserializer functions for packet types that satisfy the IsPacket concept. The function associates the packet's static_unique_id with its deserialize member function.

Template Parameters
PacketTypeThe packet type that satisfies the IsPacket concept.

Definition at line 25 of file packet-factory.hpp.

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

◆ RegisterDeserializer() [2/2]

static void mal_packet_weaver::PacketFactory::RegisterDeserializer ( UniquePacketID packet_id,
PacketDeserializeFunc factory )
inlinestatic

Register a packet deserializer function for a specific packet ID.

This function allows registration of a custom packet deserializer function for a unique packet ID. It associates the given packet_id with the provided factory function.

Parameters
packet_idThe unique packet ID.
factoryThe packet deserialization factory function.

Definition at line 75 of file packet-factory.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ instance_

std::unique_ptr< PacketFactory > mal_packet_weaver::PacketFactory::instance_
staticprivate

Definition at line 126 of file packet-factory.hpp.

◆ packet_deserializers_

std::unordered_map<UniquePacketID, PacketDeserializeFunc> mal_packet_weaver::PacketFactory::packet_deserializers_
private

Map storing registered packet deserializer functions.

Definition at line 130 of file packet-factory.hpp.


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