A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd
MIT licensed
Join the ETL community

message_packet


A container for more than one type of message.
The messages must have been derived from etl::imessage.

The messages types that the packet may contain are listed as template parameters.
e.g. etl::message_packet<Message1, Message2, Message3>

____________________________________________________________________________________________________

message_packet(const etl::imessage&)

Constructs a message packet from an etl::imessage reference.
Asserts an etl::unhandled_message_exception if the parameter is not one listed in the template parameter list.

____________________________________________________________________________________________________
template <typename T>
message_packet(const T&)

Constructs a message packet from the parameter.
Static asserts if the parameter type is not one listed in the template parameter list.

____________________________________________________________________________________________________
etl::imessage& get()
const etl::imessage& get() const

Returns a reference to an etl::imessage

____________________________________________________________________________________________________

Constants


SIZE      The size of the largest message.
ALIGNMENT The largest message alignment.

____________________________________________________________________________________________________

Example


enum
{
  MESSAGE1,
  MESSAGE2,
  MESSAGE3
};

struct Message1 : public etl::message<MESSAGE1>
{
};

struct Message2 : public etl::message<MESSAGE2>
{
};

struct Message3 : public etl::message<MESSAGE3>
{
};

using Packet = etl::message_packet<Message1, Message2>

Message1 message1;
Message2 message2;
Message3 message3;

Packet packet1(message1);
Packet packet2(message2);
Packet packet3(message3); // Compile time error! Packet does not support Message3 type.

etl::imessage& m1 = message1;
Packet packet4(m1); // Construct from an etl::imessage reference.

etl::imessage& m3 = message3;
Packet packet4(m3); // Asserts etl::unhandled_message_exception! Packet does not support Message3 type.

etl::imessage& m = packet2.get(); // Get a reference to an etl::imessage from the packet.

message_packet.h