COMMS
Template library intended to help with implementation of communication protocols.
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Related Functions | List of all members
comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts > Class Template Reference

#include "comms/GenericMessage.h"

Detailed Description

template<typename TMessage, typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
class comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >

Generic Message.

Generic message is there to substitute definition of actual message when contents of the latter are not important. It defines single data field as variable length sequence of raw bytes (see GenericMessageFields). The GenericMessage can be useful when implementing some kind of "bridge" or "firewall", that requires knowledge only about message ID and doesn't care much about message contents. The comms::protocol::MsgIdLayer support creation of the GenericMessage in case the received message ID is not known (supported by using comms::option::app::SupportGenericMessage option).

Template Parameters
TMessageCommon message interface class, becomes one of the base classes.
TFieldOptsExtra option(s) (multiple options need to be bundled in std::tuple) to be passed to the definition of the data field (see GenericMessageFields).
TExtraOptsExtra option(s) (multple options need to be bundled in std::tuple) to be passed to comms::MessageBase which is base to this one.
Precondition
Requires the common message interface (TMessage) to define inner MsgIdType and MsgIdParamType types (expected to use comms::option::def::MsgIdType, see Using Generic Message)
Inheritance diagram for comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >:
comms::MessageBase< TMessage, comms::option::def::FieldsImpl< GenericMessageFields< TMessage::Field, comms::option::app::EmptyOption > >, comms::option::def::MsgType< GenericMessage< TMessage, comms::option::app::EmptyOption, comms::option::app::EmptyOption > >, comms::option::def::HasDoGetId, comms::option::def::HasName, comms::option::app::EmptyOption > comms::Message< TOptions >

Public Types

using AllFields = FieldsProvidedWithOption
 All field classes provided with comms::option::def::FieldsImpl option. More...
 
using DispatchRetType = typename Handler::RetType
 Return type of the dispatch() member function. More...
 
using Endian = typename BaseImpl::Endian
 Serialisation endian type. More...
 
using Field = BaseImpl::Field
 Type of default base class for all the fields. More...
 
using Handler = TypeProvidedWithOption
 Type of the message handler object. More...
 
using ImplOptions = details::MessageImplOptionsParser< TOptions... >
 All the options provided to this class bundled into struct. More...
 
using InterfaceOptions = details::MessageInterfaceOptionsParser< TOptions... >
 All the options bundled into struct. More...
 
using MsgIdParamType = typename Base::MsgIdParamType
 Type of the message ID passed as parameter. More...
 
using MsgIdType = typename Base::MsgIdType
 Type of the message ID. More...
 
using MsgType = typename ImplOptions::MsgType
 Type of the actual message provided via comms::option::def::MsgType. More...
 
using ReadIterator = TypeProvidedWithOption
 Type of the iterator used for reading message contents from sequence of bytes stored somewhere. More...
 
using TransportFields = FieldsProvidedWithOption
 std::tuple of extra fields from transport layers that may affect the way the message fields get serialized / deserialized. More...
 
using VersionType = typename BaseImpl::VersionType
 Type used for version info. More...
 
using WriteIterator = TypeProvidedWithOption
 Type of the iterator used for writing message contents into sequence of bytes stored somewhere. More...
 

Public Member Functions

 GenericMessage ()=delete
 Default constructor is deleted.
 
 GenericMessage (const GenericMessage &)=default
 Copy constructor.
 
 GenericMessage (GenericMessage &&)=default
 Move constructor.
 
 GenericMessage (MsgIdParamType id)
 Constructor. More...
 
 ~GenericMessage () noexcept=default
 Destructor.
 
 COMMS_MSG_FIELDS_NAMES (data)
 Allow access to internal fields. More...
 
DispatchRetType dispatch (Handler &handler)
 Dispatch message to the handler for processing. More...
 
bool doFieldsVersionUpdate ()
 Update version information of all the fields. More...
 
MsgIdParamType doGetId () const
 Get message ID information. More...
 
std::size_t doLength () const
 Default implementation of length calculation functionality. More...
 
std::size_t doLengthFrom () const
 Default implementation of partial length calculation functionality. More...
 
std::size_t doLengthFromUntil () const
 Default implementation of partial length calculation functionality. More...
 
std::size_t doLengthUntil () const
 Default implementation of partial length calculation functionality. More...
 
std::size_t doMaxLengthFromUntil () const
 Compile time constant of maximal partial serialisation length. More...
 
std::size_t doMinLengthFromUntil () const
 Compile time constant of minimal partial serialisation length. More...
 
ErrorStatus doRead (TIter &iter, std::size_t size)
 Default implementation of read functionality. More...
 
bool doRefresh () const
 Default implementation of refreshing functionality. More...
 
bool doValid () const
 Default implementation of validity check functionality. More...
 
ErrorStatus doWrite (TIter &iter, std::size_t size) const
 Default implementation of write functionality. More...
 
AllFieldsfields ()
 Get an access to the fields of the message. More...
 
const AllFieldsfields () const
 Get an access to the fields of the message. More...
 
MsgIdParamType getId () const
 Retrieve ID of the message. More...
 
std::size_t length () const
 Get number of bytes required to serialise this message. More...
 
const char * name () const
 Get name of the message. More...
 
GenericMessageoperator= (const GenericMessage &)=default
 Copy assignment.
 
GenericMessageoperator= (GenericMessage &&)=default
 Move assignment.
 
ErrorStatus read (ReadIterator &iter, std::size_t size)
 Read message contents using provided iterator. More...
 
bool refresh ()
 Refresh to contents of the message. More...
 
TransportFieldstransportFields ()
 Get access to extra transport fields. More...
 
const TransportFieldstransportFields () const
 Const version of transportFields. More...
 
bool valid () const
 Check validity of message contents. More...
 
VersionTypeversion ()
 Access to version information. More...
 
const VersionTypeversion () const
 Const access to version information. More...
 
ErrorStatus write (WriteIterator &iter, std::size_t size) const
 Write message contents using provided iterator. More...
 

Static Public Member Functions

static constexpr bool areFieldsVersionDependent ()
 Compile time check of whether the message fields are version dependent. More...
 
static constexpr MsgIdParamType doGetId ()
 Default implementation of ID retrieval functionality. More...
 
static constexpr std::size_t doMaxLength ()
 Compile time constant of maximal serialisation length. More...
 
static constexpr std::size_t doMaxLengthFrom ()
 Compile time constant of maximal partial serialisation length. More...
 
static constexpr std::size_t doMaxLengthUntil ()
 Compile time constant of maximal partial serialisation length. More...
 
static constexpr std::size_t doMinLength ()
 Compile time constant of minimal serialisation length. More...
 
static constexpr std::size_t doMinLengthFrom ()
 Compile time constant of minimal partial serialisation length. More...
 
static constexpr std::size_t doMinLengthUntil ()
 Compile time constant of minimal partial serialisation length. More...
 
static const char * doName ()
 Get message name information. More...
 
static constexpr bool hasCustomName ()
 Compile time inquiry of whether comms::MessageBase has notified about custom name retrieval function in the derived class via comms::option::def::HasName.
 
static constexpr bool hasCustomRefresh ()
 Compile time inquiry of whether comms::MessageBase has notified about custom refresh functionality in the derived class via comms::option::def::HasCustomRefresh.
 
static constexpr bool hasDispatch ()
 Compile type inquiry whether message interface class defines dispatch() and dispatchImpl() member functions as well as Handler and DispatchRetType types.
 
static constexpr bool hasEndian ()
 Compile type inquiry whether message interface class defines Endian and Field types.
 
static constexpr bool hasFailOnInvalid ()
 Compile time inquiry of whether fail on invalid has been requested comms::option::def::FailOnInvalid option.
 
static constexpr bool hasFields ()
 Compile type inquiry whether fields have been provided via comms::option::def::FieldsImpl.
 
static constexpr bool hasGetId ()
 Compile type inquiry whether message interface class defines getId() and getIdImpl() member functions.
 
static constexpr bool hasLength ()
 Compile type inquiry whether message interface class defines length() and lengthImpl() member functions.
 
static constexpr bool hasMsgIdType ()
 Compile type inquiry whether message interface class defines MsgIdType and MsgIdParamType types.
 
static constexpr bool hasMsgType ()
 Compile time inquiry of whether the actual message type has been provided via comms::option::def::MsgType.
 
static constexpr bool hasName ()
 Compile type inquiry whether message interface class defines name() and nameImpl() member functions.
 
static constexpr bool hasPolymorphicDispatch ()
 Compile time inquiry of whether polymoriphic dispatch has been requested via interface options and hasn't been inhibited by the comms::option::app::NoDispatchImpl.
 
static constexpr bool hasPolymorphicLength ()
 Compile time inquiry of whether polymoriphic length has been requested via interface options and hasn't been inhibited by the comms::option::app::NoLengthImpl.
 
static constexpr bool hasPolymorphicRead ()
 Compile time inquiry of whether polymoriphic read has been requested via interface options and hasn't been inhibited by the comms::option::app::NoReadImpl.
 
static constexpr bool hasPolymorphicValid ()
 Compile time inquiry of whether polymoriphic validity check has been requested via interface options and hasn't been inhibited by the comms::option::app::NoValidImpl.
 
static constexpr bool hasPolymorphicWrite ()
 Compile time inquiry of whether polymoriphic write has been requested via interface options and hasn't been inhibited by the comms::option::app::NoWriteImpl.
 
static constexpr bool hasRead ()
 Compile type inquiry whether message interface class defines read() and readImpl() member functions as well as ReadIterator type.
 
