COMMS
Template library intended to help with implementation of communication protocols.
|
#include "comms/GenericMessage.h"
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).
TMessage | Common message interface class, becomes one of the base classes. |
TFieldOpts | Extra option(s) (multiple options need to be bundled in std::tuple) to be passed to the definition of the data field (see GenericMessageFields). |
TExtraOpts | Extra option(s) (multple options need to be bundled in std::tuple) to be passed to comms::MessageBase which is base to this one. |
Public Types | |
using | AllFields = FieldsProvidedWithOption |
All field classes provided with comms::option::def::FieldsImpl option. | |
using | DispatchRetType = typename Handler::RetType |
Return type of the dispatch() member function. | |
using | Endian = typename BaseImpl::Endian |
Serialisation endian type. | |
using | Field = BaseImpl::Field |
Type of default base class for all the fields. | |
using | Handler = TypeProvidedWithOption |
Type of the message handler object. | |
using | ImplOptions = details::MessageImplOptionsParser< TOptions... > |
All the options provided to this class bundled into struct. | |
using | InterfaceOptions = details::MessageInterfaceOptionsParser< TOptions... > |
All the options bundled into struct. | |
using | MsgIdParamType = typename Base::MsgIdParamType |
Type of the message ID passed as parameter. | |
using | MsgIdType = typename Base::MsgIdType |
Type of the message ID. | |
using | MsgType = typename ImplOptions::MsgType |
Type of the actual message provided via comms::option::def::MsgType. | |
using | ReadIterator = TypeProvidedWithOption |
Type of the iterator used for reading message contents from sequence of bytes stored somewhere. | |
using | TransportFields = FieldsProvidedWithOption |
std::tuple of extra fields from transport layers that may affect the way the message fields get serialized / deserialized. | |
using | VersionType = typename BaseImpl::VersionType |
Type used for version info. | |
using | WriteIterator = TypeProvidedWithOption |
Type of the iterator used for writing message contents into sequence of bytes stored somewhere. | |
Public Member Functions | |
GenericMessage ()=delete | |
Default constructor is deleted. | |
GenericMessage (const GenericMessage &)=default | |
Copy constructor. | |
GenericMessage (GenericMessage &&)=default | |
Move constructor. | |
GenericMessage (MsgIdParamType id) | |
Constructor. | |
~GenericMessage () noexcept=default | |
Destructor. | |
COMMS_MSG_FIELDS_NAMES (data) | |
Allow access to internal fields. | |
DispatchRetType | dispatch (Handler &handler) |
Dispatch message to the handler for processing. | |
bool | doFieldsVersionUpdate () |
Update version information of all the fields. | |
MsgIdParamType | doGetId () const |
Get message ID information. | |
std::size_t | doLength () const |
Default implementation of length calculation functionality. | |
template<std::size_t TFromIdx> | |
std::size_t | doLengthFrom () const |
Default implementation of partial length calculation functionality. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx> | |
std::size_t | doLengthFromUntil () const |
Default implementation of partial length calculation functionality. | |
template<std::size_t TUntilIdx> | |
std::size_t | doLengthUntil () const |
Default implementation of partial length calculation functionality. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx> | |
std::size_t | doMaxLengthFromUntil () const |
Compile time constant of maximal partial serialisation length. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx> | |
std::size_t | doMinLengthFromUntil () const |
Compile time constant of minimal partial serialisation length. | |
template<typename TIter > | |
ErrorStatus | doRead (TIter &iter, std::size_t size) |
Default implementation of read functionality. | |
bool | doRefresh () const |
Default implementation of refreshing functionality. | |
bool | doValid () const |
Default implementation of validity check functionality. | |
template<typename TIter > | |
ErrorStatus | doWrite (TIter &iter, std::size_t size) const |
Default implementation of write functionality. | |
AllFields & | fields () |
Get an access to the fields of the message. | |
const AllFields & | fields () const |
Get an access to the fields of the message. | |
MsgIdParamType | getId () const |
Retrieve ID of the message. | |
std::size_t | length () const |
Get number of bytes required to serialise this message. | |
const char * | name () const |
Get name of the message. | |
GenericMessage & | operator= (const GenericMessage &)=default |
Copy assignment. | |
GenericMessage & | operator= (GenericMessage &&)=default |
Move assignment. | |
ErrorStatus | read (ReadIterator &iter, std::size_t size) |
Read message contents using provided iterator. | |
bool | refresh () |
Refresh to contents of the message. | |
TransportFields & | transportFields () |
Get access to extra transport fields. | |
const TransportFields & | transportFields () const |
Const version of transportFields. | |
bool | valid () const |
Check validity of message contents. | |
VersionType & | version () |
Access to version information. | |
const VersionType & | version () const |
Const access to version information. | |
ErrorStatus | write (WriteIterator &iter, std::size_t size) const |
Write message contents using provided iterator. | |
Static Public Member Functions | |
static constexpr bool | areFieldsVersionDependent () |
Compile time check of whether the message fields are version dependent. | |
static constexpr MsgIdParamType | doGetId () |
Default implementation of ID retrieval functionality. | |
static constexpr std::size_t | doMaxLength () |
Compile time constant of maximal serialisation length. | |
template<std::size_t TFromIdx> | |
static constexpr std::size_t | doMaxLengthFrom () |
Compile time constant of maximal partial serialisation length. | |
template<std::size_t TUntilIdx> | |
static constexpr std::size_t | doMaxLengthUntil () |
Compile time constant of maximal partial serialisation length. | |
static constexpr std::size_t | doMinLength () |
Compile time constant of minimal serialisation length. | |
template<std::size_t TFromIdx> | |
static constexpr std::size_t | doMinLengthFrom () |
Compile time constant of minimal partial serialisation length. | |
template<std::size_t TUntilIdx> | |
static constexpr std::size_t | doMinLengthUntil () |
Compile time constant of minimal partial serialisation length. | |
static const char * | doName () |
Get message name information. | |
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. | |
static constexpr std::size_t | versionIdxInTransportFields () |
Compile type inquiry of version field index in transport field. | |
Protected Member Functions | |
virtual DispatchRetType | dispatchImpl (Handler &handler) override |
Implementation of dispatch functionality. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doReadFrom (TIter &iter, std::size_t len) |
Helper function that allows to read only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doReadFromAndUpdateLen (TIter &iter, std::size_t &len) |
Same as doReadFrom(), but modifies length parameter. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | doReadFromUntil (TIter &iter, std::size_t len) |
Helper function that allows to read only limited number of fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | doReadFromUntilAndUpdateLen (TIter &iter, std::size_t &len) |
Same as doReadFromUntil(), but modifies length parameter. | |
template<std::size_t TIdx, typename TIter > | |
void | doReadNoStatusFrom (TIter &iter) |
Helper function that allows to read only limited number of fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
void | doReadNoStatusFromUntil (TIter &iter) |
Helper function that allows to read only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
void | doReadNoStatusUntil (TIter &iter) |
Helper function that allows to read only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doReadUntil (TIter &iter, std::size_t &len) |
Helper function that allows to read only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doReadUntilAndUpdateLen (TIter &iter, std::size_t &len) |
Same as doReadUntil(), but updating length parameter. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doWriteFrom (TIter &iter, std::size_t len) const |
Helper function that allows to write only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doWriteFromAndUpdateLen (TIter &iter, std::size_t &len) const |
Same as doWriteFrom(), but modifies length parameter. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | doWriteFromUntil (TIter &iter, std::size_t len) const |
Helper function that allows to write only limited number of fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | doWriteFromUntilAndUpdateLen (TIter &iter, std::size_t &len) const |
Same as doWriteNoStatusFrom(), but updates length information. | |
template<std::size_t TIdx, typename TIter > | |
void | doWriteNoStatusFrom (TIter &iter) const |
Helper function that allows to write only limited number of fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
void | doWriteNoStatusFromUntil (TIter &iter) const |
Helper function that allows to write only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
void | doWriteNoStatusUntil (TIter &iter) const |
Helper function that allows to write only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
ErrorStatus | doWriteUntil (TIter &iter, std::size_t len) const |
Helper function that allows to write only limited number of fields. | |
template<std::size_t TIdx, typename TIter > | |
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. | |
virtual std::size_t | lengthImpl () const override |
Implementation of polymorphic length calculation functionality. | |
virtual const char * | nameImpl () const override |
Implementation of polymorphic name retrieval functionality. | |
virtual ErrorStatus | readImpl (ReadIterator &iter, std::size_t size) override |
Implementation of polymorphic read functionality. | |
virtual bool | refreshImpl () override |
Implementation of polymorphic refresh functionality. | |
virtual bool | validImpl () const override |
Implementation of polymorphic validity check functionality. | |
virtual ErrorStatus | writeImpl (WriteIterator &iter, std::size_t size) const override |
Implementation of polymorphic write functionality. | |
Static Protected Member Functions | |
template<typename T , typename TIter > | |
static T | readData (TIter &iter) |
Read data from input area. | |
template<typename T , std::size_t TSize, typename TIter > | |
static T | readData (TIter &iter) |
Read partial data from input area. | |
template<typename T , typename TIter > | |
static void | writeData (T value, TIter &iter) |
Write data into the output area. | |
template<std::size_t TSize, typename T , typename TIter > | |
static void | writeData (T value, TIter &iter) |
Write partial data into the output area. | |
Related Symbols | |
(Note that these are not member symbols.) | |
#define | COMMS_MSG_FIELD_ALIAS(f_, ...) |
Generate convinience alias types and access member functions for other member fields. | |
#define | COMMS_MSG_FIELD_ALIAS_ACCESS(f_, ...) COMMS_DO_ALIAS(field_, f_, __VA_ARGS__) |
Generate convinience alias access member functions for other member fields. | |
#define | COMMS_MSG_FIELDS_ACCESS(...) |
Add convenience access enum and functions to message fields. | |
#define | COMMS_MSG_FIELDS_NAMES(...) |
Provide names for message fields. | |
#define | COMMS_MSG_TRANSPORT_FIELD_ALIAS(f_, ...) |
Generate convinience alias access member functions for extra member transport fields. | |
#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. | |
#define | COMMS_MSG_TRANSPORT_FIELDS_ACCESS(...) |
Add convenience access enum and functions to extra transport fields. | |
#define | COMMS_MSG_TRANSPORT_FIELDS_NAMES(...) |
Provide names for extra transport fields. | |
template<typename TMessage1 , typename TMessage2 , typename... TOptions> | |
bool | operator!= (const MessageBase< TMessage1, TOptions... > &msg1, const MessageBase< TMessage2, TOptions... > &msg2) noexcept |
Message object inequality comparison operator. | |
template<typename TMessage1 , typename TMessage2 , typename... TOptions> | |
bool | operator== (const MessageBase< TMessage1, TOptions... > &msg1, const MessageBase< TMessage2, TOptions... > &msg2) noexcept |
Message object equality comparison operator. | |
|
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.
|
inherited |
Return type of the dispatch() member function.
Equal to Handler::RetType if such exists, void otherwise.
|
inherited |
Serialisation endian type.
The type exists only if comms::option::def::BigEndian or comms::option::def::LittleEndian options were used to specify it.
|
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.
|
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.
|
inherited |
All the options provided to this class bundled into struct.
For internal use only
|
inherited |
All the options bundled into struct.
For internal use only.
using comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::MsgIdParamType = typename Base::MsgIdParamType |
Type of the message ID passed as parameter.
The same as comms::Message::MsgIdParamType;
using comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::MsgIdType = typename Base::MsgIdType |
Type of the message ID.
The same as comms::Message::MsgIdType;
|
inherited |
Type of the actual message provided via comms::option::def::MsgType.
If comms::option::def::MsgType hasn't been used equals to void.
|
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.
|
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.
|
inherited |
Type used for version info.
The type exists only if comms::option::def::VersionInExtraTransportFields option has been provided.
|
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.
|
explicit |
Constructor.
[in] | id | ID of the message |
|
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.
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.
|
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.
handler | Handler object to dispatch message to. |
|
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:
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:
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.
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:
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)".
handler | Reference to handler object. |
Reimplemented from comms::Message< TOptions >.
|
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()).
|
staticconstexprinherited |
Default implementation of ID retrieval functionality.
This function exists only if comms::option::def::StaticNumIdImpl option was provided to comms::MessageBase.
MsgIdParamType comms::GenericMessage< TMessage, TFieldOpts, TExtraOpts >::doGetId | ( | ) | const |
Get message ID information.
The comms::MessageBase::getIdImpl() will invoke this function.
|
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:
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.
|
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.
TFromIdx | Index of the field, from which length calculation will start |
|
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.
TFromIdx | Index of the field, from which length calculation will start |
TUntilIdx | Index of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account. |
|
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.
TUntilIdx | Index of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account. |
|
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:
|
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.
TFromIdx | Index of the field, from which length calculation will start |
|
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.
TFromIdx | Index of the field, from which length calculation will start |
TUntilIdx | Index of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account. |
|
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.
TUntilIdx | Index of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account. |
|
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:
|
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.
TFromIdx | Index of the field, from which length calculation will start |
|
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.
TFromIdx | Index of the field, from which length calculation will start |
TUntilIdx | Index of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account. |
|
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.
TUntilIdx | Index of the field, at which the calculation will stop. The length of the filed with index TUntilIdx will NOT be taken into account. |
|
static |
Get message name information.
The comms::MessageBase::nameImpl() will invoke this function.
|
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:
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.
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
[in] | size | Maximum number of bytes that can be read. |
|
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.
TIdx | Zero 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). |
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
[in] | len | Maximum number of bytes that can be read. |
|
protectedinherited |
Same as doReadFrom(), but modifies length parameter.
[in,out] | iter | Iterator used for reading the data. |
[in,out] | len | Maximum number of bytes that can be read. |
|
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.
TFromIdx | Zero based index of the field to read from. |
TUntilIdx | Zero based index of the field to read until (not included). |
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
[in] | len | Maximum number of bytes that can be read. |
|
protectedinherited |
Same as doReadFromUntil(), but modifies length parameter.
[in,out] | iter | Iterator used for reading the data. |
[in,out] | len | Maximum number of bytes that can be read. |
|
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.
TIdx | Zero 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). |
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
|
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.
TFromIdx | Zero based index of the field to read from. |
TUntilIdx | Zero based index of the field to read until (not included). |
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
|
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.
TIdx | Zero 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. |
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
|
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.
TIdx | Zero 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. |
TIter | Type of the iterator used for reading. |
[in,out] | iter | Iterator used for reading the data. |
[in] | len | Maximum number of bytes that can be read. |
|
protectedinherited |
Same as doReadUntil(), but updating length parameter.
[in,out] | iter | Iterator used for reading the data. |
[in,out] | len | Maximum number of bytes that can be read. |
|
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:
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.
|
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:
This function will invoke such "valid()" member function for every field object listed with comms::option::def::FieldsImpl option.
|
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:
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.
TIter | Type of the iterator used for writing. |
[in,out] | iter | Iterator used for writing the data. |
[in] | size | Maximum number of bytes that can be written. |
|
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.
TIdx | Zero based index of the field to write from. |
TIter | Type of iterator used for writing. |
[in,out] | iter | Iterator used for writing the data. |
[in] | len | Maximum number of bytes that can be written. |
|
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.
TFromIdx | Zero based index of the field to write from. |
TUntilIdx | Zero based index of the field to write until (not including). |
TIter | Type of iterator used for writing. |
[in,out] | iter | Iterator used for writing the data. |
[in] | len | Maximum number of bytes that can be written. |
|
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.
TIdx | Zero based index of the field to write from. |
TIter | Type of the iterator used for writing. |
[in,out] | iter | Iterator used for reading the data. |
|
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.
TFromIdx | Zero based index of the field to write from. |
TUntilIdx | Zero based index of the field to write until (not including). |
TIter | Type of iterator used for writing. |
[in,out] | iter | Iterator used for reading the data. |
|
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.
TIdx | Zero 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. |
TIter | Type of the iterator used for writing. |
[in,out] | iter | Iterator used for reading the data. |
|
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.
TIdx | Zero 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. |
TIter | Type of iterator used for writing. |
[in,out] | iter | Iterator used for writing the data. |
[in] | len | Maximum number of bytes that can be written. |
|
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.
|
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.
|
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.
|
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.
Implements comms::Message< TOptions >.
|
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.
|
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.
Reimplemented from comms::Message< TOptions >.
|
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.
|
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.
Implements comms::Message< TOptions >.
|
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.
[in,out] | iter | Iterator used for reading the data. |
[in] | size | Maximum number of bytes that can be read. |
|
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.
T | Return type |
TIter | Type of input iterator |
[in,out] | iter | Input iterator. |
|
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.
T | Return type |
TSize | number of bytes to read |
TIter | Type of input iterator |
[in,out] | iter | Input iterator. |
|
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.
[in,out] | iter | Iterator used for reading the data. |
[in] | size | Maximum number of bytes that can be read. |
Reimplemented from comms::Message< TOptions >.
|
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.
|
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.
Reimplemented from comms::Message< TOptions >.
|
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.
|
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.
|
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.
|
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.
|
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 >.
|
inherited |
Access to version information.
The function exists only if comms::option::def::VersionInExtraTransportFields option has been provided.
|
inherited |
Const access to version information.
The function exists only if comms::option::def::VersionInExtraTransportFields option has been provided.
|
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.
|
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.
[in,out] | iter | Iterator used for writing the data. |
[in] | size | Maximum number of bytes that can be written. |
|
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.
T | Type of the value to write. Must be integral. |
Type | of output iterator |
[in] | value | Integral type value to be written. |
[in,out] | iter | Output iterator. |
|
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.
TSize | Length of the value in bytes known in compile time. |
T | Type of the value to write. Must be integral. |
TIter | Type of output iterator |
[in] | value | Integral type value to be written. |
[in,out] | iter | Output iterator. |
|
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.
[in,out] | iter | Iterator used for writing the data. |
[in] | size | Maximum number of bytes that can be written. |
Reimplemented from comms::Message< TOptions >.
|
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.
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:
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:
The usage of COMMS_MSG_FIELD_ALIAS() in the code above is equivalent to having the following functions defined:
[in] | f_ | Alias field name. |
[in] | ... | List of fields' names. |
|
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.
[in] | f_ | Alias field name. |
[in] | ... | List of fields' names. |
|
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.
[in] | ... | List of 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:
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
NOTE, that provided names name1, name2, and name3 have found their way to the following definitions:
As the result, the fields can be accessed using FieldIdx enum
or using accessor functions:
[in] | ... | List of fields' names. |
|
related |
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.
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_TRANSPORT_FIELD_ALIAS() in the code above is equivalent to having the following type and functions defined:
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:
The usage of COMMS_MSG_TRANSPORT_FIELD_ALIAS() in the code above is equivalent to having the following functions defined:
[in] | f_ | Alias field name. |
[in] | ... | List of fields' names. |
|
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.
[in] | f_ | Alias field name. |
[in] | ... | List of fields' names. |
|
related |
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.
[in] | ... | List of fields' names. |
|
related |
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:
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
NOTE, that provided names name1, name2, and name3 have found their way to the following definitions:
As the result, the fields can be accessed using TransportFieldIdx enum
or using accessor functions:
[in] | ... | List of fields' names. |
|
related |
Message object inequality comparison operator.
Messages are considered not equal if any their fields are considered inequal.
|
related |
Message object equality comparison operator.
Messages are considered equal if all their fields are considered equal