COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Related Symbols | List of all members
comms::protocol::MsgDataLayer< TExtraOpts > Class Template Reference

#include "comms/protocol/MsgDataLayer.h"

Detailed Description

template<typename... TExtraOpts>
class comms::protocol::MsgDataLayer< TExtraOpts >

Message data layer.

Must always be the last layer in protocol stack.

Template Parameters
TExtraOptsExtra 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.
 
MsgDataLayeroperator= (const MsgDataLayer &)=default
 Copy assignment operator.
 
MsgDataLayeroperator= (MsgDataLayer &&)=default
 Move assignment operator.
 
ThisLayerthisLayer ()
 Get access to this layer object.
 
const ThisLayerthisLayer () 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.
 

Member Typedef Documentation

◆ AllMessages

template<typename... TExtraOpts>
using comms::protocol::MsgDataLayer< TExtraOpts >::AllMessages = void

Default value of AllMessages type.

Defined as void.

◆ Field

template<typename... TExtraOpts>
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.

◆ MsgFactory

template<typename... TExtraOpts>
using comms::protocol::MsgDataLayer< TExtraOpts >::MsgFactory = void

Default value of MsgFactory type.

Defined as void.

Member Function Documentation

◆ accessCachedField()

template<typename... TExtraOpts>
template<typename TAllFields >
static auto comms::protocol::MsgDataLayer< TExtraOpts >::accessCachedField ( TAllFields &  allFields) -> decltype(std::get<std::tuple_size<typename std::decay<TAllFields>::type>::value - std::tuple_size<AllFields>::value>(allFields))
static

Access appropriate field from "cached" bundle of all the protocol stack fields.

Parameters
allFieldsAll fields of the protocol stack
Returns
Reference to requested field.

◆ canSplitRead()

template<typename... TExtraOpts>
static constexpr bool comms::protocol::MsgDataLayer< TExtraOpts >::canSplitRead ( )
staticconstexpr

Compile time check whether split read "until" and "from" data layer is allowed.

Returns
Always true.

◆ length() [1/2]

template<typename... TExtraOpts>
static constexpr std::size_t comms::protocol::MsgDataLayer< TExtraOpts >::length ( )
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.

Returns
0.

◆ length() [2/2]

template<typename... TExtraOpts>
template<typename TMsg >
static constexpr std::size_t comms::protocol::MsgDataLayer< TExtraOpts >::length ( const TMsg &  msg)
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.

Parameters
[in]msgMessage
Returns
Length of the message.

◆ read()

template<typename... TExtraOpts>
template<typename TMsg , typename TIter , typename... TExtraValues>
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::read ( TMsg &  msg,
TIter &  iter,
std::size_t  size,
TExtraValues...  extraValues 
)
static

Read the message contents.

Calls the read() member function of the message object.

Template Parameters
TMsgType of the msg parameter.
TIterType of iterator used for reading.
Parameters
[in]msgReference to the smart pointer holding message object or to the message object itself.
[in,out]iterIterator used for reading.
[in]sizeNumber of bytes available for reading.
[out]extraValuesExtra output parameters provided using one of the following functions
Returns
Status of the read operation.
Precondition
If msg is a smart pointer to message object, it must point to a real object.
Postcondition
missingSize output value is updated if and only if function returns comms::ErrorStatus::NotEnoughData.

◆ readFieldsCached()

template<typename... TExtraOpts>
template<typename TAllFields , typename TMsg , typename TIter , typename... TExtraValues>
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::readFieldsCached ( TAllFields &  allFields,
TMsg &  msg,
TIter &  iter,
std::size_t  size,
TExtraValues...  extraValues 
)
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.

Template Parameters
TIdxIndex of the data field in TAllFields, expected to be last element in the tuple.
TAllFieldsstd::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack.
TMsgType of the msg parameter
TIterType of iterator used for reading.
Parameters
[out]allFieldsReference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class).
[in]msgReference to the smart pointer holding message object or to the message object itself.
[in,out]iterIterator used for reading.
[in]sizeNumber of bytes available for reading.
[out]extraValuesExtra output parameters provided using one of the following functions
Returns
Status of the read operation.

◆ readFromData()

template<typename... TExtraOpts>
template<typename TMsg , typename TIter , typename... TExtraValues>
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::readFromData ( TMsg &  msg,
TIter &  iter,
std::size_t  size,
TExtraValues...  extraValues 
)
static

Same as read().

Expected to be called by the privous layers to properly finalise read operation after the call to readUntilData();

Returns
comms::ErrorStatus::Success;