static constexpr bool hasRefresh ()
 Compile type inquiry whether message interface class defines refresh() and refreshImpl() member functions.
 
static constexpr bool hasStaticMsgId ()
 Compile type inquiry whether static numeric id has been provided via comms::option::def::StaticNumIdImpl.
 
static constexpr bool hasTransportFields ()
 Compile type inquiry whether message interface class defines transportFields() member functions as well as TransportFields type.
 
static constexpr bool hasValid ()
 Compile type inquiry whether message interface class defines valid() and validImpl() member functions.
 
static constexpr bool hasVersionInTransportFields ()
 Compile type inquiry whether there is version information inside transport fields.
 
static constexpr bool hasWrite ()
 Compile type inquiry whether message interface class defines write() and writeImpl() member functions as well as WriteIterator type.
 
static constexpr std::intmax_t staticMsgId ()
 Compile time retrieval of the message id provided via comms::option::def::StaticNumIdImpl. More...
 
static constexpr std::size_t versionIdxInTransportFields ()
 Compile type inquiry of version field index in transport field. More...
 

Protected Member Functions

virtual DispatchRetType dispatchImpl (Handler &handler) override
 Implementation of dispatch functionality. More...
 
ErrorStatus doReadFrom (TIter &iter, std::size_t len)
 Helper function that allows to read only limited number of fields. More...
 
ErrorStatus doReadFromAndUpdateLen (TIter &iter, std::size_t &len)
 Same as doReadFrom(), but modifies length parameter. More...
 
ErrorStatus doReadFromUntil (TIter &iter, std::size_t len)
 Helper function that allows to read only limited number of fields. More...
 
ErrorStatus doReadFromUntilAndUpdateLen (TIter &iter, std::size_t &len)
 Same as doReadFromUntil(), but modifies length parameter. More...
 
void doReadNoStatusFrom (TIter &iter)
 Helper function that allows to read only limited number of fields. More...
 
void doReadNoStatusFromUntil (TIter &iter)
 Helper function that allows to read only limited number of fields. More...
 
void doReadNoStatusUntil (TIter &iter)
 Helper function that allows to read only limited number of fields. More...
 
ErrorStatus doReadUntil (TIter &iter, std::size_t &len)
 Helper function that allows to read only limited number of fields. More...
 
ErrorStatus doReadUntilAndUpdateLen (TIter &iter, std::size_t &len)
 Same as doReadUntil(), but updating length parameter. More...
 
ErrorStatus doWriteFrom (TIter &iter, std::size_t len) const
 Helper function that allows to write only limited number of fields. More...
 
ErrorStatus doWriteFromAndUpdateLen (TIter &iter, std::size_t &len) const
 Same as doWriteFrom(), but modifies length parameter.
 
ErrorStatus doWriteFromUntil (TIter &iter, std::size_t len) const
 Helper function that allows to write only limited number of fields. More...
 
ErrorStatus doWriteFromUntilAndUpdateLen (TIter &iter, std::size_t &len) const
 Same as doWriteNoStatusFrom(), but updates length information.
 
void doWriteNoStatusFrom (TIter &iter) const
 Helper function that allows to write only limited number of fields. More...
 
void doWriteNoStatusFromUntil (TIter &iter) const
 Helper function that allows to write only limited number of fields. More...
 
void doWriteNoStatusUntil (TIter &iter) const
 Helper function that allows to write only limited number of fields. More...
 
ErrorStatus doWriteUntil (TIter &iter, std::size_t len) const
 Helper function that allows to write only limited number of fields. More...
 
ErrorStatus doWriteUntilAndUpdateLen (TIter &iter, std::size_t &len) const
 Same as doWriteUntil(), but modifies length parameter.
 
virtual MsgIdParamType getIdImpl () const override
 Implementation of ID retrieval functionality. More...
 
virtual std::size_t lengthImpl () const override
 Implementation of polymorphic length calculation functionality. More...
 
virtual const char * nameImpl () const override
 Implementation of polymorphic name retrieval functionality. More...
 
virtual ErrorStatus readImpl (ReadIterator &iter, std::size_t size) override
 Implementation of polymorphic read functionality. More...
 
virtual bool refreshImpl () override
 Implementation of polymorphic refresh functionality. More...
 
virtual bool validImpl () const override
 Implementation of polymorphic validity check functionality. More...
 
virtual ErrorStatus writeImpl (WriteIterator &iter, std::size_t size) const override
 Implementation of polymorphic write functionality. More...
 

Static Protected Member Functions

template<typename T , typename TIter >
static T readData (TIter &iter)
 Read data from input area. More...
 
template<typename T , std::size_t TSize, typename TIter >
static T readData (TIter &iter)
 Read partial data from input area. More...
 
template<typename T , typename TIter >
static void writeData (T value, TIter &iter)
 Write data into the output area. More...
 
template<std::size_t TSize, typename T , typename TIter >
static void writeData (T value, TIter &iter)
 Write partial data into the output area. More...
 

Related Functions

(Note that these are not member functions.)

#define COMMS_MSG_FIELD_ALIAS(f_, ...)
 Generate convinience alias types and access member functions for other member fields. More...
 
#define COMMS_MSG_FIELD_ALIAS_ACCESS(f_, ...)
 Generate convinience alias access member functions for other member fields. More...
 
#define COMMS_MSG_FIELDS_ACCESS(...)
 Add convenience access enum and functions to message fields. More...
 
#define COMMS_MSG_FIELDS_NAMES(...)
 Provide names for message fields. More...
 
#define COMMS_MSG_TRANSPORT_FIELD_ALIAS(f_, ...)
 Generate convinience alias access member functions for extra member transport fields. More...
 
#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_, ...)   COMMS_EXPAND(COMMS_DO_ALIAS(transportField_, f_, __VA_ARGS__))
 Generate convinience alias access member functions for extra member transport fields. More...
 
#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS(...)
 Add convenience access enum and functions to extra transport fields. More...
 
#define COMMS_MSG_TRANSPORT_FIELDS_NAMES(...)
 Provide names for extra transport fields. More...
 
bool operator!= (const MessageBase< TMessage1, TOptions... > &msg1, const MessageBase< TMessage2, TOptions... > &msg2) noexcept
 Message object inequality comparison operator. More...
 
bool operator== (const MessageBase< TMessage1, TOptions... > &msg1, const MessageBase< TMessage2, TOptions... > &msg2) noexcept
 Message object equality comparison operator. More...
 

Member Typedef Documentation

◆ AllFields

using comms::MessageBase< TMessage, TOptions >::AllFields = FieldsProvidedWithOption
inherited

All field classes provided with comms::option::def::FieldsImpl option.

The type is not defined if comms::option::def::FieldsImpl option wasn't provided to comms::MessageBase.

◆ DispatchRetType

template<typename... TOptions>
using comms::Message< TOptions >::DispatchRetType = typename Handler::RetType
inherited

Return type of the dispatch() member function.

Equal to Handler::RetType if such exists, void otherwise.

◆ Endian

template<typename... TOptions>
using comms::Message< TOptions >::Endian = typename BaseImpl::Endian
inherited

Serialisation endian type.

The type exists only if comms::option::def::BigEndian or comms::option::def::LittleEndian options were used to specify it.

See also
hasEndian()

◆ Field

template<typename... TOptions>
using comms::Message< TOptions >::Field = BaseImpl::Field
inherited

Type of default base class for all the fields.

Requires definition of the Endian type, i.e. the type exist only if comms::option::def::BigEndian or comms::option::def::LittleEndian options were used.

◆ Handler

template<typename... TOptions>
using comms::Message< TOptions >::Handler = TypeProvidedWithOption
inherited

Type of the message handler object.

The type exists only if comms::option::app::Handler option was provided to comms::Message to specify one.

◆ ImplOptions

using comms::MessageBase< TMessage, TOptions >::ImplOptions = details::MessageImplOptionsParser<TOptions...>
inherited

All the options provided to this class bundled into struct.

For internal use only

◆ InterfaceOptions

template<typename... TOptions>
using comms::Message< TOptions >::InterfaceOptions = details::MessageInterfaceOptionsParser<TOptions...>
inherited

All the options bundled into struct.

For internal use only.

◆ MsgIdParamType

template<typename TMessage , typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
using comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::MsgIdParamType = typename Base::MsgIdParamType

Type of the message ID passed as parameter.

The same as comms::Message::MsgIdParamType;

◆ MsgIdType

template<typename TMessage , typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
using comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::MsgIdType = typename Base::MsgIdType

Type of the message ID.

The same as comms::Message::MsgIdType;

◆ MsgType

using comms::MessageBase< TMessage, TOptions >::MsgType = typename ImplOptions::MsgType
inherited

Type of the actual message provided via comms::option::def::MsgType.

If comms::option::def::MsgType hasn't been used equals to void.

◆ ReadIterator

template<typename... TOptions>
using comms::Message< TOptions >::ReadIterator = TypeProvidedWithOption
inherited

Type of the iterator used for reading message contents from sequence of bytes stored somewhere.

The type exists only if comms::option::app::ReadIterator option was provided to comms::Message to specify one.

See also
hasRead()

◆ TransportFields

template<typename... TOptions>
using comms::Message< TOptions >::TransportFields = FieldsProvidedWithOption
inherited

std::tuple of extra fields from transport layers that may affect the way the message fields get serialized / deserialized.

The type exists only if comms::option::def::ExtraTransportFields option has been provided to comms::Message class to specify them.

See also
hasTransportFields()

◆ VersionType

template<typename... TOptions>
using comms::Message< TOptions >::VersionType = typename BaseImpl::VersionType
inherited

