Class cerializer::Message
template <typename Derived, uint8_t TypeVal, typename... FieldTypes>
ClassList > cerializer > Message
A template base class for defining serializable messages. More...
#include <serializer.hpp>
Inherits the following classes: cerializer::BasePacket
Public Types
| Type | Name |
|---|---|
| typedef std::array< char,(sizeof(FieldTypes)+...)+2 *sizeof(uint16_t)+sizeof(uint8_t)> | BinaryMessage A type alias for the array holding the full binary message, including headers and footers. |
| typedef std::array< char, 4+(std::get< 0 >(formatSize< FieldTypes >())+...)> | MessageFormat A type alias for the array holding the message's format string. |
Public Static Attributes
| Type | Name |
|---|---|
| const bool | registered = /* multi line expression */A static flag that triggers registration with the MessageMaker factory upon program start. |
Public Functions
| Type | Name |
|---|---|
| virtual constexpr uint8_t | Code () override Gets the unique code for this message type. |
| constexpr BinaryMessage | ToBinary () const Generates the binary representation of the message. This method serializes the message fields, adds the magic head/foot and type code. |
Public Functions inherited from cerializer::BasePacket
| Type | Name |
|---|---|
| virtual constexpr uint8_t | Code () = 0 Gets the unique 8-bit code that identifies the message type. |
| virtual | ~BasePacket () = default |
Public Static Functions
| Type | Name |
|---|---|
| constexpr MessageFormat | Format () Generates the format string for the message. |
| constexpr Derived | LoadBinary (BinaryMessage & binaryData) Deserializes a message from a character array. |
| constexpr Derived | LoadBinary (const std::span< char > & binaryData) Deserializes a message from a span of characters. |
| constexpr unsigned int | Size () Gets the total size of the message payload in bytes. |
| constexpr uint8_t | Type () Gets the unique code for this message type (static version). |
Detailed Description
This class uses the Curiously Recurring Template Pattern (CRTP) to provide a common interface and implementation for all message types. It automatically handles registration with the MessageMaker factory, serialization to a binary format (including headers and footers), and deserialization.
To define a new message, a class should inherit from this template, providing itself as the Derived parameter, a unique TypeVal, and a list of the FieldTypes that make up its payload.
Template parameters:
DerivedThe derived message class that is being defined.TypeValA unique 8-bit identifier for this message type.FieldTypesA parameter pack of the types of the fields in the message payload.
Public Types Documentation
typedef BinaryMessage
A type alias for the array holding the full binary message, including headers and footers.
using cerializer::Message< Derived, TypeVal, FieldTypes >::BinaryMessage = std::array<char, (sizeof(FieldTypes) + ...) + 2 * sizeof(uint16_t) + sizeof(uint8_t)>;
typedef MessageFormat
A type alias for the array holding the message's format string.
using cerializer::Message< Derived, TypeVal, FieldTypes >::MessageFormat = std::array<char, 4 + (std::get<0>(formatSize<FieldTypes>()) + ...)>;
Public Static Attributes Documentation
variable registered
A static flag that triggers registration with the MessageMaker factory upon program start.
const bool cerializer::Message< Derived, TypeVal, FieldTypes >::registered;
Public Functions Documentation
function Code
Gets the unique code for this message type.
inline virtual constexpr uint8_t cerializer::Message::Code () override
Returns:
The 8-bit type code.
Implements cerializer::BasePacket::Code
function ToBinary
Generates the binary representation of the message. This method serializes the message fields, adds the magic head/foot and type code.
inline constexpr BinaryMessage cerializer::Message::ToBinary () const
Returns:
An array of characters containing the full binary message.
Public Static Functions Documentation
function Format
Generates the format string for the message.
static inline constexpr MessageFormat cerializer::Message::Format ()
Returns:
An array of characters representing the format.
function LoadBinary [1/2]
Deserializes a message from a character array.
static inline constexpr Derived cerializer::Message::LoadBinary (
BinaryMessage & binaryData
)
Parameters:
binaryDataThe array containing the binary message.
Returns:
An instance of the derived message class.
function LoadBinary [2/2]
Deserializes a message from a span of characters.
static inline constexpr Derived cerializer::Message::LoadBinary (
const std::span< char > & binaryData
)
Parameters:
binaryDataThe span containing the binary message.
Returns:
An instance of the derived message class.
function Size
Gets the total size of the message payload in bytes.
static inline constexpr unsigned int cerializer::Message::Size ()
Returns:
The size of the message payload.
function Type
Gets the unique code for this message type (static version).
static inline constexpr uint8_t cerializer::Message::Type ()
Returns:
The 8-bit type code.
The documentation for this class was generated from the following file serializer.hpp