◆ readFromDataFeildsCached()

template<typename... TExtraOpts>
template<typename TAllFields , typename TMsg , typename TIter , typename... TExtraValues>
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::readFromDataFeildsCached ( TAllFields &  allFields,
TMsg &  msg,
TIter &  iter,
std::size_t  size,
TExtraValues...  extraValues 
)
static

Same as readFieldsCached().

Expected to be called by the privous layers to properly finalise read operation after the call to readUntilDataFieldsCached();

Returns
comms::ErrorStatus::Success;

◆ readUntilData()

template<typename... TExtraOpts>
template<typename TMsg , typename TIter , typename... TExtraValues>
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::readUntilData ( TMsg &  msg,
TIter &  iter,
std::size_t  size,
TExtraValues...   
)
static

Read transport fields until data layer.

Does nothing because it is data layer.

Returns
comms::ErrorStatus::Success;

◆ readUntilDataFieldsCached()

template<typename... TExtraOpts>
template<typename TAllFields , typename TMsg , typename TIter , typename... TExtraValues>
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::readUntilDataFieldsCached ( TAllFields &  allFields,
TMsg &  msg,
TIter &  iter,
std::size_t  size,
TExtraValues...   
)
static

Read transport fields with caching until data layer.

Does nothing because it is data layer.

Returns
comms::ErrorStatus::Success;

◆ update() [1/2]

template<typename... TExtraOpts>
template<typename TMsg , typename TIter >
static comms::ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::update ( const TMsg &  msg,
TIter &  iter,
std::size_t  size 
)
static

Update recently written (using write()) message contents data.

Same as other update(), but with extra message parameter/

Parameters
[in]msgReference to recently writtem message object.
[in,out]iterAny random access iterator.
[in]sizeNumber of bytes that have been written using write().
Returns
Status of the update operation.

◆ update() [2/2]

template<typename... TExtraOpts>
template<typename TIter >
static comms::ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::update ( TIter &  iter,
std::size_t  size 
)
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".

Parameters
[in,out]iterAny random access iterator.
[in]sizeNumber of bytes that have been written using write().
Returns
Status of the update operation.

◆ updateFieldsCached() [1/2]

template<typename... TExtraOpts>
template<typename TAllFields , typename TMsg , typename TIter >
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::updateFieldsCached ( TAllFields &  allFields,
const TMsg &  msg,
TIter &  iter,
std::size_t  size 
)
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.

Template Parameters
TAllFieldsstd::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack.
TMsgType of msg parameter.
TIterType of the random access iterator.
Parameters
[out]allFieldsReference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class).
[in]msgReference to recently written message object.
[in,out]iterRandom access iterator to the written data.
[in]sizeNumber of bytes that have been written using writeFieldsCached().
Returns
Status of the update operation.

◆ updateFieldsCached() [2/2]

template<typename... TExtraOpts>
template<typename TAllFields , typename TIter >
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::updateFieldsCached ( TAllFields &  allFields,
TIter &  iter,
std::size_t  size 
)
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.

Template Parameters
TAllFieldsstd::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack.
TIterType of the random access iterator.
Parameters
[out]allFieldsReference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class).
[in,out]iterRandom access iterator to the written data.
[in]sizeNumber of bytes that have been written using writeFieldsCached().
Returns
Status of the update operation.

◆ write()

template<typename... TExtraOpts>
template<typename TMsg , typename TIter >
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::write ( const TMsg &  msg,
TIter &  iter,
std::size_t  size 
)
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.

Template Parameters
TMsgType of the message.
TIterType of the iterator used for writing.
Parameters
[in]msgReference to the message object,
[in,out]iterIterator used for writing.
[in]sizeMax number of bytes that can be written.
Returns
Status of the write operation.

◆ writeFieldsCached()

template<typename... TExtraOpts>
template<typename TAllFields , typename TMsg , typename TIter >
static ErrorStatus comms::protocol::MsgDataLayer< TExtraOpts >::writeFieldsCached ( TAllFields &  allFields,
const TMsg &  msg,
TIter &  iter,
std::size_t  size 
)
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.

Template Parameters
TAllFieldsstd::tuple of all the transport fields, must be AllFields type defined in the last layer class that defines protocol stack.
TMsgType of the message.
TIterType of the iterator used for writing.
Parameters
[out]allFieldsReference to the std::tuple object that wraps all transport fields (AllFields type of the last protocol layer class).
[in]msgReference to the message object that is being written,
[in,out]iterIterator used for writing.
[in]sizeMax number of bytes that can be written.
Returns
Status of the write operation.

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