Type used for version info.

The type exists only if comms::option::def::VersionInExtraTransportFields option has been provided.

◆ WriteIterator

template<typename... TOptions>
using comms::Message< TOptions >::WriteIterator = TypeProvidedWithOption
inherited

Type of the iterator used for writing message contents into sequence of bytes stored somewhere.

The type exists only if comms::option::app::WriteIterator option was provided to comms::Message to specify one.

See also
hasWrite()

Constructor & Destructor Documentation

◆ GenericMessage()

template<typename TMessage , typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::GenericMessage ( MsgIdParamType  id)
explicit

Constructor.

Parameters
[in]idID of the message

Member Function Documentation

◆ areFieldsVersionDependent()

static constexpr bool comms::MessageBase< TMessage, TOptions >::areFieldsVersionDependent ( )
staticconstexprinherited

Compile time check of whether the message fields are version dependent.

The function doesn't exist if comms::option::def::FieldsImpl option wasn't provided to comms::MessageBase.

Returns
true if at least one of the fields is version dependent.

◆ COMMS_MSG_FIELDS_NAMES()

template<typename TMessage , typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::COMMS_MSG_FIELDS_NAMES ( data  )

Allow access to internal fields.

See definition of COMMS_MSG_FIELDS_NAMES() macro related to comms::MessageBase class for details.

◆ dispatch()

template<typename... TOptions>
DispatchRetType comms::Message< TOptions >::dispatch ( Handler handler)
inherited

Dispatch message to the handler for processing.

The function exists only if comms::option::app::Handler option was provided to comms::Message to specify type of the handler. The function invokes virtual dispatchImpl() function.

Parameters
handlerHandler object to dispatch message to.

◆ dispatchImpl()

virtual DispatchRetType comms::MessageBase< TMessage, TOptions >::dispatchImpl ( Handler handler)
overrideprotectedvirtualinherited

Implementation of dispatch functionality.

This function exists only if the following conditions are true:

In order to properly implement the dispatch functionality this class imposes several requirements. First of all, the custom message class must provide its own type as an argument to comms::option::def::MsgType option:

class MyMessageBase : public comms::Message<...> { ...};
class Message1 :
MyMessageBase,
...
comms::option::def::MsgType<Message1>
...
>
{
...
};
Base class for all the custom protocol messages.
Definition: MessageBase.h:83
Main interface class for all the messages.
Definition: Message.h:80

Second, The Handler type (inherited from comms::Message) must implement "handle()" member function for every message type (specified as Message1, Message2, ...) it is supposed to handle:

class MyHandler {
public:
DispatchRetType handle(Message1& msg);
DispatchRetType handle(Message2& msg);
...
}
typename Handler::RetType DispatchRetType
Return type of the dispatch() member function.
Definition: Message.h:311

The "handle()" functions may be virtual. If the handler is capable of handling only limited number of messages, there is a need to provide additional "handle()" member function to implement default handling functionality (usually ignore the message by doing nothing) for all other messages that weren't handled explicitly.

class MyHandler {
public:
...
DispatchRetType handle(MessageBase& msg);
}

Where "MessageBase" is a common base class for all the possible messages.

Once the requirements above are properly implemented, the implementation of this message is very simple:

{
typedef <actual-message-type-provided-with-option> Actual;
return handler.handle(static_cast<Actual&>(*this));
}
TypeProvidedWithOption Handler
Type of the message handler object.
Definition: Message.h:307

The code above forces a compiler to choose appropriate handle() function in the Handler class, based on the actual type of the message. If such function is not found, the compiler will choose to call the one that covers all possible messages "void handle(MessageBase& msg)".

Parameters
handlerReference to handler object.

Reimplemented from comms::Message< TOptions >.

◆ doFieldsVersionUpdate()

bool comms::MessageBase< TMessage, TOptions >::doFieldsVersionUpdate ( )
inherited

Update version information of all the fields.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase and comms::option::def::VersionInExtraTransportFields was provided to the message interface class (comms::Message).
This function will invoke such setVersion() member function for every field object listed with comms::option::def::FieldsImpl option and will return true if at least one of the invoked functions returned true (similar to doRefresh()).

Returns
true when at least one of the fields has been updated.

◆ doGetId() [1/2]

static constexpr MsgIdParamType comms::MessageBase< TMessage, TOptions >::doGetId ( )
staticconstexprinherited

Default implementation of ID retrieval functionality.

This function exists only if comms::option::def::StaticNumIdImpl option was provided to comms::MessageBase.

Returns
Numeric ID of the message.

◆ doGetId() [2/2]

template<typename TMessage , typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
MsgIdParamType comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::doGetId ( ) const

Get message ID information.

The comms::MessageBase::getIdImpl() will invoke this function.

◆ doLength()

std::size_t comms::MessageBase< TMessage, TOptions >::doLength ( ) const
inherited

Default implementation of length calculation functionality.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. To make this function works, every field class must provide "length()" function with following signature:

std::size_t length() const;
std::size_t length() const
Get number of bytes required to serialise this message.

This function will invoke such "length()" member function for every field object listed with comms::option::def::FieldsImpl option. The final result is a summary of the "length" values of all the fields.

Returns
Serialisation length of the message.

◆ doLengthFrom()

std::size_t comms::MessageBase< TMessage, TOptions >::doLengthFrom ( ) const
inherited

Default implementation of partial length calculation functionality.

Similar to length() member function but starts the calculation at the the field specified using TFromIdx template parameter.

Template Parameters
TFromIdxIndex of the field, from which length calculation will start
Returns
Calculated serialisation length
Precondition
TFromIdx < std::tuple_size<AllFields>::value

◆ doLengthFromUntil()

std::size_t comms::MessageBase< TMessage, TOptions >::doLengthFromUntil ( ) const
inherited

Default implementation of partial length calculation functionality.

Similar to length() member function but starts the calculation at the the field specified using TFromIdx template parameter, and stops the calculation at the the field specified using TUntilIdx template parameter.

Template Parameters
TFromIdxIndex of the field, from which length calculation will start
TUntilIdxIndex of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account.
Returns
Calculated serialisation length
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doLengthUntil()

std::size_t comms::MessageBase< TMessage, TOptions >::doLengthUntil ( ) const
inherited

Default implementation of partial length calculation functionality.

Similar to length() member function but stops the calculation at the the field specified using TUntilIdx template parameter.

Template Parameters
TUntilIdxIndex of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account.
Returns
Calculated serialisation length
Precondition
TUntilIdx <= std::tuple_size<AllFields>::value

◆ doMaxLength()

static constexpr std::size_t comms::MessageBase< TMessage, TOptions >::doMaxLength ( )
staticconstexprinherited

Compile time constant of maximal serialisation length.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. To make this function works, every field class must provide "maxLength()" function with following signature:

static constexpr std::size_t maxLength();
Returns
Minimal serialisation length of the message.

◆ doMaxLengthFrom()

static constexpr std::size_t comms::MessageBase< TMessage, TOptions >::doMaxLengthFrom ( )
staticconstexprinherited

Compile time constant of maximal partial serialisation length.

Similar to doMaxLength() member function but starts the calculation at the the field specified using TFromIdx template parameter.

Template Parameters
TFromIdxIndex of the field, from which length calculation will start
Returns
Calculated minimal serialisation length
Precondition
TFromIdx < std::tuple_size<AllFields>::value

◆ doMaxLengthFromUntil()

std::size_t comms::MessageBase< TMessage, TOptions >::doMaxLengthFromUntil ( ) const
inherited

Compile time constant of maximal partial serialisation length.

Similar to doMaxLength() member function but starts the calculation at the the field specified using TFromIdx template parameter, and stops the calculation at the the field specified using TUntilIdx template parameter.

Template Parameters
TFromIdxIndex of the field, from which length calculation will start
TUntilIdxIndex of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account.
Returns
Calculated minimal serialisation length
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doMaxLengthUntil()

static constexpr std::size_t comms::MessageBase< TMessage, TOptions >::doMaxLengthUntil ( )
staticconstexprinherited

Compile time constant of maximal partial serialisation length.

Similar to doMaxLength() member function but stops the calculation at the the field specified using TUntilIdx template parameter.

Template Parameters
TUntilIdxIndex of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account.
Returns
Calculated minimal serialisation length
Precondition
TUntilIdx <= std::tuple_size<AllFields>::value

◆ doMinLength()

static constexpr std::size_t comms::MessageBase< TMessage, TOptions >::doMinLength ( )
staticconstexprinherited

Compile time constant of minimal serialisation length.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. To make this function works, every field class must provide "minLength()" function with following signature:

static constexpr std::size_t minLength();
Returns
Minimal serialisation length of the message.

◆ doMinLengthFrom()

static constexpr std::size_t comms::MessageBase< TMessage, TOptions >::doMinLengthFrom ( )
staticconstexprinherited

Compile time constant of minimal partial serialisation length.

Similar to doMinLength() member function but starts the calculation at the the field specified using TFromIdx template parameter.

Template Parameters
TFromIdxIndex of the field, from which length calculation will start
Returns
Calculated minimal serialisation length
Precondition
TFromIdx < std::tuple_size<AllFields>::value

◆ doMinLengthFromUntil()

std::size_t comms::MessageBase< TMessage, TOptions >::doMinLengthFromUntil ( ) const
inherited

Compile time constant of minimal partial serialisation length.

Similar to doMinLength() member function but starts the calculation at the the field specified using TFromIdx template parameter, and stops the calculation at the the field specified using TUntilIdx template parameter.

