![]() |
CommRaT 2.0.0
C++20 Real-Time Messaging Framework
|
Compile-time message type registry using MessageDefinition templates. More...
#include <commrat/messaging/message_registry.hpp>
Classes | |
| struct | IsInTuple |
| struct | IsInTuple< T, std::tuple< Types... > > |
Public Types | |
| using | PayloadTypes = typename ExtractPayloads< ProcessedDefs >::PayloadTypes |
| template<uint32_t ID> | |
| using | PayloadTypeFor = typename TypeByID< ID, 0 >::type |
| Get the payload type by message ID (compile-time) | |
| template<std::size_t I> | |
| using | type_at = std::tuple_element_t< I, PayloadTypes > |
| Get payload type at index I. | |
Static Public Member Functions | |
| template<typename... Payloads> | |
| static constexpr size_t | calc_max_size (std::tuple< Payloads... > *) |
| template<typename... SpecificTypes> | |
| static constexpr size_t | max_size_for_types () |
| Calculate maximum message size for specific payload types. | |
| template<typename T > requires is_registered_v<T> | |
| static constexpr uint32_t | get_message_id () |
| Get the message ID for a given payload type. | |
| template<typename T > requires is_registered_v<T> | |
| static auto | serialize (T &message) |
| Serialize a message with automatic type registration check. | |
| template<typename PayloadT > requires is_registered_v<PayloadT> | |
| static auto | serialize (TimsMessage< PayloadT > &message) |
| Serialize a TimsMessage<PayloadT> wrapper. | |
| template<typename T > requires is_registered_v<T> && (!requires { typename T::payload_type; }) | |
| static auto | deserialize (std::span< const std::byte > data) |
| Deserialize a message with known type at compile time. | |
| template<typename MsgT > requires requires { typename MsgT::payload_type; } && is_registered_v<typename MsgT::payload_type> | |
| static auto | deserialize (std::span< const std::byte > data) |
| Deserialize a TimsMessage<PayloadT> wrapper. | |
| template<typename Visitor > | |
| static bool | visit (uint32_t msg_id, std::span< const std::byte > data, Visitor &&visitor) |
| Visit a message by its message ID using a visitor. | |
| template<typename Callback > | |
| static bool | dispatch (uint32_t msg_id, std::span< const std::byte > data, Callback &&callback) |
| Deserialize message by ID and dispatch to callback. | |
| static constexpr size_t | max_buffer_size () |
| Get maximum buffer size needed for any message in the registry. | |
| static constexpr size_t | size () |
| Get number of registered message types. | |
| template<typename... Defs> | |
| static constexpr auto | get_all_ids_impl (std::tuple< Defs... > *) |
| Get list of all message IDs in the registry. | |
| static constexpr auto | message_ids () |
| template<typename T > | |
| static constexpr std::size_t | get_type_index () |
| Get type index for payload type T. | |
Static Public Attributes | |
| template<typename T > | |
| static constexpr bool | is_registered_v = IsInTuple<T, PayloadTypes>::value |
| static constexpr size_t | num_types = sizeof...(MessageDefs) |
| static constexpr size_t | max_message_size = calc_max_size(static_cast<PayloadTypes*>(nullptr)) |
| template<typename T > | |
| static constexpr bool | is_registered = is_registered_v<T> |
| Check if a payload type is registered. | |
| template<uint32_t ID> | |
| static constexpr bool | has_message_id = TypeByID<ID, 0>::found |
| Check if a message ID is registered. | |
Compile-time message type registry using MessageDefinition templates.
This registry uses the new MessageDefinition system for compile-time message ID generation, auto-increment, collision detection, and type-safe dispatch.
Usage: using MyRegistry = MessageRegistry< MessageDefinition<StatusData, MessagePrefix::UserDefined, UserSubPrefix::Data>, MessageDefinition<CommandMessage, MessagePrefix::UserDefined, UserSubPrefix::Commands>, MessageDefinition<SubscribeRequest, MessagePrefix::System, SystemSubPrefix::Subscription, 0x0001> >;
// Auto-increment and collision detection happen at compile-time // max_message_size calculated from all payload types
Definition at line 148 of file message_registry.hpp.
| using commrat::MessageRegistry< MessageDefs >::PayloadTypeFor = typename TypeByID<ID, 0>::type |
Get the payload type by message ID (compile-time)
Definition at line 333 of file message_registry.hpp.
| using commrat::MessageRegistry< MessageDefs >::PayloadTypes = typename ExtractPayloads<ProcessedDefs>::PayloadTypes |
Definition at line 167 of file message_registry.hpp.
| using commrat::MessageRegistry< MessageDefs >::type_at = std::tuple_element_t<I, PayloadTypes> |
Get payload type at index I.
Definition at line 518 of file message_registry.hpp.
|
inlinestaticconstexpr |
Definition at line 187 of file message_registry.hpp.
References commrat::MessageRegistry< MessageDefs >::max_buffer_size().
|
inlinestatic |
Deserialize a message with known type at compile time.
Use this when you know the message type at compile time. For payload types, deserializes to TimsMessage<T> and extracts payload.
| data | Buffer containing serialized message |
Definition at line 402 of file message_registry.hpp.
|
inlinestatic |
Deserialize a TimsMessage<PayloadT> wrapper.
Overload for TimsMessage<PayloadT> where PayloadT is registered. This enables payload-only registration while still deserializing the full message with header.
Definition at line 427 of file message_registry.hpp.
|
inlinestatic |
Deserialize message by ID and dispatch to callback.
This is a convenience wrapper around visit() for consistency with older API.
| msg_id | The message ID (32-bit) |
| data | Buffer containing serialized message |
| callback | Callback function that accepts any message type |
Definition at line 470 of file message_registry.hpp.
References commrat::MessageRegistry< MessageDefs >::visit().
|
inlinestaticconstexpr |
Get list of all message IDs in the registry.
Definition at line 496 of file message_registry.hpp.
References commrat::make_message_id().
Referenced by commrat::MessageRegistry< MessageDefs >::message_ids().
|
inlinestaticconstexpr |
Get the message ID for a given payload type.
Definition at line 325 of file message_registry.hpp.
|
inlinestaticconstexpr |
Get type index for payload type T.
Definition at line 524 of file message_registry.hpp.
|
inlinestaticconstexpr |
Get maximum buffer size needed for any message in the registry.
Definition at line 481 of file message_registry.hpp.
References commrat::MessageRegistry< MessageDefs >::max_message_size.
Referenced by commrat::MessageRegistry< MessageDefs >::calc_max_size(), and commrat::MessageRegistry< MessageDefs >::max_size_for_types().
|
inlinestaticconstexpr |
Calculate maximum message size for specific payload types.
This allows creating typed mailboxes with correct buffer sizes instead of using max_message_size for all mailboxes (which wastes memory).
| SpecificTypes | Subset of payload types |
Example:
Definition at line 210 of file message_registry.hpp.
References commrat::MessageRegistry< MessageDefs >::max_buffer_size().
|
inlinestaticconstexpr |
Definition at line 506 of file message_registry.hpp.
References commrat::MessageRegistry< MessageDefs >::get_all_ids_impl().
|
inlinestatic |
Serialize a message with automatic type registration check.
This function provides compile-time type safety - will not compile if the message type is not registered in the registry.
| message | The message to serialize |
Definition at line 356 of file message_registry.hpp.
References commrat::serialize_message().
Referenced by commrat::MessageRegistry< MessageDefs >::serialize().
|
inlinestatic |
Serialize a TimsMessage<PayloadT> wrapper.
Overload for TimsMessage<PayloadT> where PayloadT is registered. This enables payload-only registration while still serializing the full message with header.
Definition at line 378 of file message_registry.hpp.
References commrat::TimsMessage< PayloadT >::header, commrat::TimsHeader::msg_size, commrat::TimsHeader::msg_type, and commrat::MessageRegistry< MessageDefs >::serialize().
|
inlinestaticconstexpr |
Get number of registered message types.
Definition at line 488 of file message_registry.hpp.
References commrat::MessageRegistry< MessageDefs >::num_types.
|
inlinestatic |
Visit a message by its message ID using a visitor.
This provides runtime dispatch when the message type is not known at compile time. Uses template expansion to generate efficient switch-like behavior without virtual functions.
The visitor should accept any message type in the registry: auto visitor = [](auto&& msg) { using MsgType = std::decay_t<decltype(msg)>; // Handle message... };
| msg_id | The message ID (32-bit) |
| data | Buffer containing serialized message |
| visitor | Visitor function/lambda that accepts any message type |
Definition at line 455 of file message_registry.hpp.
Referenced by commrat::MessageRegistry< MessageDefs >::dispatch().
|
staticconstexpr |
Check if a message ID is registered.
Definition at line 339 of file message_registry.hpp.
|
staticconstexpr |
Check if a payload type is registered.
Definition at line 318 of file message_registry.hpp.
|
staticconstexpr |
Definition at line 179 of file message_registry.hpp.
|
staticconstexpr |
Definition at line 191 of file message_registry.hpp.
Referenced by commrat::createWorkMailboxConfig(), commrat::MailboxSet< UserRegistry, OutputType, CommandTypes >::initialize(), and commrat::MessageRegistry< MessageDefs >::max_buffer_size().
|
staticconstexpr |
Definition at line 182 of file message_registry.hpp.
Referenced by commrat::MessageRegistry< MessageDefs >::size().