Skip to content

Class cerializer::MessageMaker

ClassList > cerializer > MessageMaker

A factory class for creating message objects from binary data. More...

  • #include <serializer.hpp>

Public Types

Type Name
typedef std::function< BasePointer(const std::span< char > &binaryData)> TCreateMethod
A function pointer type for a method that creates a message object.

Public Static Functions

Type Name
BasePointer Create (const uint8_t typeVal, const std::span< char > & binaryData)
Creates a message object of the specified type.
bool Register (const uint8_t typeVal, TCreateMethod builder)
Registers a message type with the factory.

Detailed Description

This class uses the factory pattern to decouple the message parsing logic from the concrete message classes. It maintains a map of message type codes to constructor functions, allowing for dynamic creation of message objects based on a type code read from a stream.

Public Types Documentation

typedef TCreateMethod

A function pointer type for a method that creates a message object.

using cerializer::MessageMaker::TCreateMethod =  std::function<BasePointer(const std::span<char>& binaryData)>;

Public Static Functions Documentation

function Create

Creates a message object of the specified type.

static inline BasePointer cerializer::MessageMaker::Create (
    const uint8_t typeVal,
    const std::span< char > & binaryData
) 

Parameters:

  • typeVal The unique identifier for the message type.
  • binaryData The binary data to deserialize.

Returns:

A unique pointer to the created message object, or nullptr if the type is not registered.


function Register

Registers a message type with the factory.

static inline bool cerializer::MessageMaker::Register (
    const uint8_t typeVal,
    TCreateMethod builder
) 

Parameters:

  • typeVal The unique identifier for the message type.
  • builder The function that constructs the message object.

Returns:

True if registration was successful.



The documentation for this class was generated from the following file serializer.hpp