Template Parameters
TFromIdxIndex of the field, from which length calculation will start
TUntilIdxIndex of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account.
Returns
Calculated minimal serialisation length
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doMinLengthUntil()

static constexpr std::size_t comms::MessageBase< TMessage, TOptions >::doMinLengthUntil ( )
staticconstexprinherited

Compile time constant of minimal partial serialisation length.

Similar to doMinLength() member function but stops the calculation at the the field specified using TUntilIdx template parameter.

Template Parameters
TUntilIdxIndex of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account.
Returns
Calculated minimal serialisation length
Precondition
TUntilIdx <= std::tuple_size<AllFields>::value

◆ doName()

template<typename TMessage , typename TFieldOpts = comms::option::app::EmptyOption, typename TExtraOpts = comms::option::app::EmptyOption>
static const char* comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::doName ( )
static

Get message name information.

The comms::MessageBase::nameImpl() will invoke this function.

◆ doRead()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doRead ( TIter &  iter,
std::size_t  size 
)
inherited

Default implementation of read functionality.

This function exists only if comms::option::def::FieldsImpl option was provided to comms::MessageBase.
To make this function works, every field class must provide "read" function with following signature:

template <typename TIter>
ErrorStatus read(TIter& iter, std::size_t size);
ErrorStatus read(ReadIterator &iter, std::size_t size)
Read message contents using provided iterator.
ErrorStatus
Error statuses reported by the Communication module.
Definition: ErrorStatus.h:17

This function will invoke such "read()" member function for every field object listed with comms::option::def::FieldsImpl option. If any field doesn't report ErrorStatus::Success, then read operation stops, i.e. the provided iterator is not advanced any more.

Template Parameters
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
[in]sizeMaximum number of bytes that can be read.
Returns
Status of the operation.

◆ doReadFrom()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doReadFrom ( TIter &  iter,
std::size_t  len 
)
protectedinherited

Helper function that allows to read only limited number of fields.

Sometimes the default implementation of doRead() is incorrect. For example, some bit in specific field specifies whether other field exists or must be skipped. In this case the derived class must implement different read functionality. To help in such task doReadUntil() function allows to read fields up to a specified one, while this function provides an ability to resume reading from some other field in the middle. The overriding doRead() function in the custom message definition class may use this function for such task. This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. The requirements from field classes is the same as explained in doRead() documentation.

Template Parameters
TIdxZero based index of the field to read from. The function reads all the fields between the one indexed TIdx (included) and the last one (also included).
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
[in]lenMaximum number of bytes that can be read.
Returns
Status of the operation.
Precondition
TIdx < std::tuple_size<AllFields>::value

◆ doReadFromAndUpdateLen()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doReadFromAndUpdateLen ( TIter &  iter,
std::size_t &  len 
)
protectedinherited

Same as doReadFrom(), but modifies length parameter.

Parameters
[in,out]iterIterator used for reading the data.
[in,out]lenMaximum number of bytes that can be read.

◆ doReadFromUntil()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doReadFromUntil ( TIter &  iter,
std::size_t  len 
)
protectedinherited

Helper function that allows to read only limited number of fields.

Sometimes the default implementation of doRead() is incorrect. For example, some bit in specific field specifies whether other fields exist or must be skipped. In this case the derived class must implement different read functionality. In similar way to doReadFrom() and doReadUntil() this function provides an ability to read any number of fields. This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. The requirements from field classes is the same as explained in doRead() documentation.

Template Parameters
TFromIdxZero based index of the field to read from.
TUntilIdxZero based index of the field to read until (not included).
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
[in]lenMaximum number of bytes that can be read.
Returns
Status of the operation.
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doReadFromUntilAndUpdateLen()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doReadFromUntilAndUpdateLen ( TIter &  iter,
std::size_t &  len 
)
protectedinherited

Same as doReadFromUntil(), but modifies length parameter.

Parameters
[in,out]iterIterator used for reading the data.
[in,out]lenMaximum number of bytes that can be read.

◆ doReadNoStatusFrom()

void comms::MessageBase< TMessage, TOptions >::doReadNoStatusFrom ( TIter &  iter)
protectedinherited

Helper function that allows to read only limited number of fields.

Similar to doReadFrom(), but doesn't check for errors and doesn't report status. This function can be used instead of doReadFrom() when correction of the read operation was ensured by other means prior to its invocation.

Template Parameters
TIdxZero based index of the field to read from. The function reads all the fields between the one indexed TIdx (included) and the last one (also included).
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
Precondition
TIdx < std::tuple_size<AllFields>::value

◆ doReadNoStatusFromUntil()

void comms::MessageBase< TMessage, TOptions >::doReadNoStatusFromUntil ( TIter &  iter)
protectedinherited

Helper function that allows to read only limited number of fields.

Similar to doReadFromUntil(), but doesn't check for errors and doesn't report status. This function can be used instead of doReadFromUntil() when correction of the read operation was ensured by other means prior to its invocation.

Template Parameters
TFromIdxZero based index of the field to read from.
TUntilIdxZero based index of the field to read until (not included).
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doReadNoStatusUntil()

void comms::MessageBase< TMessage, TOptions >::doReadNoStatusUntil ( TIter &  iter)
protectedinherited

Helper function that allows to read only limited number of fields.

Similar to doReadUntil(), but doesn't check for errors and doesn't report status. This function can be used instead of doReadUntil() when correction of the read operation was ensured by other means prior to its invocation.

Template Parameters
TIdxZero based index of the field to read until. The function returns when field with index "TIdx - 1" (if such exists) has been read, while field with index "TIdx" still hasn't.
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
Precondition
TIdx <= std::tuple_size<AllFields>::value

◆ doReadUntil()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doReadUntil ( TIter &  iter,
std::size_t &  len 
)
protectedinherited

Helper function that allows to read only limited number of fields.

Sometimes the default implementation of doRead() is incorrect. For example, some bit in specific field specifies whether other field exists or must be skipped. In this case the derived class must implement different read functionality. To help in such task this function provides an ability to read all the fields up to (not including) requested field. The overriding doRead() function in the custom message definition class may use this function for such task. This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. The requirements from field classes is the same as explained in doRead() documentation.

Template Parameters
TIdxZero based index of the field to read until. The function returns when field with index "TIdx - 1" (if such exists) has been read, while field with index "TIdx" still hasn't.
TIterType of the iterator used for reading.
Parameters
[in,out]iterIterator used for reading the data.
[in]lenMaximum number of bytes that can be read.
Returns
Status of the operation.
Precondition
TIdx <= std::tuple_size<AllFields>::value

◆ doReadUntilAndUpdateLen()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doReadUntilAndUpdateLen ( TIter &  iter,
std::size_t &  len 
)
protectedinherited

Same as doReadUntil(), but updating length parameter.

Parameters
[in,out]iterIterator used for reading the data.
[in,out]lenMaximum number of bytes that can be read.

◆ doRefresh()

bool comms::MessageBase< TMessage, TOptions >::doRefresh ( ) const
inherited

Default implementation of refreshing functionality.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. To make this function works, every field class must provide "refresh()" function with following signature:

bool refresh() const;
bool refresh()
Refresh to contents of the message.

This function will invoke such "refresh()" member function for every field object listed with comms::option::def::FieldsImpl option and will return true if at least one of the invoked functions returned true.

Returns
true when at least one of the fields has been updated.

◆ doValid()

bool comms::MessageBase< TMessage, TOptions >::doValid ( ) const
inherited

Default implementation of validity check functionality.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. To make this function works, every field class must provide "valid()" function with following signature:

bool valid() const;
bool valid() const
Check validity of message contents.

This function will invoke such "valid()" member function for every field object listed with comms::option::def::FieldsImpl option.

Returns
true when all fields are valid.

◆ doWrite()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doWrite ( TIter &  iter,
std::size_t  size 
) const
inherited

Default implementation of write functionality.

This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase.
To make this function works, every field class must provide "write" function with following signature:

template <typename TIter>
ErrorStatus write(TIter& iter, std::size_t size) const;
ErrorStatus write(WriteIterator &iter, std::size_t size) const
Write message contents using provided iterator.

This function will invoke such "write()" member function for every field object listed with comms::option::def::FieldsImpl option. If any field doesn't report ErrorStatus::Success, then write operation stops, i.e. the provided iterator is not advanced any more.

Template Parameters
TIterType of the iterator used for writing.
Parameters
[in,out]iterIterator used for writing the data.
[in]sizeMaximum number of bytes that can be written.
Returns
Status of the operation.

◆ doWriteFrom()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doWriteFrom ( TIter &  iter,
std::size_t  len 
) const
protectedinherited

Helper function that allows to write only limited number of fields.

In a similar way to doReadFrom(), this function allows writing limited number of fields starting from the requested one until the end. This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. The requirements from field classes is the same as explained in doWrite() documentation.

Template Parameters
TIdxZero based index of the field to write from.
TIterType of iterator used for writing.
Parameters
[in,out]iterIterator used for writing the data.
[in]lenMaximum number of bytes that can be written.
Returns
Status of the operation.
Precondition
TIdx < std::tuple_size<AllFields>::value

◆ doWriteFromUntil()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doWriteFromUntil ( TIter &  iter,
std::size_t  len 
) const
protectedinherited

Helper function that allows to write only limited number of fields.

In a similar way to doReadFromUntil(), this function allows writing limited number of fields between the requested indices. This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. The requirements from field classes is the same as explained in doWrite() documentation.

