14#include "comms/protocol/details/ProtocolLayerBase.h"
15#include "comms/protocol/details/SyncPrefixLayerOptionsParser.h"
16#include "comms/protocol/details/ProtocolLayerExtendingClassHelper.h"
18COMMS_MSVC_WARNING_PUSH
19COMMS_MSVC_WARNING_DISABLE(4189)
42template <
typename TField,
typename TNextLayer,
typename... TOptions>
47 details::ProtocolLayerExtendingClassT<
48 SyncPrefixLayer<TField, TNextLayer, TOptions...>,
49 details::SyncPrefixLayerOptionsParser<TOptions...>
57 details::ProtocolLayerExtendingClassT<
59 details::SyncPrefixLayerOptionsParser<TOptions...>
63 using ParsedOptionsInternal = details::SyncPrefixLayerOptionsParser<TOptions...>;
90 static constexpr
bool hasExtendingClass()
92 return ParsedOptionsInternal::HasExtendingClass;
123 template <
typename TMsg,
typename TIter,
typename TNextLayerReader,
typename... TExtraValues>
129 TNextLayerReader&& nextLayerReader,
130 TExtraValues... extraValues)
132 auto& thisObj = BaseImpl::thisLayer();
133 auto* msgPtr = BaseImpl::toMsgPtr(msg);
134 auto beforeReadIter = iter;
136 auto es = thisObj.doReadField(msgPtr, field, iter, size);
138 BaseImpl::updateMissingSize(field, size, extraValues...);
145 bool verified = thisObj.verifyFieldValue(field);
150 auto fieldLen =
static_cast<std::size_t
>(std::distance(beforeReadIter, iter));
151 return nextLayerReader.read(msg, iter, size - fieldLen, extraValues...);
171 template <
typename TMsg,
typename TIter,
typename TNextLayerWriter>
177 TNextLayerWriter&& nextLayerWriter)
const
179 auto& thisObj = BaseImpl::thisLayer();
180 thisObj.prepareFieldForWrite(field);
181 auto es = thisObj.doWriteField(&msg, field, iter, size);
182 if (es != ErrorStatus::Success) {
187 return nextLayerWriter.write(msg, iter, size - field.length());
199 return field ==
Field();
211 static_cast<void>(field);
218struct SyncPrefixLayerCheckHelper
220 static const bool Value =
false;
223template <
typename TField,
typename TNextLayer>
224struct SyncPrefixLayerCheckHelper<SyncPrefixLayer<TField, TNextLayer> >
226 static const bool Value =
true;
237 return details::SyncPrefixLayerCheckHelper<T>::Value;
244COMMS_MSVC_WARNING_POP
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
Contains various compiler related definitions.
Base class for all the middle (non MsgDataLayer) protocol transport layers.
Definition ProtocolLayerBase.h:61
TField Field
Type of the field used for this layer.
Definition ProtocolLayerBase.h:64
Protocol layer that uses "sync" field as a prefix to all the subsequent data written by other (next) ...
Definition SyncPrefixLayer.h:52
SyncPrefixLayer(const SyncPrefixLayer &)=default
Copy constructor.
typename ParsedOptionsInternal::ExtendingClass ExtendingClass
Type of real extending class.
Definition SyncPrefixLayer.h:72
typename BaseImpl::Field Field
Type of the field object used to read/write "sync" value.
Definition SyncPrefixLayer.h:67
constexpr bool isSyncPrefixLayer()
Compile time check of whether the provided type is a variant of SyncPrefixLayer.
Definition SyncPrefixLayer.h:235
comms::ErrorStatus doWrite(Field &field, const TMsg &msg, TIter &iter, std::size_t size, TNextLayerWriter &&nextLayerWriter) const
Customized write functionality, invoked by write().
Definition SyncPrefixLayer.h:172
static bool verifyFieldValue(const Field &field)
Verify the validity of the field.
Definition SyncPrefixLayer.h:197
SyncPrefixLayer()=default
Default constructor.
comms::ErrorStatus doRead(Field &field, TMsg &msg, TIter &iter, std::size_t size, TNextLayerReader &&nextLayerReader, TExtraValues... extraValues)
Customized read functionality, invoked by read().
Definition SyncPrefixLayer.h:124
SyncPrefixLayer(SyncPrefixLayer &&)=default
Move constructor.
~SyncPrefixLayer() noexcept=default
Destructor.
static void prepareFieldForWrite(Field &field)
Prepare field for writing.
Definition SyncPrefixLayer.h:209
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
@ Success
Used to indicate successful outcome of the operation.