COMMS
Template library intended to help with implementation of communication protocols.
Namespaces | Classes | Functions
comms::protocol Namespace Reference

Namespace that contains definition of layers that can be used to wrap message data with transport data. More...

Detailed Description

Namespace that contains definition of layers that can be used to wrap message data with transport data.

Namespaces

 checksum
 Namespace that contains definition of checksum calculator classes which can be used with comms::protocol::ChecksumLayer transport layer class.
 

Classes

class  ChecksumLayer
 Protocol layer that is responsible to calculate checksum on the data written by all the wrapped internal layers and append it to the end of the written data. When reading, this layer is responsible to verify the checksum reported at the end of the read data. More...
 
class  ChecksumPrefixLayer
 Protocol layer that is responsible to calculate checksum on the data written by all the wrapped internal layers and prepend it before the written data. When reading, this layer is responsible to verify the checksum reported at the beginning of the read data. More...
 
class  MsgDataLayer
 Message data layer. More...
 
class  MsgIdLayer
 Protocol layer that uses uses message ID field as a prefix to all the subsequent data written by other (next) layers. More...
 
class  MsgSizeLayer
 Protocol layer that uses size field as a prefix to all the subsequent data written by other (next) layers. More...
 
class  ProtocolLayerBase
 Base class for all the middle (non MsgDataLayer) protocol transport layers. More...
 
class  SyncPrefixLayer
 Protocol layer that uses "sync" field as a prefix to all the subsequent data written by other (next) layers. More...
 
class  TransportValueLayer
 Protocol layer that reads a value from transport wrapping and reassigns it to appropriate "extra transport" data member of the created message object. More...
 

Functions

details::MissingSizeRetriever missingSize (std::size_t &val)
 Add "missing size" output parameter to protocol stack's (frame's) "read" operation. More...
 
template<typename TId >
details::MsgIdRetriever< TId > msgId (TId &val)
 Add "message ID" output parameter to protocol stack's (frame's) "read" operation. More...
 
details::MsgIndexRetriever msgIndex (std::size_t &val)
 Add "message index" output parameter to protocol stack's (frame's) "read" operation. More...
 
template<typename TIter >
details::MsgPayloadRetriever< TIter > msgPayload (TIter &iter, std::size_t &len)
 Add "payload start" and "payload size" output parameters to protocol stack's (frame's) "read" operation. More...
 
template<typename TField , typename TNextLayer , typename TDerived , typename... TOptions>
constexpr const ProtocolLayerBase< TField, TNextLayer, TDerived, TOptions... > & toProtocolLayerBase (const ProtocolLayerBase< TField, TNextLayer, TDerived, TOptions... > &layer)
 Upcast protocol layer in order to have access to its internal types.
 
template<typename TField , typename TNextLayer , typename TDerived , typename... TOptions>
ProtocolLayerBase< TField, TNextLayer, TDerived, TOptions... > & toProtocolLayerBase (ProtocolLayerBase< TField, TNextLayer, TDerived, TOptions... > &layer)
 Upcast protocol layer in order to have access to its internal types.
 

Function Documentation

◆ missingSize()

details::MissingSizeRetriever comms::protocol::missingSize ( std::size_t &  val)

Add "missing size" output parameter to protocol stack's (frame's) "read" operation.

Can be passed as variadic parameters to "read" functions of protocol stack (see comms::protocol::ProtocolLayerBase::read() and comms::protocol::ProtocolLayerBase::readFieldsCached()). It can be used to retrieve missing length information in case "read" of protocol stack operation returns comms::ErrorStatus::NotEnoughData.

using ProtocolStack = ...
ProtocolStack stack;
ProtocolStack::MsgPtr msg;
std::size_t missingSize = 0U;
auto es = stack.read(msg, readIter, size, comms::protocol::missingSize(missingSize));
... // missingSize will hold a minimal number of bytes that are required to be yet read
}
details::MissingSizeRetriever missingSize(std::size_t &val)
Add "missing size" output parameter to protocol stack's (frame's) "read" operation.
Definition: ProtocolLayerBase.h:1561
Parameters
[out]valMissing size value to be returned.
Returns
Implementation dependent object accepted by "read" functions.
See also
comms::protocol::ProtocolLayerBase::read()
comms::protocol::ProtocolLayerBase::readFieldsCached()