Template Parameters
TFromIdxZero based index of the field to write from.
TUntilIdxZero based index of the field to write until (not including).
TIterType of iterator used for writing.
Parameters
[in,out]iterIterator used for writing the data.
[in]lenMaximum number of bytes that can be written.
Returns
Status of the operation.
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doWriteNoStatusFrom()

void comms::MessageBase< TMessage, TOptions >::doWriteNoStatusFrom ( TIter &  iter) const
protectedinherited

Helper function that allows to write only limited number of fields.

Similar to doWriteFrom(), but doesn't check for errors and doesn't report status. This function can be used instead of doWriteFrom() when correction of the write operation was ensured by other means prior to its invocation.

Template Parameters
TIdxZero based index of the field to write from.
TIterType of the iterator used for writing.
Parameters
[in,out]iterIterator used for reading the data.
Precondition
TIdx < std::tuple_size<AllFields>::value

◆ doWriteNoStatusFromUntil()

void comms::MessageBase< TMessage, TOptions >::doWriteNoStatusFromUntil ( TIter &  iter) const
protectedinherited

Helper function that allows to write only limited number of fields.

Similar to doWriteFromUntil(), but doesn't check for errors and doesn't report status. This function can be used instead of doWriteFromUntil() when correction of the write operation was ensured by other means prior to its invocation.

Template Parameters
TFromIdxZero based index of the field to write from.
TUntilIdxZero based index of the field to write until (not including).
TIterType of iterator used for writing.
Parameters
[in,out]iterIterator used for reading the data.
Precondition
TFromIdx < std::tuple_size<AllFields>::value
TUntilIdx <= std::tuple_size<AllFields>::value
TFromIdx < TUntilIdx

◆ doWriteNoStatusUntil()

void comms::MessageBase< TMessage, TOptions >::doWriteNoStatusUntil ( TIter &  iter) const
protectedinherited

Helper function that allows to write only limited number of fields.

Similar to doWriteUntil(), but doesn't check for errors and doesn't report status. This function can be used instead of doWriteUntil() when correction of the write operation was ensured by other means prior to its invocation.

Template Parameters
TIdxZero based index of the field to write until. The function returns when field with index "TIdx - 1" (if such exists) has been written, while field with index "TIdx" still hasn't.
TIterType of the iterator used for writing.
Parameters
[in,out]iterIterator used for reading the data.
Precondition
TIdx <= std::tuple_size<AllFields>::value

◆ doWriteUntil()

ErrorStatus comms::MessageBase< TMessage, TOptions >::doWriteUntil ( TIter &  iter,
std::size_t  len 
) const
protectedinherited

Helper function that allows to write only limited number of fields.

In a similar way to doReadUntil(), this function allows writing limited number of fields starting from the first one. This function exists only if comms::option::def::FieldsImpl or comms::option::def::ZeroFieldsImpl option was provided to comms::MessageBase. The requirements from field classes is the same as explained in doWrite() documentation.

Template Parameters
TIdxZero based index of the field to write until. The function returns when field with index "TIdx - 1" (if such exists) has been written, while field with index "TIdx" still hasn't.
TIterType of iterator used for writing.
Parameters
[in,out]iterIterator used for writing the data.
[in]lenMaximum number of bytes that can be written.
Returns
Status of the operation.
Precondition
TIdx <= std::tuple_size<AllFields>::value

◆ fields() [1/2]

AllFields& comms::MessageBase< TMessage, TOptions >::fields ( )
inherited

Get an access to the fields of the message.

The function doesn't exist if comms::option::def::FieldsImpl option wasn't provided to comms::MessageBase.

Returns
Reference to the fields of the message.

◆ fields() [2/2]

const AllFields& comms::MessageBase< TMessage, TOptions >::fields ( ) const
inherited

Get an access to the fields of the message.

The function doesn't exist if comms::option::def::FieldsImpl option wasn't provided to comms::MessageBase.

Returns
Const reference to the fields of the message.

◆ getId()

template<typename... TOptions>
MsgIdParamType comms::Message< TOptions >::getId ( ) const
inherited

Retrieve ID of the message.

Invokes pure virtual getIdImpl(). This function exists only if comms::option::def::MsgIdType option was used to specify type of the ID value and comms::option::app::IdInfoInterface option are used.

Returns
ID of the message.
See also
hasGetId();

◆ getIdImpl()

virtual MsgIdParamType comms::MessageBase< TMessage, TOptions >::getIdImpl ( ) const
overrideprotectedvirtualinherited

Implementation of ID retrieval functionality.

This function may exist only if ID retrieval is possible, i.e. the ID type has been privded to comms::Message using comms::option::def::MsgIdType option and the polymorphic ID retrieval functionality was requested (using comms::option::app::IdInfoInterface). In addition to the conditions listed earlier this function is provided if local doGetId() function was generated. If not, it may still be provided if the derived class is known (comms::option::def::MsgType option was used) and the comms::option::def::HasDoGetId option is used to declare the derived type having doGetId() member function defined.

Returns
ID value passed as template parameter to comms::option::def::StaticNumIdImpl option.

Implements comms::Message< TOptions >.

◆ length()

template<typename... TOptions>
std::size_t comms::Message< TOptions >::length ( ) const
inherited

Get number of bytes required to serialise this message.

The function exists only if comms::option::app::LengthInfoInterface option was provided to comms::Message. The function invokes virtual lengthImpl() function.

Returns
Number of bytes required to serialise this message.
See also
hasLength()

◆ lengthImpl()

virtual std::size_t comms::MessageBase< TMessage, TOptions >::lengthImpl ( ) const
overrideprotectedvirtualinherited

Implementation of polymorphic length calculation functionality.

This function exists if comms::option::app::LengthInfoInterface option was provided to comms::Message class when specifying interface, and comms::option::app::NoLengthImpl option was NOT used to inhibit the implementation.
If comms::option::def::MsgType option was used to specify the actual type of the message, and if it contains custom doLength() function, it will be invoked. Otherwise, the invocation of comms::MessageBase::doLength() will be chosen in case fields were specified using comms::option::def::FieldsImpl option.

Returns
Serialisation length of the message.

Reimplemented from comms::Message< TOptions >.

◆ name()

template<typename... TOptions>
const char* comms::Message< TOptions >::name ( ) const
inherited

Get name of the message.

The function exists only if comms::option::app::NameInterface option was provided to comms::Message. The function invokes virtual nameImpl() function.

See also
hasName()

◆ nameImpl()

virtual const char* comms::MessageBase< TMessage, TOptions >::nameImpl ( ) const
overrideprotectedvirtualinherited

Implementation of polymorphic name retrieval functionality.

This function exists if comms::option::app::NameInterface option was provided to comms::Message class when specifying interface, and comms::option::def::HasName as well as comms::option::def::MsgType options ware used for this class. This function downcasts this pointer to actual message type and invokes doName() member function.

Returns
true in case fields were updated, false if nothing has changed.

Implements comms::Message< TOptions >.

◆ read()

template<typename... TOptions>
ErrorStatus comms::Message< TOptions >::read ( ReadIterator iter,
std::size_t  size 
)
inherited

Read message contents using provided iterator.

The function exists only if comms::option::app::ReadIterator option was provided to comms::Message to specify type of the ReadIterator. The contents of the message are updated with bytes being read. The buffer is external and maintained by the caller. The provided iterator is advanced. The function invokes virtual readImpl() function.

Parameters
[in,out]iterIterator used for reading the data.
[in]sizeMaximum number of bytes that can be read.
Returns
Status of the operation.
See also
hasRead()

◆ readData() [1/2]

template<typename... TOptions>
template<typename T , typename TIter >
static T comms::Message< TOptions >::readData ( TIter &  iter)
staticprotectedinherited

Read data from input area.

Use this function to read data from the input area using provided iterator. This function requires knowledge about serialisation endian. It exists only if endian type was specified using comms::option::def::BigEndian or comms::option::def::LittleEndian options to the class.

Template Parameters
TReturn type
TIterType of input iterator
Parameters
[in,out]iterInput iterator.
Returns
The integral type value.
Precondition
TSize <= sizeof(T)
The iterator must be valid and can be successfully dereferenced and incremented at least sizeof(T) times.
Postcondition
The iterator is advanced.
Note
Thread safety: Safe for distinct stream buffers, unsafe otherwise.

◆ readData() [2/2]

template<typename... TOptions>
template<typename T , std::size_t TSize, typename TIter >
static T comms::Message< TOptions >::readData ( TIter &  iter)
staticprotectedinherited

Read partial data from input area.

Use this function to read partial data from the input area using provided iterator. This function requires knowledge about serialisation endian. It exists only if endian type was specified using comms::option::def::BigEndian or comms::option::def::LittleEndian options to the class.

Template Parameters
TReturn type
TSizenumber of bytes to read
TIterType of input iterator
Parameters
[in,out]iterInput iterator.
Returns
The integral type value.
Precondition
TSize <= sizeof(T)
The iterator must be valid and can be successfully dereferenced and incremented at least TSize times.
Postcondition
The internal pointer of the stream buffer is advanced.
Note
Thread safety: Safe for distinct stream buffers, unsafe otherwise.

◆ readImpl()

virtual ErrorStatus comms::MessageBase< TMessage, TOptions >::readImpl ( ReadIterator iter,
std::size_t  size 
)
overrideprotectedvirtualinherited

Implementation of polymorphic read functionality.

This function exists if comms::option::app::ReadIterator option was provided to comms::Message class when specifying interface, and comms::option::app::NoReadImpl option was NOT used to inhibit the implementation.
If comms::option::def::MsgType option was used to specify the actual type of the message, and if it contains custom doRead() function, it will be invoked. Otherwise, the invocation of comms::MessageBase::doRead() will be chosen in case fields were specified using comms::option::def::FieldsImpl option.

