COMMS
Template library intended to help with implementation of communication protocols.
|
#include "comms/protocol/MsgDataLayer.h"
Message data layer.
Must always be the last layer in protocol stack.
TExtraOpts | Extra options to inner Field type which is defined to be comms::field::ArrayList. This field is used only in AllFields type and readFieldsCached() member function. |
Public Types | |
using | AllFields = std::tuple< Field > |
All fields of the remaining transport layers, contains only Field. | |
using | AllMessages = void |
Default value of AllMessages type. | |
using | Field = comms::field::ArrayList< comms::Field< comms::option::def::BigEndian >, std::uint8_t, TExtraOpts... > |
Raw data field type. | |
using | MsgFactory = void |
Default value of MsgFactory type. | |
using | ThisLayer = MsgDataLayer< TExtraOpts... > |
Type of this layer. | |
Public Member Functions | |
MsgDataLayer ()=default | |
Default constructor. | |
MsgDataLayer (const MsgDataLayer &)=default | |
Copy constructor. | |
MsgDataLayer (MsgDataLayer &&)=default | |
Move constructor. | |
~MsgDataLayer () noexcept=default | |
Destructor. | |
MsgDataLayer & | operator= (const MsgDataLayer &)=default |
Copy assignment operator. | |
MsgDataLayer & | operator= (MsgDataLayer &&)=default |
Move assignment operator. | |
ThisLayer & | thisLayer () |
Get access to this layer object. | |
const ThisLayer & | thisLayer () const |
Get "const" access to this layer object. | |
Static Public Member Functions | |
template<typename TAllFields > | |
static auto | accessCachedField (TAllFields &allFields) -> decltype(std::get< std::tuple_size< typename std::decay< TAllFields >::type >::value - std::tuple_size< AllFields >::value >(allFields)) |
Access appropriate field from "cached" bundle of all the protocol stack fields. | |
static constexpr bool | canSplitRead () |
Compile time check whether split read "until" and "from" data layer is allowed. | |
static constexpr std::size_t | length () |
Get remaining length of wrapping transport information. | |
template<typename TMsg > | |
static constexpr std::size_t | length (const TMsg &msg) |
Get remaining length of wrapping transport information + length of the provided message. | |
template<typename TMsg , typename TIter , typename... TExtraValues> | |
static ErrorStatus | read (TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues) |
Read the message contents. | |
template<typename TAllFields , typename TMsg , typename TIter , typename... TExtraValues> | |
static ErrorStatus | readFieldsCached (TAllFields &allFields, TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues) |
Read the message contents while caching the read transport information fields. | |
template<typename TMsg , typename TIter , typename... TExtraValues> | |
static ErrorStatus | readFromData (TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues) |
Same as read(). | |
template<typename TAllFields , typename TMsg , typename TIter , typename... TExtraValues> | |
static ErrorStatus | readFromDataFeildsCached (TAllFields &allFields, TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues) |
Same as readFieldsCached(). | |
template<typename TMsg , typename TIter , typename... TExtraValues> | |
static ErrorStatus | readUntilData (TMsg &msg, TIter &iter, std::size_t size, TExtraValues...) |
Read transport fields until data layer. | |
template<typename TAllFields , typename TMsg , typename TIter , typename... TExtraValues> | |
static ErrorStatus | readUntilDataFieldsCached (TAllFields &allFields, TMsg &msg, TIter &iter, std::size_t size, TExtraValues...) |
Read transport fields with caching until data layer. | |
template<typename TMsg , typename TIter > | |
static comms::ErrorStatus | update (const TMsg &msg, TIter &iter, std::size_t size) |
Update recently written (using write()) message contents data. | |
template<typename TIter > | |
static comms::ErrorStatus | update (TIter &iter, std::size_t size) |
Update recently written (using write()) message contents data. | |
template<typename TAllFields , typename TMsg , typename TIter > | |
static ErrorStatus | updateFieldsCached (TAllFields &allFields, const TMsg &msg, TIter &iter, std::size_t size) |
Update recently written (using writeFieldsCached()) message data as well as cached transport information fields. | |
template<typename TAllFields , typename TIter > | |
static ErrorStatus | updateFieldsCached (TAllFields &allFields, TIter &iter, std::size_t size) |
Update recently written (using writeFieldsCached()) message data as well as cached transport information fields. | |
template<typename TMsg , typename TIter > | |
static ErrorStatus | write (const TMsg &msg, TIter &iter, std::size_t size) |
Write the message contents. | |
template<typename TAllFields , typename TMsg , typename TIter > | |
static ErrorStatus | writeFieldsCached (TAllFields &allFields, const TMsg &msg, TIter &iter, std::size_t size) |
Write the message contents while caching the written transport information fields. | |
Static Public Attributes | |
static const std::size_t | NumOfLayers = 1 |
Static constant indicating amount of transport layers used. | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename T > | |
constexpr bool | isMsgDataLayer () |
Compile time check of whether the provided type is a variant of MsgDataLayer. | |
using comms::protocol::MsgDataLayer< TExtraOpts >::AllMessages = void |
Default value of AllMessages type.
Defined as void.
using comms::protocol::MsgDataLayer< TExtraOpts >::Field = comms::field::ArrayList< comms::Field<comms::option::def::BigEndian>, std::uint8_t, TExtraOpts... > |
Raw data field type.
This field is used only in AllFields field and readFieldsCached() member function.
using comms::protocol::MsgDataLayer< TExtraOpts >::MsgFactory = void |
Default value of MsgFactory type.
Defined as void.
|
static |
Access appropriate field from "cached" bundle of all the protocol stack fields.
allFields | All fields of the protocol stack |
|
staticconstexpr |
Compile time check whether split read "until" and "from" data layer is allowed.
|
staticconstexpr |
Get remaining length of wrapping transport information.
The message data always get wrapped with transport information to be successfully delivered to and unpacked on the other side. This function return remaining length of the transport information.
|
staticconstexpr |
Get remaining length of wrapping transport information + length of the provided message.
This function usually gets called when there is a need to identify the size of the buffer required to write provided message wrapped in the transport information. This function is very similar to length(), but adds also length of the message.
[in] | msg | Message |
|
static |
Read the message contents.
Calls the read() member function of the message object.
TMsg | Type of the msg parameter. |
TIter | Type of iterator used for reading. |
[in] | msg | Reference to the smart pointer holding message object or to the message object itself. |
[in,out] | iter | Iterator used for reading. |
[in] | size | Number of bytes available for reading. |
[out] | extraValues | Extra output parameters provided using one of the following functions |
|
static |
Read the message contents while caching the read transport information fields.
Very similar to read() member function, but adds "allFields" parameter to store raw data of the message.
TIdx | Index of the data field in TAllFields, expected to be last element in the tuple. |
TAllFields | std::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack. |
TMsg | Type of the msg parameter |
TIter | Type of iterator used for reading. |
[out] | allFields | Reference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class). |
[in] | msg | Reference to the smart pointer holding message object or to the message object itself. |
[in,out] | iter | Iterator used for reading. |
[in] | size | Number of bytes available for reading. |
[out] | extraValues | Extra output parameters provided using one of the following functions |
|
static |
Same as read().
Expected to be called by the privous layers to properly finalise read operation after the call to readUntilData();
|
static |
Same as readFieldsCached().
Expected to be called by the privous layers to properly finalise read operation after the call to readUntilDataFieldsCached();
|
static |
Read transport fields until data layer.
Does nothing because it is data layer.
|
static |
Read transport fields with caching until data layer.
Does nothing because it is data layer.
|
static |
Update recently written (using write()) message contents data.
Same as other update(), but with extra message parameter/
[in] | msg | Reference to recently writtem message object. |
[in,out] | iter | Any random access iterator. |
[in] | size | Number of bytes that have been written using write(). |
|
static |
Update recently written (using write()) message contents data.
Sometimes, when NON random access iterator is used for writing (for example std::back_insert_iterator), some transport data cannot be properly written. In this case, write() function will return comms::ErrorStatus::UpdateRequired. When such status is returned it is necessary to call update() with random access iterator on the written buffer to update written dummy information with proper values. This function in this layer does nothing, just advances the iterator by "size".
[in,out] | iter | Any random access iterator. |
[in] | size | Number of bytes that have been written using write(). |
|
static |
Update recently written (using writeFieldsCached()) message data as well as cached transport information fields.
Very similar to other updateFieldsCached() member function, but adds "msg" parameter to reference message object if needed.
TAllFields | std::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack. |
TMsg | Type of msg parameter. |
TIter | Type of the random access iterator. |
[out] | allFields | Reference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class). |
[in] | msg | Reference to recently written message object. |
[in,out] | iter | Random access iterator to the written data. |
[in] | size | Number of bytes that have been written using writeFieldsCached(). |
|
static |
Update recently written (using writeFieldsCached()) message data as well as cached transport information fields.
Very similar to update() member function, but adds "allFields" parameter to store raw data of the message.
TAllFields | std::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack. |
TIter | Type of the random access iterator. |
[out] | allFields | Reference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class). |
[in,out] | iter | Random access iterator to the written data. |
[in] | size | Number of bytes that have been written using writeFieldsCached(). |
|
static |
Write the message contents.
The way the message contents are written is determined by the type of the message. If TMsg type is recognised to be actual message inheriting from comms::MessageBase with its fields provided using comms::option::def::FieldsImpl option, the function calls doWrite non-virtual function defined by comms::MessageBase (see comms::MessageBase::doWrite) or redefined by the actual message itself. Otherwise, TMsg type is expected to be the used interface which allows polymorphic write functionality. It must define write() member function which will be called.
TMsg | Type of the message. |
TIter | Type of the iterator used for writing. |
[in] | msg | Reference to the message object, |
[in,out] | iter | Iterator used for writing. |
[in] | size | Max number of bytes that can be written. |
|
static |
Write the message contents while caching the written transport information fields.
Very similar to write() member function, but adds "allFields" parameter to store raw data of the message.
TAllFields | std::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack. |
TMsg | Type of the message. |
TIter | Type of the iterator used for writing. |
[out] | allFields | Reference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class). |
[in] | msg | Reference to the message object that is being written, |
[in,out] | iter | Iterator used for writing. |
[in] | size | Max number of bytes that can be written. |