◆ msgId()

template<typename TId >
details::MsgIdRetriever<TId> comms::protocol::msgId ( TId &  val)

Add "message ID" output parameter to protocol stack's (frame's) "read" operation.

Can be passed as variadic parameters to "read" functions of protocol stack (see comms::protocol::ProtocolLayerBase::read() and comms::protocol::ProtocolLayerBase::readFieldsCached()). It can be used to retrieve numeric message ID value.

using ProtocolStack = ...
ProtocolStack stack;
ProtocolStack::MsgPtr msg;
my_prot::MsgId msgId = my_prot::MsgId();
auto es = stack.read(msg, readIter, size, comms::protocol::msgId(msgId));
assert(msg); // Message object must be created
... // use msgId value
}
details::MsgIdRetriever< TId > msgId(TId &val)
Add "message ID" output parameter to protocol stack's (frame's) "read" operation.
Definition: ProtocolLayerBase.h:1588
@ Success
Used to indicate successful outcome of the operation.
Parameters
[out]valNumeric message ID value to be returned.
Returns
Implementation dependent object accepted by "read" functions.
See also
comms::protocol::ProtocolLayerBase::read()
comms::protocol::ProtocolLayerBase::readFieldsCached()

◆ msgIndex()

details::MsgIndexRetriever comms::protocol::msgIndex ( std::size_t &  val)

Add "message index" output parameter to protocol stack's (frame's) "read" operation.

In case the expected input message types tuple contains multiple different message classes but having the same numeric ID, it may be beneficial to know the reletive index (starting from the first message type having the same ID) of the detected message. This function can be used to retrieve such information. Can be passed as variadic parameters to "read" functions of protocol stack (see comms::protocol::ProtocolLayerBase::read() and comms::protocol::ProtocolLayerBase::readFieldsCached()).

using ProtocolStack = ...
ProtocolStack stack;
ProtocolStack::MsgPtr msg;
my_prot::MsgId msgId = my_prot::MsgId();
std::size_t msgIndex = 0U;
auto es =
stack.read(
msg,
readIter,
size,
assert(msg); // Message object must be created
... // use msgId and msgIndex values
}
details::MsgIndexRetriever msgIndex(std::size_t &val)
Add "message index" output parameter to protocol stack's (frame's) "read" operation.
Definition: ProtocolLayerBase.h:1626
Parameters
[out]valMessage index value to be returned.
Returns
Implementation dependent object accepted by "read" functions.
See also
comms::protocol::ProtocolLayerBase::read()
comms::protocol::ProtocolLayerBase::readFieldsCached()

◆ msgPayload()

template<typename TIter >
details::MsgPayloadRetriever<TIter> comms::protocol::msgPayload ( TIter &  iter,
std::size_t &  len 
)

Add "payload start" and "payload size" output parameters to protocol stack's (frame's) "read" operation.

Can be passed as variadic parameters to "read" functions of protocol stack (see comms::protocol::ProtocolLayerBase::read() and comms::protocol::ProtocolLayerBase::readFieldsCached()). It can be used to retrieve information on payload start location as well as its size.

using ProtocolStack = ...
ProtocolStack stack;
ProtocolStack::MsgPtr msg;
decltype(readIter) payloadIter;
std::size_t payloadSize = 0U;
auto es = stack.read(msg, readIter, size, comms::protocol::msgPayload(payloadIter, payloadSize));
... // use payload location and size information
details::MsgPayloadRetriever< TIter > msgPayload(TIter &iter, std::size_t &len)
Add "payload start" and "payload size" output parameters to protocol stack's (frame's) "read" operati...
Definition: ProtocolLayerBase.h:1654
Parameters
[out]iterIterator pointing to the begining of the message payload in the input buffer.
[out]lenNumber of bytes in the detected payload.
Returns
Implementation dependent object accepted by "read" functions.
See also
comms::protocol::ProtocolLayerBase::read()
comms::protocol::ProtocolLayerBase::readFieldsCached()