Parameters
[in,out]iterIterator used for reading the data.
[in]sizeMaximum number of bytes that can be read.
Returns
Status of the operation.

Reimplemented from comms::Message< TOptions >.

◆ refresh()

template<typename... TOptions>
bool comms::Message< TOptions >::refresh ( )
inherited

Refresh to contents of the message.

Many protocols define their messages in a way that the content of some fields may depend on the value of the other field(s). For example, providing in one field the information about number of elements in the list that will follow later. Another example is having bits in a bitmask field specifying whether other optional fields exist. In this case, directly modifying value of some fields may leave a message contents in an inconsistent state. Having refresh() member function allows the developer to bring the message into a consistent state prior to sending it over I/O link .
The function exists only if comms::option::app::RefreshInterface option was provided to comms::Message. The function invokes virtual refreshImpl() function.

Returns
true in case the contents of the message were modified, false if all the fields of the message remained unchanged.

◆ refreshImpl()

virtual bool comms::MessageBase< TMessage, TOptions >::refreshImpl ( )
overrideprotectedvirtualinherited

Implementation of polymorphic refresh functionality.

This function exists if comms::option::app::RefreshInterface option was provided to comms::Message class when specifying interface, and comms::option::def::HasCustomRefresh option was used (either on on of the fields or when defining a message class) to to notify about existence of custom refresh functionality. If comms::option::def::MsgType option was used to specify the actual message class, the this pointer will be downcasted to it to invoke doRefresh() member function defined there. If such is not defined the default doRefresh() member function from this class will be used.

Returns
true in case fields were updated, false if nothing has changed.

Reimplemented from comms::Message< TOptions >.

◆ staticMsgId()

static constexpr std::intmax_t comms::MessageBase< TMessage, TOptions >::staticMsgId ( )
staticconstexprinherited

Compile time retrieval of the message id provided via comms::option::def::StaticNumIdImpl.

If comms::option::def::StaticNumIdImpl hasn't been used, std::numeric_limits<std::intmax_t>::max() is returned.

◆ transportFields() [1/2]

template<typename... TOptions>
TransportFields& comms::Message< TOptions >::transportFields ( )
inherited

Get access to extra transport fields.

The function exists only if comms::option::def::ExtraTransportFields option has been provided to comms::Message class to specify them. Some protocols may use additional values in transport information, such as message version for example. Such values may influence the way message data is being serialized / deserialized. The provided extra transport fields are NOT serialised as part of message payload. Their values are expected to be set by transport layer(s) when such information is read. The transport layers are also responsible to take the updated information from the relevant field and write it when message contents being written.

See also
hasTransportFields()

◆ transportFields() [2/2]

template<typename... TOptions>
const TransportFields& comms::Message< TOptions >::transportFields ( ) const
inherited

Const version of transportFields.

The function exists only if comms::option::def::ExtraTransportFields option has been provided to comms::Message class to specify them.

See also
hasTransportFields()

◆ valid()

template<typename... TOptions>
bool comms::Message< TOptions >::valid ( ) const
inherited

Check validity of message contents.

The function exists only if comms::option::app::ValidCheckInterface option was provided to comms::Message. The function invokes virtual validImpl() function.

Returns
true for valid contents, false otherwise.
See also
hasValid()

◆ validImpl()

virtual bool comms::MessageBase< TMessage, TOptions >::validImpl ( ) const
overrideprotectedvirtualinherited

Implementation of polymorphic validity check functionality.

This function exists if comms::option::app::ValidCheckInterface option was provided to comms::Message class when specifying interface, and comms::option::app::NoValidImpl option was NOT used to inhibit the implementation.
If comms::option::def::MsgType option was used to specify the actual type of the message, and if it contains custom doValid() function, it will be invoked. Otherwise, the invocation of comms::MessageBase::doValid() will be chosen in case fields were specified using comms::option::def::FieldsImpl option.

Reimplemented from comms::Message< TOptions >.

◆ version() [1/2]

template<typename... TOptions>
VersionType& comms::Message< TOptions >::version ( )
inherited

Access to version information.

The function exists only if comms::option::def::VersionInExtraTransportFields option has been provided.

◆ version() [2/2]

template<typename... TOptions>
const VersionType& comms::Message< TOptions >::version ( ) const
inherited

Const access to version information.

The function exists only if comms::option::def::VersionInExtraTransportFields option has been provided.

◆ versionIdxInTransportFields()

template<typename... TOptions>
static constexpr std::size_t comms::Message< TOptions >::versionIdxInTransportFields ( )
staticconstexprinherited

Compile type inquiry of version field index in transport field.

If comms::option::def::VersionInExtraTransportFields option hasn't been used, the std::numeric_limits<std::size_t>::max() is returned.

◆ write()

template<typename... TOptions>
ErrorStatus comms::Message< TOptions >::write ( WriteIterator iter,
std::size_t  size 
) const
inherited

Write message contents using provided iterator.

The function exists only if comms::option::app::WriteIterator option was provided to comms::Message to specify type of the WriteIterator. The contents of the message are serialised into buffer. The buffer is external and is maintained by the caller. The provided iterator is advanced. The function invokes virtual writeImpl() function.

Parameters
[in,out]iterIterator used for writing the data.
[in]sizeMaximum number of bytes that can be written.
Returns
Status of the operation.
See also
hasWrite()

◆ writeData() [1/2]

template<typename... TOptions>
template<typename T , typename TIter >
static void comms::Message< TOptions >::writeData ( value,
TIter &  iter 
)
staticprotectedinherited

Write data into the output area.

Use this function to write data to the output area using provided iterator. This function requires knowledge about serialisation endian. It exists only if endian type was specified using comms::option::def::BigEndian or comms::option::def::LittleEndian options to the class.

Template Parameters
TType of the value to write. Must be integral.
Typeof output iterator
Parameters
[in]valueIntegral type value to be written.
[in,out]iterOutput iterator.
Precondition
The iterator must be valid and can be successfully dereferenced and incremented at least sizeof(T) times.
Postcondition
The iterator is advanced.
Note
Thread safety: Safe for distinct buffers, unsafe otherwise.

◆ writeData() [2/2]

template<typename... TOptions>
template<std::size_t TSize, typename T , typename TIter >
static void comms::Message< TOptions >::writeData ( value,
TIter &  iter 
)
staticprotectedinherited

Write partial data into the output area.

Use this function to write partial data to the output area using provided iterator. This function requires knowledge about serialisation endian. It exists only if endian type was specified using comms::option::def::BigEndian or comms::option::def::LittleEndian options to the class.

Template Parameters
TSizeLength of the value in bytes known in compile time.
TType of the value to write. Must be integral.
TIterType of output iterator
Parameters
[in]valueIntegral type value to be written.
[in,out]iterOutput iterator.
Precondition
TSize <= sizeof(T)
The iterator must be valid and can be successfully dereferenced and incremented at least TSize times.
Postcondition
The iterator is advanced.
Note
Thread safety: Safe for distinct buffers, unsafe otherwise.

◆ writeImpl()

virtual ErrorStatus comms::MessageBase< TMessage, TOptions >::writeImpl ( WriteIterator iter,
std::size_t  size 
) const
overrideprotectedvirtualinherited

Implementation of polymorphic write functionality.

This function exists if comms::option::app::WriteIterator option was provided to comms::Message class when specifying interface, and comms::option::app::NoWriteImpl option was NOT used to inhibit the implementation.
If comms::option::def::MsgType option was used to specify the actual type of the message, and if it contains custom doWrite() function, it will be invoked. Otherwise, the invocation of comms::MessageBase::doWrite() will be chosen in case fields were specified using comms::option::def::FieldsImpl option.

Parameters
[in,out]iterIterator used for writing the data.
[in]sizeMaximum number of bytes that can be written.
Returns
Status of the operation.

Reimplemented from comms::Message< TOptions >.

Friends And Related Function Documentation

◆ COMMS_MSG_FIELD_ALIAS

#define COMMS_MSG_FIELD_ALIAS (   f_,
  ... 
)
related

Generate convinience alias types and access member functions for other member fields.

The COMMS_MSG_FIELDS_NAMES() macro generates inner types and convenience access member functions for member fields. Sometimes the fields may get renamed or moved to be a member of other fields, like comms::field::Bundle or comms::field::Bitfield. In such case the compilation of the existing client code (that already uses published protocol definition) may fail. To avoid such scenarios and make the transition to newer versions of the protocol easier, the COMMS_MSG_FIELD_ALIAS() macro can be used to create alias to other fields. For example, let's assume that some message class was defined: like this.

class Message1 : public comms::MessageBase<...>
{
using Base = comms::MessageBase<...>;
public:
COMMS_MSG_FIELDS_NAMES(name1, name2, name3);
};
COMMS_MSG_FIELDS_NAMES(data)
Allow access to internal fields.

In the future versions of the protocol "name3" was renamed to "newName3". To keep the existing code (that uses "name3" name) compiling it is possible to create an alias access function(s) with:

The usage of COMMS_MSG_FIELD_ALIAS() in the code above is equivalent to having the following functions as well as type defined:

class Message1 : public comms::MessageBase<...>
{
public:
...
using Field_name3 = Field_newName3;
auto field_name3() -> decltype(field_newName3())
{
return field_newName3();
}
auto field_name3() const -> decltype(field_newName3())
{
return field_newName3();
}
};

