17#include "comms/details/tag.h"
18#include "comms/protocol/details/TransportValueLayerAdapter.h"
19#include "comms/protocol/details/TransportValueLayerOptionsParser.h"
20#include "comms/protocol/details/ProtocolLayerExtendingClassHelper.h"
22COMMS_MSVC_WARNING_PUSH
23COMMS_MSVC_WARNING_DISABLE(4189)
64template <
typename TField, std::size_t TIdx,
typename TNextLayer,
typename... TOptions>
66 details::TransportValueLayerAdapterT<
70 details::ProtocolLayerExtendingClassT<
71 TransportValueLayer<TField, TIdx, TNextLayer, TOptions...>,
72 details::TransportValueLayerOptionsParser<TOptions...>
74 typename details::TransportValueLayerOptionsParser<TOptions...>::
75 template ForceReadUntilDataSplitIfNeeded<TNextLayer>
82 details::TransportValueLayerAdapterT<
86 details::ProtocolLayerExtendingClassT<
88 details::TransportValueLayerOptionsParser<TOptions...>
90 typename details::TransportValueLayerOptionsParser<TOptions...>::
91 template ForceReadUntilDataSplitIfNeeded<TNextLayer>
96 using ParsedOptionsInternal = details::TransportValueLayerOptionsParser<TOptions...>;
100 using Field =
typename BaseImpl::Field;
123 static constexpr
bool hasExtendingClass()
125 return ParsedOptionsInternal::HasExtendingClass;
132 return ParsedOptionsInternal::HasPseudoValue;
168 template <
typename TMsg,
typename TIter,
typename TNextLayerReader,
typename... TExtraValues>
174 TNextLayerReader&& nextLayerReader,
175 TExtraValues... extraValues)
177 auto es = readFieldInternal(field, msg, iter, size, ValueTag<>(), extraValues...);
182 static constexpr bool ForcedReadUntilDataSplit =
183 BaseImpl::ParsedOptions::HasForceReadUntilDataSplit;
185 if (ForcedReadUntilDataSplit) {
186 es = nextLayerReader.read(msg, iter, size, extraValues...);
193 auto& thisObj = BaseImpl::thisLayer();
194 auto* msgPtr = BaseImpl::toMsgPtr(msg);
195 bool success = thisObj.reassignFieldValueToMsg(field, msgPtr);
200 if (!ForcedReadUntilDataSplit) {
201 es = nextLayerReader.read(msg, iter, size, extraValues...);
224 template <
typename TMsg,
typename TIter,
typename TNextLayerWriter>
230 TNextLayerWriter&& nextLayerWriter)
const
232 auto& thisObj = BaseImpl::thisLayer();
233 thisObj.prepareFieldForWrite(msg, field);
235 auto es = writeFieldInternal(field, msg, iter, size, ValueTag<>());
236 if (es != ErrorStatus::Success) {
240 return nextLayerWriter.write(msg, iter, size);
248 return doFieldLengthInternal(ValueTag<>());
254 template <
typename TMsg>
257 return doFieldLength();
260#ifdef FOR_DOXYGEN_DOC_ONLY
282 template <
typename TMsg>
285 using MsgType =
typename std::decay<
decltype(msg)>::type;
286 static_assert(MsgType::hasTransportFields(),
287 "Message interface class hasn't defined transport fields, "
288 "use comms::option::def::ExtraTransportFields option.");
289 static_assert(TIdx < std::tuple_size<typename MsgType::TransportFields>::value,
290 "TIdx is too big, exceeds the amount of transport fields defined in interface class");
292 auto& allTransportFields = msg.transportFields();
293 auto& transportField = std::get<TIdx>(allTransportFields);
295 using FieldType =
typename std::decay<
decltype(transportField)>::type;
296 transportField = comms::field_cast<FieldType>(field);
311 template <
typename TMsg>
314 if (msgPtr ==
nullptr) {
318 auto& thisObj = BaseImpl::thisLayer();
319 thisObj.reassignFieldValue(*msgPtr, field);
330 template <
typename TMsg>
333 using MsgType =
typename std::decay<
decltype(msg)>::type;
334 static_assert(MsgType::hasTransportFields(),
335 "Message interface class hasn't defined transport fields, "
336 "use comms::option::def::ExtraTransportFields option.");
337 static_assert(TIdx < std::tuple_size<typename MsgType::TransportFields>::value,
338 "TIdx is too big, exceeds the amount of transport fields defined in interface class");
340 auto& transportField = std::get<TIdx>(msg.transportFields());
341 field = comms::field_cast<Field>(transportField);
346 template <
typename... TParams>
347 using PseudoValueTag = comms::details::tag::Tag1<>;
349 template <
typename... TParams>
350 using NormalValueTag = comms::details::tag::Tag2<>;
352 template <
typename...>
354 typename comms::util::LazyShallowConditional<
355 ParsedOptionsInternal::HasPseudoValue
362 template <
typename... TParams>
363 static constexpr std::size_t doFieldLengthInternal(PseudoValueTag<TParams...>)
368 template <
typename... TParams>
369 static constexpr std::size_t doFieldLengthInternal(NormalValueTag<TParams...>)
371 return BaseImpl::doFieldLength();
374 template <
typename TMsg,
typename TIter,
typename... TExtraValues>
383 static_cast<void>(msg);
384 static_cast<void>(iter);
385 static_cast<void>(len);
386 field = BaseImpl::pseudoField();
390 template <
typename TMsg,
typename TIter,
typename... TExtraValues>
397 TExtraValues... extraValues)
399 auto& thisObj = BaseImpl::thisLayer();
400 auto* msgPtr = BaseImpl::toMsgPtr(msg);
401 auto beforeReadIter = iter;
403 auto es = thisObj.doReadField(msgPtr, field, iter, len);
405 BaseImpl::updateMissingSize(field, len, extraValues...);
408 auto fieldLen =
static_cast<std::size_t
>(std::distance(beforeReadIter, iter));
414 template <
typename TMsg,
typename TIter,
typename... TParams>
420 PseudoValueTag<TParams...>)
const
422 static_cast<void>(msg);
423 static_cast<void>(iter);
424 static_cast<void>(len);
425 field = BaseImpl::pseudoField();
429 template <
typename TMsg,
typename TIter,
typename... TParams>
435 NormalValueTag<TParams...>)
const
437 auto& thisObj = BaseImpl::thisLayer();
438 auto es = thisObj.doWriteField(&msg, field, iter, len);
441 len -= field.length();
450struct TransportValueLayerCheckHelper
452 static const bool Value =
false;
455template <
typename TField, std::
size_t TIdx,
typename TNextLayer>
456struct TransportValueLayerCheckHelper<TransportValueLayer<TField, TIdx, TNextLayer> >
458 static const bool Value =
true;
469 return details::TransportValueLayerCheckHelper<T>::Value;
476COMMS_MSVC_WARNING_POP
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
Contains various compiler related definitions.
Contains definition of comms::protocol::ProtocolLayerBase.
Contains definition of various casts.
Base class for all the middle (non MsgDataLayer) protocol transport layers.
Definition ProtocolLayerBase.h:61
Protocol layer that reads a value from transport wrapping and reassigns it to appropriate "extra tran...
Definition TransportValueLayer.h:79
Field & pseudoField()
Access to pseudo field stored internally.
comms::ErrorStatus doRead(Field &field, TMsg &msg, TIter &iter, std::size_t size, TNextLayerReader &&nextLayerReader, TExtraValues... extraValues)
Customized read functionality, invoked by read().
Definition TransportValueLayer.h:169
TransportValueLayer(TransportValueLayer &&)=default
Move constructor.
static constexpr bool hasPseudoValue()
Compile time inquiry of whether the comms::option::def::PseudoValue option has been used.
Definition TransportValueLayer.h:130
~TransportValueLayer() noexcept=default
Destructor.
typename BaseImpl::Field Field
Type of the field object used to read/write "sync" value.
Definition TransportValueLayer.h:100
static std::size_t doFieldLength(const TMsg &)
Customising field length calculation.
Definition TransportValueLayer.h:255
bool reassignFieldValueToMsg(const Field &field, TMsg *msgPtr)
Re-assign the value from the input field to appropriate transport field in the message object.
Definition TransportValueLayer.h:312
comms::ErrorStatus doWrite(Field &field, const TMsg &msg, TIter &iter, std::size_t size, TNextLayerWriter &&nextLayerWriter) const
Customized write functionality, invoked by write().
Definition TransportValueLayer.h:225
TransportValueLayer()=default
Default constructor.
typename ParsedOptionsInternal::ExtendingClass ExtendingClass
Type of real extending class.
Definition TransportValueLayer.h:105
static void prepareFieldForWrite(const TMsg &msg, Field &field)
Prepare field for writing.
Definition TransportValueLayer.h:331
constexpr bool isTransportValueLayer()
Compile time check of whether the provided type is a variant of TransportValueLayer.
Definition TransportValueLayer.h:467
static constexpr std::size_t doFieldLength()
Customising field length calculation.
Definition TransportValueLayer.h:246
const Field & pseudoField() const
Const access to pseudo field stored internally.
TransportValueLayer(const TransportValueLayer &)=default
Copy constructor.
static void reassignFieldValue(TMsg &msg, const Field &field)
Re-assign the value from the input field to appropriate transport field in the message object.
Definition TransportValueLayer.h:283
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.
Replacement to some types from standard type_traits.