Another example would be a replacing a comms::field::IntValue with comms::field::Bitfield in the future version of the protocol. It can happen when the developer decides to split the used storage into multiple values (because the range of the used/valid values allows so). In order to keep the old client code compiling, the access to the replaced field needs to be an alias to the first member of the comms::field::Bitfield. In this case the usage of COMMS_MSG_FIELD_ALIAS() will look like this:

class Message1 : public comms::MessageBase<...>
{
using Base = comms::MessageBase<...>;
public:
COMMS_MSG_FIELDS_NAMES(name1, name2, newName3);
COMMS_MSG_FIELD_ALIAS(name3, newName3, member1);
};

The usage of COMMS_MSG_FIELD_ALIAS() in the code above is equivalent to having the following functions defined:

class Message1 : public comms::MessageBase<...>
{
public:
...
using Field_name3 = typename Field_newName3::Field_member1;
auto field_name3() -> decltype(field_newName3().field_member1())
{
return field_newName3().field_member1();
}
auto field_name3() const -> decltype(field_newName3().field_member1())
{
return field_newName3().field_member1();
}
};
Parameters
[in]f_Alias field name.
[in]...List of fields' names.
Precondition
The macro COMMS_MSG_FIELDS_NAMES() needs to be used before COMMS_MSG_FIELD_ALIAS() to define convenience access functions.
See also
COMMS_MSG_FIELD_ALIAS_ACCESS()
Note
Defined in "comms/MessageBase.h"

◆ COMMS_MSG_FIELD_ALIAS_ACCESS

#define COMMS_MSG_FIELD_ALIAS_ACCESS (   f_,
  ... 
)
related

Generate convinience alias access member functions for other member fields.

Similar to COMMS_MSG_FIELD_ALIAS() but requires usage of COMMS_MSG_FIELDS_ACCESS() instead of COMMS_MSG_FIELDS_NAMES() and does NOT create alias to the field type, only access functions.

Parameters
[in]f_Alias field name.
[in]...List of fields' names.
Precondition
The macro COMMS_MSG_FIELDS_ACCESS() needs to be used before COMMS_MSG_FIELD_ALIAS_ACCESS() to define convenience access functions.
Note
Defined in "comms/MessageBase.h"
See also
COMMS_MSG_FIELD_ALIAS()

◆ COMMS_MSG_FIELDS_ACCESS

#define COMMS_MSG_FIELDS_ACCESS (   ...)
related

Add convenience access enum and functions to message fields.

Very similar to COMMS_MSG_FIELDS_NAMES(), but does NOT require definition of Base inner member type (for some compilers) and does NOT define inner Field_* types for used fields.

Parameters
[in]...List of fields' names.
See also
COMMS_MSG_FIELDS_NAMES()
Note
Defined in "comms/MessageBase.h"

◆ COMMS_MSG_FIELDS_NAMES

#define COMMS_MSG_FIELDS_NAMES (   ...)
related

Provide names for message fields.

The comms::MessageBase class provides access to its fields via comms::MessageBase::fields() member function(s). The fields are bundled into std::tuple and can be accessed using indices with std::get. For convenience, the fields should be named. The COMMS_MSG_FIELDS_NAMES() macro does exactly that.
As an example, let's assume that custom message uses 3 fields of any types:

using Field1 = ... /* some field definition */;
using Field2 = ... /* some field definition */;
using Field3 = ... /* some field definition */;
using Message1Fields = std::tuple<Field1, Field2, Field3>;
class Message1 : public
MyInterface,
comms::option::def::FieldsImpl<Message1Fields>,
... /* some other options */>
{
// Base class (re) definition required by COMMS_MSG_FIELDS_NAMES()
using Base =
MyInterface,
... /* some other options */>
public:
// Provide names for message fields
COMMS_MSG_FIELDS_NAMES(name1, name2, name3);
};
Option used to specify fields of the message and force implementation of default read,...
Definition: options.h:234

NOTE that there is a required to have Base member type that specifies base class used. It is needed to be able to access comms::MessageBase::AllFields type definition.

The usage of the COMMS_MSG_FIELDS_NAMES() macro with the list of the field's names is equivalent to having the following definitions inside the message class

class Message1 : public comms::MessageBase<...>
{
using Base = comms::MessageBase<...>;
public:
// Indices of the fields
enum FieldIdx {
FieldIdx_name1,
FieldIdx_name2,
FieldIdx_name3,
FieldIdx_nameOfValues
};
static_assert(std::tuple_size<Base::AllFields>::value == FieldIdx_nameOfValues,
"Number of expected fields is incorrect");
// Accessor to "name1" field.
auto field_name1() -> decltype(std::get<FieldIdx_name1>(Base::fields()))
{
return std::get<FieldIdx_name1>(Base::fields());
}
// Accessor to "name1" field.
auto field_name1() const -> decltype(std::get<FieldIdx_name1>(Base::fields()))
{
return std::get<FieldIdx_name1>(Base::fields());
}
// Accessor to "name2" field.
auto field_name2() -> decltype(std::get<FieldIdx_name2>(Base::fields()))
{
return std::get<FieldIdx_name2>(Base::fields());
}
// Accessor to "name2" field.
auto field_name2() const -> decltype(std::get<FieldIdx_name2>(Base::fields()))
{
return std::get<FieldIdx_name2>(Base::fields());
}
// Accessor to "name3" field.
auto field_name3() -> decltype(std::get<FieldIdx_name3>(Base::fields()))
{
return std::get<FieldIdx_name3>(Base::fields());
}
// Accessor to "name3" field.
auto field_name3() const -> decltype(std::get<FieldIdx_name3>(Base::fields()))
{
return std::get<FieldIdx_name3>(Base::fields());
}
// Redefinition of the field types:
using Field_name1 = Field1;
using Field_name2 = Field2;
using Field_name3 = Field3;
};
AllFields & fields()
Get an access to the fields of the message.

NOTE, that provided names name1, name2, and name3 have found their way to the following definitions:

  • FieldIdx enum. The names are prefixed with FieldIdx_. The FieldIdx_nameOfValues value is automatically added at the end.
  • Accessor functions prefixed with field_*
  • Types of fields prefixed with Field_*

As the result, the fields can be accessed using FieldIdx enum

void handle(Message1& msg)
{
auto& allFields = msg.fields();
auto& field1 = std::get<Message1::FieldIdx_name1>(allFields);
auto& field2 = std::get<Message1::FieldIdx_name2>(allFields);
auto& field3 = std::get<Message1::FieldIdx_name3>(allFields);
auto value1 = field1.value();
auto value2 = field2.value();
auto value3 = field3.value();
}

or using accessor functions:

void handle(Message1& msg)
{
auto value1 = field_name1().value();
auto value2 = field_name2().value();
auto value3 = field_name3().value();
}
Parameters
[in]...List of fields' names.
Precondition
Requires (re)definition of the message base class as inner Base member type.
See also
COMMS_MSG_FIELDS_ACCESS()
Note
Defined in "comms/MessageBase.h"

◆ COMMS_MSG_TRANSPORT_FIELD_ALIAS

template<typename... TOptions>
#define COMMS_MSG_TRANSPORT_FIELD_ALIAS (   f_,
  ... 
)
related
Value:
COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_, __VA_ARGS__)) \
COMMS_EXPAND(COMMS_DO_ALIAS_TYPEDEF(TransportField_, f_, __VA_ARGS__))
#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_,...)
Generate convinience alias access member functions for extra member transport fields.
Definition: Message.h:733

Generate convinience alias access member functions for extra member transport fields.

The COMMS_MSG_TRANSPORT_FIELDS_NAMES() macro generates alias type as well as convenience access member functions for extra transport fields. Sometimes the fields may get renamed or moved to be a member of other fields, like comms::field::Bundle or comms::field::Bitfield. In such case the compilation of the existing client code (that already uses published protocol definition) may fail. To avoid such scenarios and make the transition to newer versions of the protocol easier, the COMMS_MSG_TRANSPORT_FIELD_ALIAS() macro can be used to create alias to other fields. For example, let's assume that some common interface class was defined: like this.

class MyInterface : public comms::Message<...>
{
// (Re)definition of the base class as inner Base type.
using Base = comms::Message<...>;
public:
COMMS_MSG_TRANSPORT_FIELDS_NAMES(name1, name2, name3);
};
#define COMMS_MSG_TRANSPORT_FIELDS_NAMES(...)
Provide names for extra transport fields.
Definition: Message.h:716

In the future versions of the protocol "name3" was renamed to "newName3". To keep the existing code (that uses "name3" name) compiling it is possible to create an alias access function(s) with:

class MyInterface : public public comms::Message<...>
{
using Base = comms::Message<...>;
public:
COMMS_MSG_TRANSPORT_FIELDS_NAMES(name1, name2, newName3);
};
#define COMMS_MSG_TRANSPORT_FIELD_ALIAS(f_,...)
Generate convinience alias access member functions for extra member transport fields.
Definition: Message.h:845

The usage of COMMS_MSG_TRANSPORT_FIELD_ALIAS() in the code above is equivalent to having the following type and functions defined:

class MyInterface : public public comms::Message<...>
{
public:
...
using TransportField_name3 = TransportField_newName3;
auto transportField_name3() -> decltype(transportField_newName3())
{
return transportField_newName3();
}
auto transportField_name3() const -> decltype(transportField_newName3())
{
return transportField_newName3();
}
};

Another example would be a replacing a comms::field::IntValue with comms::field::Bitfield in the future version of the protocol. It can happen when the developer decides to split the used storage into multiple values (because the range of the used/valid values allows so). In order to keep the old client code compiling, the access to the replaced field needs to be an alias to the first member of the comms::field::Bitfield. In this case the usage of COMMS_MSG_TRANSPORT_FIELD_ALIAS() will look like this:

class MyInterface : public public comms::Message<...>
{
using Base = comms::Message<...>;
public:
COMMS_MSG_TRANSPORT_FIELDS_NAMES(name1, name2, newName3);
COMMS_MSG_TRANSPORT_FIELD_ALIAS(name3, newName3, member1);
};

The usage of COMMS_MSG_TRANSPORT_FIELD_ALIAS() in the code above is equivalent to having the following functions defined:

class MyInterface : public public comms::Message<...>
{
public:
...
using TransportField_name3 = TransportField_newName3::Field_Member1;
auto transportField_name3() -> decltype(transportField_newName3().field_member1())
{
return field_newName3().field_member1();
}
auto transportField_name3() const -> decltype(transportField_newName3().field_member1())
{
return transportField_newName3().field_member1();
}
};
Parameters
[in]f_Alias field name.
[in]...List of fields' names.
Precondition
The macro COMMS_MSG_TRANSPORT_FIELDS_NAMES() needs to be used before COMMS_MSG_TRANSPORT_FIELD_ALIAS() to define convenience access functions.
See also
COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS_NOTEMPLATE()
COMMS_MSG_TRANSPORT_FIELD_ALIAS_NOTEMPLATE()
Note
Defined in "comms/Message.h"

◆ COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS

template<typename... TOptions>
#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS (   f_,
  ... 
)    COMMS_EXPAND(COMMS_DO_ALIAS(transportField_, f_, __VA_ARGS__))
related

Generate convinience alias access member functions for extra member transport fields.

Similar to COMMS_MSG_TRANSPORT_FIELD_ALIAS() but requires usage of COMMS_MSG_TRANSPORT_FIELDS_ACCESS() instead of COMMS_MSG_TRANSPORT_FIELDS_NAMES() and does NOT create alias to the field type, only access functions.

Parameters
[in]f_Alias field name.
[in]...List of fields' names.
Precondition
The macro COMMS_MSG_TRANSPORT_FIELDS_ACCESS() needs to be used before COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS() to define convenience access functions.
See also
COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS_NOTEMPLATE()
COMMS_MSG_TRANSPORT_FIELD_ALIAS()
Note
Defined in "comms/Message.h"

◆ COMMS_MSG_TRANSPORT_FIELDS_ACCESS

template<typename... TOptions>
#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS (   ...)
related
Value:
COMMS_EXPAND(COMMS_DEFINE_TRANSPORT_FIELD_ENUM(__VA_ARGS__)) \
COMMS_MSG_TRANSPORT_FIELDS_ACCESS_FUNC { \
auto& msgBase = comms::toMessage(*this); \
using MsgBase = typename std::decay<decltype(msgBase)>::type; \
static_assert(MsgBase::hasTransportFields(), \
"Message interface class doesn't define extra transport fields."); \
using TransportFieldsTuple = typename MsgBase::TransportFields; \
static_assert(std::tuple_size<TransportFieldsTuple>::value == TransportFieldIdx_numOfValues, \
"Invalid number of names for transport fields tuple"); \
return msgBase.transportFields(); \
} \
COMMS_MSG_TRANSPORT_FIELDS_ACCESS_CONST_FUNC { \
return comms::toMessage(*this).transportFields(); \
} \
COMMS_EXPAND(COMMS_DO_TRANSPORT_FIELD_ACC_FUNC(TransportFields, transportFields(), __VA_ARGS__))
FieldsProvidedWithOption TransportFields
std::tuple of extra fields from transport layers that may affect the way the message fields get seria...
Definition: Message.h:325
TransportFields & transportFields()
Get access to extra transport fields.
Message< TOptions... > & toMessage(Message< TOptions... > &msg)
Upcast type of the message object to comms::Message in order to have access to its internal types.
Definition: Message.h:524

Add convenience access enum and functions to extra transport fields.

Very similar to COMMS_MSG_TRANSPORT_FIELDS_NAMES(), but does NOT require definition of Base inner member type (for some compilers) and does NOT define inner TransportField_* types for used fields.

Parameters
[in]...List of fields' names.
See also
COMMS_MSG_TRANSPORT_FIELDS_NAMES()
Note
Defined in "comms/Message.h"

◆ COMMS_MSG_TRANSPORT_FIELDS_NAMES

template<typename... TOptions>
#define COMMS_MSG_TRANSPORT_FIELDS_NAMES (   ...)
related
Value:
COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELDS_ACCESS(__VA_ARGS__)) \
COMMS_EXPAND(COMMS_DO_FIELD_TYPEDEF(typename Base::TransportFields, TransportField_, TransportFieldIdx_, __VA_ARGS__))
#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS(...)
Add convenience access enum and functions to extra transport fields.
Definition: Message.h:575

Provide names for extra transport fields.

The comms::Message class provides access to its extra transport fields via comms::MessageBase::transportFields() member function(s). The fields are bundled into std::tuple and can be accessed using indices with std::get. For convenience, the fields should be named. The COMMS_MSG_TRANSPORT_FIELDS_NAMES() macro does exactly that.
As an example, let's assume that custom message uses 3 fields of any types:

using TransportField1 = ...;
using TransportField2 = ...;
using TransportField3 = ...;
typedef std::tuple<TransportField1, TransportField2, TransportField3> MyExtraTransportFields
class MyInterface : public
...
comms::option::def::ExtraTransportFields<MyExtraTransportFields> >
{
// (Re)definition of the base class as inner Base type is
// required by the COMMS_MSG_TRANSPORT_FIELDS_NAMES() macro.
using Base = comms::Message<...>;
public:
COMMS_MSG_TRANSPORT_FIELDS_NAMES(name1, name2, name3);
};

The usage of the COMMS_MSG_TRANSPORT_FIELDS_NAMES() macro with the list of the extra transport field's names is equivalent to having the following definitions inside the message class

class MyInterface : public comms::Message<...>
{
using Base = comms::Message<...>;
public:
enum TransportFieldIdx {
TransportFieldIdx_name1,
TransportFieldIdx_name2,
TransportFieldIdx_name3,
TransportFieldIdx_nameOfValues
};
static_assert(std::tuple_size<Base::TransportFields>::value == TransportFieldIdx_nameOfValues,
"Number of expected transport fields is incorrect");
// Accessor to "name1" transport field.
auto transportField_name1() -> decltype(std::get<TransportFieldIdx_name1>(Base::transportFields()))
{
return std::get<TransportFieldIdx_name1>(Base::transportFields());
}
// Accessor to "name1" field.
auto transportField_name1() const -> decltype(std::get<TransportFieldIdx_name1>(Base::transportFields()))
{
return std::get<TransportFieldIdx_name1>(Base::transportFields());
}
// Accessor to "name2" field.
auto transportField_name2() -> decltype(std::get<TransportFieldIdx_name2>(Base::transportFields()))
{
return std::get<TransportFieldIdx_name2>(Base::transportFields());
}
// Accessor to "name2" field.
auto transportField_name2() const -> decltype(std::get<TransportFieldIdx_name2>(Base::transportFields()))
{
return std::get<TransportFieldIdx_name2>(Base::transportFields());
}
// Accessor to "name3" field.
auto transportField_name3() -> decltype(std::get<TransportFieldIdx_name3>(Base::transportFields()))
{
return std::get<TransportFieldIdx_name3>(Base::transportFields());
}
// Accessor to "name3" field.
auto transportField_name3() const -> decltype(std::get<FieldIdx_name3>(Base::transportFields()))
{
return std::get<FieldIdx_name3>(Base::transportFields());
}
// Redefinition of the transport field types:
using TransportField_name1 = TransportField1;
using TransportField_name2 = TransportField2;
using TransportField_name3 = TransportField3;
};

NOTE, that provided names name1, name2, and name3 have found their way to the following definitions:

  • TransportFieldIdx enum. The names are prefixed with TransportFieldIdx_. The TransportFieldIdx_nameOfValues value is automatically added at the end.
  • Accessor functions prefixed with transportField_*
  • Types of fields prefixed with TransportField_*

As the result, the fields can be accessed using TransportFieldIdx enum

void handle(Message1& msg)
{
auto& transportFields = msg.transportFields();
auto& field1 = std::get<Message1::TransportFieldIdx_name1>(transportFields);
auto& field2 = std::get<Message1::TransportFieldIdx_name2>(transportFields);
auto& field3 = std::get<Message1::TransportFieldIdx_name3>(transportFields);
auto value1 = field1.value();
auto value2 = field2.value();
auto value3 = field3.value();
}

or using accessor functions:

void handle(Message1& msg)
{
auto value1 = transportField_name1().value();
auto value2 = transportField_name2().value();
auto value3 = transportField_name3().value();
}
Parameters
[in]...List of fields' names.
Precondition
Requires (re)definition of the message base class as inner Base member type.
See also
COMMS_MSG_TRANSPORT_FIELDS_ACCESS()
Note
Defined in "comms/Message.h"

◆ operator!=()

bool operator!= ( const MessageBase< TMessage1, TOptions... > &  msg1,
const MessageBase< TMessage2, TOptions... > &  msg2 
)
related

Message object inequality comparison operator.

Messages are considered not equal if any their fields are considered inequal.

◆ operator==()

bool operator== ( const MessageBase< TMessage1, TOptions... > &  msg1,
const MessageBase< TMessage2, TOptions... > &  msg2 
)
related

Message object equality comparison operator.

Messages are considered equal if all their fields are considered equal


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