25#include "comms/protocol/details/ProtocolLayerBaseOptionsParser.h"
26#include "comms/protocol/details/ProtocolLayerDetails.h"
27#include "comms/details/protocol_layers_access.h"
28#include "comms/details/detect.h"
29#include "comms/details/tag.h"
31COMMS_MSVC_WARNING_PUSH
32COMMS_MSVC_WARNING_DISABLE(4100)
70 using ParsedOptions = details::ProtocolLayerBaseOptionsParser<TOptions...>;
79 std::declval<std::tuple<Field> >(),
80 std::declval<typename TNextLayer::AllFields>())
96 using MsgPtr =
typename details::ProtocolLayerMsgPtr<NextLayer>::Type;
102 static const std::size_t NumOfLayers = 1 + NextLayer::NumOfLayers;
114 template <
typename... TArgs>
116 : nextLayer_(
std::forward<TArgs>(args)...)
147 return static_cast<const ThisLayer&
>(*this);
154 return (!ParsedOptions::HasDisallowReadUntilDataSplit) && NextLayer::canSplitRead();
212 template <
typename TMsg,
typename TIter,
typename... TExtraValues>
217 TExtraValues... extraValues)
220 typename comms::util::LazyShallowConditional<
221 ParsedOptions::HasForceReadUntilDataSplit
227 static_assert(std::is_same<Tag, NormalReadTag<> >::value || canSplitRead(),
228 "Read split is disallowed by at least one of the inner layers");
229 return readInternal(msg, iter, size, Tag(), extraValues...);
256 template <
typename TMsg,
typename TIter,
typename... TExtraValues>
261 TExtraValues... extraValues)
265 auto& derivedObj =
static_cast<TDerived&
>(*this);
266 auto reader = createNextLayerUntilDataReader();
299 template <
typename TMsg,
typename TIter,
typename... TExtraValues>
304 TExtraValues... extraValues)
306 return nextLayer().readFromData(msg, iter, size, extraValues...);
334 template <
typename TAllFields,
typename TMsg,
typename TIter,
typename... TExtraValues>
336 TAllFields& allFields,
340 TExtraValues... extraValues)
342 using AllFieldsDecayed =
typename std::decay<TAllFields>::type;
343 static_assert(util::tupleIsTailOf<AllFields, AllFieldsDecayed>(),
"Passed tuple is wrong.");
344 static const std::size_t Idx =
345 std::tuple_size<AllFieldsDecayed>::value -
346 std::tuple_size<AllFields>::value;
347 auto& field = getField<Idx>(allFields);
348 auto& derivedObj =
static_cast<TDerived&
>(*this);
349 auto reader = createNextLayerCachedFieldsReader(allFields);
385 template <
typename TAllFields,
typename TMsg,
typename TIter,
typename... TExtraValues>
387 TAllFields& allFields,
391 TExtraValues... extraValues)
393 using AllFieldsDecayed =
typename std::decay<TAllFields>::type;
394 static_assert(util::tupleIsTailOf<AllFields, AllFieldsDecayed>(),
"Passed tuple is wrong.");
395 static const std::size_t Idx =
396 std::tuple_size<AllFieldsDecayed>::value -
397 std::tuple_size<AllFields>::value;
399 auto& field = getField<Idx>(allFields);
400 auto& derivedObj =
static_cast<TDerived&
>(*this);
401 auto reader = createNextLayerCachedFieldsUntilDataReader(allFields);
435 template <
typename TAllFields,
typename TMsg,
typename TIter,
typename... TExtraValues>
437 TAllFields& allFields,
441 TExtraValues... extraValues)
443 return nextLayer().readFromDataFieldsCached(allFields, msg, iter, size, extraValues...);
485 template <
typename TMsg,
typename TIter>
489 std::size_t size)
const
492 auto& derivedObj =
static_cast<const TDerived&
>(*this);
493 auto writer = createNextLayerWriter();
494 return derivedObj.doWrite(field, msg, iter, size, writer);
514 template <
typename TAllFields,
typename TMsg,
typename TIter>
516 TAllFields& allFields,
519 std::size_t size)
const
521 using AllFieldsDecayed =
typename std::decay<TAllFields>::type;
522 static_assert(util::tupleIsTailOf<AllFields, AllFieldsDecayed>(),
"Passed tuple is wrong.");
523 static const std::size_t Idx =
524 std::tuple_size<AllFieldsDecayed>::value -
525 std::tuple_size<AllFields>::value;
527 auto& field = getField<Idx>(allFields);
528 auto& derivedObj =
static_cast<const TDerived&
>(*this);
529 auto writer = createNextLayerCachedFieldsWriter(allFields);
530 return derivedObj.doWrite(field, msg, iter, size, writer);
543 return thisLayer().doFieldLength() + nextLayer_.length();
558 template <
typename TMsg>
559 constexpr std::size_t
length(
const TMsg& msg)
const
561 return thisLayer().doFieldLength(msg) + nextLayer_.length(msg);
600 template <
typename TIter>
604 auto& derivedObj =
static_cast<const TDerived&
>(*this);
605 auto updater = createNextLayerUpdater();
606 return derivedObj.doUpdate(field, iter, size, updater);
616 template <
typename TMsg,
typename TIter>
620 auto& derivedObj =
static_cast<const TDerived&
>(*this);
621 auto updater = createNextLayerUpdater();
622 return derivedObj.doUpdate(msg, field, iter, size, updater);
640 template <
typename TAllFields,
typename TIter>
642 TAllFields& allFields,
644 std::size_t size)
const
646 using AllFieldsDecayed =
typename std::decay<TAllFields>::type;
647 static_assert(util::tupleIsTailOf<AllFields, AllFieldsDecayed>(),
"Passed tuple is wrong.");
648 static const std::size_t Idx =
649 std::tuple_size<AllFieldsDecayed>::value -
650 std::tuple_size<AllFields>::value;
652 auto& field = getField<Idx>(allFields);
653 auto& derivedObj =
static_cast<const TDerived&
>(*this);
654 auto updater = createNextLayerCachedFieldsUpdater(allFields);
655 return derivedObj.doUpdate(field, iter, size, updater);
675 template <
typename TAllFields,
typename TMsg,
typename TIter>
677 TAllFields& allFields,
680 std::size_t size)
const
682 using AllFieldsDecayed =
typename std::decay<TAllFields>::type;
683 static_assert(util::tupleIsTailOf<AllFields, AllFieldsDecayed>(),
"Passed tuple is wrong.");
684 static const std::size_t Idx =
685 std::tuple_size<AllFieldsDecayed>::value -
686 std::tuple_size<AllFields>::value;
688 auto& field = getField<Idx>(allFields);
689 auto& derivedObj =
static_cast<const TDerived&
>(*this);
690 auto updater = createNextLayerCachedFieldsUpdater(allFields);
691 return derivedObj.doUpdate(msg, field, iter, size, updater);
706 template <
typename TIter,
typename TNextLayerUpdater>
711 TNextLayerUpdater&& nextLayerUpdater)
const
713 return updateInternal(field, iter, size, std::forward<TNextLayerUpdater>(nextLayerUpdater), LengthTag<>());
727 template <
typename TMsg,
typename TIter,
typename TNextLayerUpdater>
733 TNextLayerUpdater&& nextLayerUpdater)
const
735 return updateInternal(msg, field, iter, size, std::forward<TNextLayerUpdater>(nextLayerUpdater), LengthTag<>());
746 return Field::minLength();
756 template <
typename TMsg>
759 return doFieldLength();
771 template <
typename TId>
774 return nextLayer().createMsg(std::forward<TId>(
id), idx);
781 template <
typename TAllFields>
783 decltype(std::get<std::tuple_size<typename std::decay<TAllFields>::type>::value - std::tuple_size<AllFields>::value>(allFields))
785 using AllFieldsDecayed =
typename std::decay<TAllFields>::type;
786 static_assert(util::tupleIsTailOf<AllFields, AllFieldsDecayed>(),
"Passed tuple is wrong.");
787 static const std::size_t Idx =
788 std::tuple_size<AllFieldsDecayed>::value -
789 std::tuple_size<AllFields>::value;
791 return std::get<Idx>(allFields);
803 template <
typename TMsg,
typename TIter>
806 static_cast<void>(msgPtr);
807 return field.read(iter, len);
818 template <
typename TMsg,
typename TIter>
821 static_cast<void>(msgPtr);
822 return field.write(iter, len);
829 template <
typename T>
832 return comms::details::hasImplOptions<T>();
838 template <
typename TMsg>
841 resetMsgInternal(msg, MsgTypeTag<
typename std::decay<
decltype(msg)>::type>());
845 template <
typename... TParams>
846 using MessageObjTag = comms::details::tag::Tag5<>;
848 template <
typename... TParams>
849 using SmartPtrTag = comms::details::tag::Tag6<>;
851 template <
typename TMsg>
853 typename comms::util::LazyShallowConditional<
854 comms::details::hasImplOptions<TMsg>()
860 template <
typename TMsg,
typename... TParams>
861 static auto toMsgPtrInternal(TMsg& msg, MessageObjTag<TParams...>) ->
decltype(&msg)
866 template <
typename TMsg,
typename... TParams>
867 static auto toMsgPtrInternal(TMsg& msg, SmartPtrTag<TParams...>) ->
decltype(msg.get())
877 template <
typename TMsg>
878 static auto toMsgPtr(TMsg& msg) ->
decltype(toMsgPtrInternal(msg, MsgTypeTag<
typename std::decay<
decltype(msg)>::type>()))
880 return toMsgPtrInternal(msg, MsgTypeTag<
typename std::decay<
decltype(msg)>::type>());
891 template <
typename... TExtraValues>
894 return updateMissingSizeInternal(size, extraValues...);
906 template <
typename... TExtraValues>
910 TExtraValues... extraValues)
const
912 return updateMissingSizeInternal(field, size, extraValues...);
922 template <
typename... TExtraValues>
925 TExtraValues... extraValues)
const
927 return setMissingSizeInternal(val, extraValues...);
937 template <
typename TId,
typename... TExtraValues>
940 TExtraValues... extraValues)
const
942 return setMsgIdInternal(val, extraValues...);
952 template <
typename... TExtraValues>
955 TExtraValues... extraValues)
const
957 return setMsgIndexInternal(val, extraValues...);
963 template <std::
size_t TIdx,
typename TAllFields>
967 "Expected TAllFields to be a tuple");
968 static_assert(TIdx < std::tuple_size<TAllFields>::value,
969 "Invalid tuple access index");
971 auto& field = std::get<TIdx>(allFields);
973 using FieldType =
typename std::decay<
decltype(field)>::type;
975 std::is_same<Field, FieldType>::value,
976 "Field has wrong type");
982 template <
typename... TParams>
983 using FixedLengthTag = comms::details::tag::Tag1<>;
985 template <
typename... TParams>
986 using VarLengthTag = comms::details::tag::Tag2<>;
988 static constexpr std::size_t MinFieldLength = Field::minLength();
989 static constexpr std::size_t MaxFieldLength = Field::maxLength();
991 template <
typename...>
993 typename comms::util::LazyShallowConditional<
994 (MinFieldLength == MaxFieldLength)
1000 class NextLayerReader
1003 explicit NextLayerReader(NextLayer& nextLayer)
1004 : nextLayer_(nextLayer)
1008 template <
typename TMsgPtr,
typename TIter,
typename... TExtraValues>
1013 TExtraValues... extraValues)
1015 return nextLayer_.read(msg, iter, size, extraValues...);
1018 NextLayer& nextLayer_;
1021 class NextLayerUntilDataReader
1024 explicit NextLayerUntilDataReader(NextLayer& nextLayer)
1025 : nextLayer_(nextLayer)
1029 template <
typename TMsgPtr,
typename TIter,
typename... TExtraValues>
1034 TExtraValues... extraValues)
1036 return nextLayer_.readUntilData(msg, iter, size, extraValues...);
1039 NextLayer& nextLayer_;
1042 template <
typename TAllFields>
1043 class NextLayerCachedFieldsReader
1046 NextLayerCachedFieldsReader(
1047 NextLayer& nextLayer,
1048 TAllFields& allFields)
1049 : nextLayer_(nextLayer),
1050 allFields_(allFields)
1054 template<
typename TMsgPtr,
typename TIter,
typename... TExtraValues>
1059 TExtraValues... extraValues)
1061 return nextLayer_.readFieldsCached(allFields_, msg, iter, size, extraValues...);
1065 NextLayer& nextLayer_;
1066 TAllFields& allFields_;
1069 template <
typename TAllFields>
1070 class NextLayerCachedFieldsUntilDataReader
1073 NextLayerCachedFieldsUntilDataReader(
1074 NextLayer& nextLayer,
1075 TAllFields& allFields)
1076 : nextLayer_(nextLayer),
1077 allFields_(allFields)
1081 template<
typename TMsgPtr,
typename TIter,
typename... TExtraValues>
1086 TExtraValues... extraValues)
1088 return nextLayer_.readUntilDataFieldsCache(allFields_, msg, iter, size, extraValues...);
1092 NextLayer& nextLayer_;
1093 TAllFields& allFields_;
1096 class NextLayerWriter
1100 explicit NextLayerWriter(
const NextLayer& nextLayer)
1101 : nextLayer_(nextLayer)
1105 template <
typename TMsg,
typename TIter>
1106 ErrorStatus write(
const TMsg& msg, TIter& iter, std::size_t size)
const
1108 return nextLayer_.write(msg, iter, size);
1112 const NextLayer& nextLayer_;
1115 template <
typename TAllFields>
1116 class NextLayerCachedFieldsWriter
1119 NextLayerCachedFieldsWriter(
1120 const NextLayer& nextLayer,
1121 TAllFields& allFields)
1122 : nextLayer_(nextLayer),
1123 allFields_(allFields)
1127 template <
typename TMsg,
typename TIter>
1128 ErrorStatus write(
const TMsg& msg, TIter& iter, std::size_t size)
const
1130 return nextLayer_.writeFieldsCached(allFields_, msg, iter, size);
1134 const NextLayer& nextLayer_;
1135 TAllFields& allFields_;
1138 class NextLayerUpdater
1142 explicit NextLayerUpdater(
const NextLayer& nextLayer)
1143 : nextLayer_(nextLayer)
1147 template <
typename TIter>
1148 ErrorStatus update(TIter& iter, std::size_t size)
const
1150 return nextLayer_.update(iter, size);
1153 template <
typename TMsg,
typename TIter>
1154 ErrorStatus update(
const TMsg& msg, TIter& iter, std::size_t size)
const
1156 return nextLayer_.update(msg, iter, size);
1160 const NextLayer& nextLayer_;
1163 template <
typename TAllFields>
1164 class NextLayerCachedFieldsUpdater
1167 NextLayerCachedFieldsUpdater(
1168 const NextLayer& nextLayer,
1169 TAllFields& allFields)
1170 : nextLayer_(nextLayer),
1171 allFields_(allFields)
1175 template <
typename TIter>
1176 ErrorStatus update(TIter& iter, std::size_t size)
const
1178 return nextLayer_.updateFieldsCached(allFields_, iter, size);
1181 template <
typename TMsg,
typename TIter>
1182 ErrorStatus update(
const TMsg& msg, TIter& iter, std::size_t size)
const
1184 return nextLayer_.updateFieldsCached(allFields_, msg, iter, size);
1188 const NextLayer& nextLayer_;
1189 TAllFields& allFields_;
1192 NextLayerReader createNextLayerReader()
1194 return NextLayerReader(nextLayer_);
1197 NextLayerUntilDataReader createNextLayerUntilDataReader()
1199 return NextLayerUntilDataReader(nextLayer_);
1202 template <
typename TAllFields>
1203 NextLayerCachedFieldsReader<TAllFields>
1204 createNextLayerCachedFieldsReader(TAllFields& fields)
1206 return NextLayerCachedFieldsReader<TAllFields>(nextLayer_, fields);
1209 template <
typename TAllFields>
1210 NextLayerCachedFieldsUntilDataReader<TAllFields>
1211 createNextLayerCachedFieldsUntilDataReader(TAllFields& fields)
1213 return NextLayerCachedFieldsUntilDataReader<TAllFields>(nextLayer_, fields);
1216 NextLayerWriter createNextLayerWriter()
const
1218 return NextLayerWriter(nextLayer_);
1221 template <
typename TAllFields>
1222 NextLayerCachedFieldsWriter<TAllFields>
1223 createNextLayerCachedFieldsWriter(TAllFields& fields)
const
1225 return NextLayerCachedFieldsWriter<TAllFields>(nextLayer_, fields);
1228 NextLayerUpdater createNextLayerUpdater()
const
1230 return NextLayerUpdater(nextLayer_);
1233 template <
typename TAllFields>
1234 NextLayerCachedFieldsUpdater<TAllFields>
1235 createNextLayerCachedFieldsUpdater(TAllFields& fields)
const
1237 return NextLayerCachedFieldsUpdater<TAllFields>(nextLayer_, fields);
1243 template <
typename... TParams>
1244 using NormalReadTag = comms::details::tag::Tag3<>;
1246 template <
typename... TParams>
1247 using SplitReadTag = comms::details::tag::Tag4<>;
1249 template <
typename TMsg,
typename TIter,
typename... TExtraValues>
1255 TExtraValues... extraValues)
1258 auto& derivedObj =
static_cast<TDerived&
>(*this);
1259 auto reader = createNextLayerReader();
1260 return derivedObj.doRead(field, msg, iter, size, reader, extraValues...);
1263 template <
typename TMsgPtr,
typename TIter,
typename... TExtraValues>
1269 TExtraValues... extraValues)
1271 auto fromIter = iter;
1272 auto es = readUntilData(msgPtr, iter, size, extraValues...);
1277 auto consumed =
static_cast<std::size_t
>(std::distance(fromIter, iter));
1279 return readFromData(msgPtr, iter, size - consumed, extraValues...);
1282 template <
typename TIter,
typename TNextLayerUpdater,
typename... TParams>
1287 TNextLayerUpdater&& nextLayerUpdater,
1288 FixedLengthTag<TParams...>)
const
1290 auto len = field.length();
1292 std::advance(iter, len);
1293 return nextLayerUpdater.update(iter, size - len);
1296 template <
typename TIter,
typename TNextLayerUpdater,
typename... TParams>
1301 TNextLayerUpdater&& nextLayerUpdater,
1302 VarLengthTag<TParams...>)
const
1304 auto iterTmp = iter;
1305 auto es = field.read(iter, size);
1307 auto diff =
static_cast<std::size_t
>(std::distance(iterTmp, iter));
1308 es = nextLayerUpdater.update(iter, size - diff);
1313 template <
typename TMsg,
typename TIter,
typename TNextLayerUpdater,
typename... TParams>
1319 TNextLayerUpdater&& nextLayerUpdater,
1320 FixedLengthTag<TParams...>)
const
1322 auto len = field.length();
1324 std::advance(iter, len);
1325 return nextLayerUpdater.update(msg, iter, size - len);
1328 template <
typename TMsg,
typename TIter,
typename TNextLayerUpdater,
typename... TParams>
1334 TNextLayerUpdater&& nextLayerUpdater,
1335 VarLengthTag<TParams...>)
const
1337 auto iterTmp = iter;
1338 auto es = field.read(iter, size);
1340 auto diff =
static_cast<std::size_t
>(std::distance(iterTmp, iter));
1341 es = nextLayerUpdater.update(msg, iter, size - diff);
1346 template <
typename TMsg,
typename... TParams>
1347 static void resetMsgInternal(TMsg&, MessageObjTag<TParams...>)
1352 template <
typename TMsg,
typename... TParams>
1353 static void resetMsgInternal(TMsg& msg, SmartPtrTag<TParams...>)
1358 static void updateMissingSizeInternal(std::size_t size)
1360 static_cast<void>(size);
1363 static void updateMissingSizeInternal(
const Field& field, std::size_t size)
1365 static_cast<void>(field);
1366 static_cast<void>(size);
1369 template <
typename... TExtraValues>
1370 void updateMissingSizeInternal(
1372 details::MissingSizeRetriever<> retriever,
1373 TExtraValues... extraValues)
const
1376 retriever.setValue(std::max(std::size_t(1U), length() - size));
1377 updateMissingSizeInternal(size, extraValues...);
1380 template <
typename... TExtraValues>
1381 void updateMissingSizeInternal(
1384 details::MissingSizeRetriever<> retriever,
1385 TExtraValues... extraValues)
const
1388 details::isMissingSizeRetriever<
typename std::decay<
decltype(retriever)>::type>(),
1389 "Must be missing size retriever");
1390 auto totalLen = field.length() + nextLayer_.length();
1392 retriever.setValue(std::max(std::size_t(1U), totalLen - size));
1393 updateMissingSizeInternal(size, extraValues...);
1396 template <
typename T,
typename... TExtraValues>
1397 void updateMissingSizeInternal(
1400 TExtraValues... extraValues)
const
1402 static_cast<void>(retriever);
1404 !details::isMissingSizeRetriever<
typename std::decay<
decltype(retriever)>::type>(),
1405 "Mustn't be missing size retriever");
1406 updateMissingSizeInternal(size, extraValues...);
1409 template <
typename T,
typename... TExtraValues>
1410 void updateMissingSizeInternal(
1414 TExtraValues... extraValues)
const
1416 static_cast<void>(retriever);
1418 !details::isMissingSizeRetriever<
typename std::decay<
decltype(retriever)>::type>(),
1419 "Mustn't be missing size retriever");
1420 updateMissingSizeInternal(field, size, extraValues...);
1423 static void setMissingSizeInternal(std::size_t val)
1425 static_cast<void>(val);
1428 template <
typename... TExtraValues>
1429 static void setMissingSizeInternal(
1431 details::MissingSizeRetriever<> retriever,
1432 TExtraValues... extraValues)
1434 retriever.setValue(val);
1435 setMissingSizeInternal(val, extraValues...);
1438 template <
typename T,
typename... TExtraValues>
1439 static void setMissingSizeInternal(
1442 TExtraValues... extraValues)
1444 static_cast<void>(retriever);
1446 !details::isMissingSizeRetriever<
typename std::decay<
decltype(retriever)>::type>(),
1447 "Mustn't be missing size retriever");
1448 setMissingSizeInternal(val, extraValues...);
1451 template <
typename TId>
1452 static void setMsgIdInternal(TId val)
1454 static_cast<void>(val);
1457 template <
typename TId,
typename U,
typename... TExtraValues>
1458 static void setMsgIdInternal(
1460 details::MsgIdRetriever<U> retriever,
1461 TExtraValues... extraValues)
1463 retriever.setValue(val);
1464 setMsgIdInternal(val, extraValues...);
1467 template <
typename TId,
typename T,
typename... TExtraValues>
1468 static void setMsgIdInternal(
1471 TExtraValues... extraValues)
1473 static_cast<void>(retriever);
1475 !details::isMsgIdRetriever<
typename std::decay<
decltype(retriever)>::type>(),
1476 "Mustn't be message id retriever");
1477 setMsgIdInternal(val, extraValues...);
1480 static void setMsgIndexInternal(std::size_t val)
1482 static_cast<void>(val);
1485 template <
typename... TExtraValues>
1486 static void setMsgIndexInternal(
1488 details::MsgIndexRetriever retriever,
1489 TExtraValues... extraValues)
1491 retriever.setValue(val);
1492 setMsgIndexInternal(val, extraValues...);
1495 template <
typename T,
typename... TExtraValues>
1496 static void setMsgIndexInternal(
1499 TExtraValues... extraValues)
1501 static_cast<void>(retriever);
1503 !details::isMsgIndexRetriever<
typename std::decay<
decltype(retriever)>::type>(),
1504 "Mustn't be missing size retriever");
1505 setMsgIndexInternal(val, extraValues...);
1509 NextLayer nextLayer_;
1516 typename TNextLayer,
1518 typename... TOptions>
1519ProtocolLayerBase<TField, TNextLayer, TDerived, TOptions...>&
1529 typename TNextLayer,
1531 typename... TOptions>
1533const ProtocolLayerBase<TField, TNextLayer, TDerived, TOptions...>&
1563 return details::MissingSizeRetriever<>(val);
1587template <
typename TId>
1588details::MsgIdRetriever<TId>
msgId(TId& val)
1590 return details::MsgIdRetriever<TId>(val);
1628 return details::MsgIndexRetriever(val);
1653template <
typename TIter>
1654details::MsgPayloadRetriever<TIter>
msgPayload(TIter& iter, std::size_t& len)
1656 return details::MsgPayloadRetriever<TIter>(iter, len);
1669#define COMMS_PROTOCOL_LAYERS_ACCESS(...) \
1670 COMMS_DO_ACCESS_LAYER_ACC_FUNC(__VA_ARGS__)
1678#define COMMS_PROTOCOL_LAYERS_NAMES(...) \
1679 COMMS_DO_LAYER_TYPE_ALIAS(Base, __VA_ARGS__) \
1680 COMMS_DO_ACCESS_LAYER_ACC_FUNC(__VA_ARGS__)
1685#define COMMS_PROTOCOL_LAYERS_ACCESS_INNER(...) \
1686 COMMS_PROTOCOL_LAYERS_ACCESS(__VA_ARGS__)
1690#define COMMS_PROTOCOL_LAYERS_NAMES_INNER(...) \
1691 COMMS_PROTOCOL_LAYERS_NAMES(__VA_ARGS__)
1701#define COMMS_PROTOCOL_LAYERS_ACCESS_OUTER(...) \
1702 COMMS_PROTOCOL_LAYERS_ACCESS(COMMS_EXPAND(COMMS_REVERSE_MACRO_ARGS(__VA_ARGS__)))
1710#define COMMS_PROTOCOL_LAYERS_NAMES_OUTER(...) \
1711 COMMS_PROTOCOL_LAYERS_NAMES(COMMS_EXPAND(COMMS_REVERSE_MACRO_ARGS(__VA_ARGS__)))
1713COMMS_MSVC_WARNING_POP
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
Contains various compiler related definitions.
This file contain definition of error statuses used by comms module.
Contains various tuple type manipulation classes and functions.
Base class for all the middle (non MsgDataLayer) protocol transport layers.
Definition ProtocolLayerBase.h:61
ProtocolLayerBase(ProtocolLayerBase &&)=default
Move constructor.
static void resetMsg(TMsg &msg)
Reset msg in case it is a smart pointer (MsgPtr).
Definition ProtocolLayerBase.h:839
void updateMissingSize(const Field &field, std::size_t size, TExtraValues... extraValues) const
Update the missing size information if such is requested.
Definition ProtocolLayerBase.h:907
typename details::ProtocolLayerMsgPtr< NextLayer >::Type MsgPtr
Type of pointer to the message.
Definition ProtocolLayerBase.h:96
comms::ErrorStatus doUpdate(const TMsg &msg, Field &field, TIter &iter, std::size_t size, TNextLayerUpdater &&nextLayerUpdater) const
Default implementation of the "update" functaionality.
Definition ProtocolLayerBase.h:728
static comms::ErrorStatus doWriteField(const TMsg *msgPtr, const Field &field, TIter &iter, std::size_t len)
Write the layer field.
Definition ProtocolLayerBase.h:819
comms::ErrorStatus update(TIter &iter, std::size_t size) const
Update recently written (using write()) message contents data.
Definition ProtocolLayerBase.h:601
TField Field
Type of the field used for this layer.
Definition ProtocolLayerBase.h:64
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.
Definition ProtocolLayerBase.h:782
comms::ErrorStatus update(const TMsg &msg, TIter &iter, std::size_t size) const
Update recently written (using write()) message contents data.
Definition ProtocolLayerBase.h:617
MsgPtr createMsg(TId &&id, unsigned idx=0)
Create message object given the ID.
Definition ProtocolLayerBase.h:772
ProtocolLayerBase(const ProtocolLayerBase &)=default
Copy constructor.
comms::ErrorStatus readUntilData(TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues)
Perform read of data fields until data layer (message payload).
Definition ProtocolLayerBase.h:257
ProtocolLayerBase(TArgs &&... args)
Constructor.
Definition ProtocolLayerBase.h:115
comms::ErrorStatus readFromData(TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues)
Finalise the read operation by reading the message payload.
Definition ProtocolLayerBase.h:300
comms::ErrorStatus readFromDataFieldsCached(TAllFields &allFields, TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues)
Finalise the read operation by reading the message payload while caching the read transport informati...
Definition ProtocolLayerBase.h:436
details::ProtocolLayerBaseOptionsParser< TOptions... > ParsedOptions
Parsed options structure.
Definition ProtocolLayerBase.h:70
static constexpr bool canSplitRead()
Compile time check whether split read "until" and "from" data layer is allowed.
Definition ProtocolLayerBase.h:152
void setMissingSize(std::size_t val, TExtraValues... extraValues) const
Set the missing size information if such is requested.
Definition ProtocolLayerBase.h:923
constexpr std::size_t length() const
Get remaining length of wrapping transport information.
Definition ProtocolLayerBase.h:541
comms::ErrorStatus read(TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues)
Deserialise message from the input data sequence.
Definition ProtocolLayerBase.h:213
ErrorStatus updateFieldsCached(TAllFields &allFields, TIter &iter, std::size_t size) const
Update recently written (using writeFieldsCached()) message data as well as cached transport informat...
Definition ProtocolLayerBase.h:641
comms::ErrorStatus write(const TMsg &msg, TIter &iter, std::size_t size) const
Serialise message into output data sequence.
Definition ProtocolLayerBase.h:486
const NextLayer & nextLayer() const
Get "const" access to the next layer object.
Definition ProtocolLayerBase.h:133
void setMsgIndex(std::size_t val, TExtraValues... extraValues) const
Set the message index information if such is requested.
Definition ProtocolLayerBase.h:953
comms::ErrorStatus readUntilDataFieldsCached(TAllFields &allFields, TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues)
Perform read of data fields until data layer (message payload) while caching the read transport infor...
Definition ProtocolLayerBase.h:386
static comms::ErrorStatus doReadField(const TMsg *msgPtr, Field &field, TIter &iter, std::size_t len)
Read the layer field.
Definition ProtocolLayerBase.h:804
ErrorStatus updateFieldsCached(TAllFields &allFields, const TMsg &msg, TIter &iter, std::size_t size) const
Update recently written (using writeFieldsCached()) message data as well as cached transport informat...
Definition ProtocolLayerBase.h:676
void updateMissingSize(std::size_t size, TExtraValues... extraValues) const
Update the missing size information if such is requested.
Definition ProtocolLayerBase.h:892
ThisLayer & thisLayer()
Get access to this layer object.
Definition ProtocolLayerBase.h:139
static constexpr std::size_t doFieldLength()
Default implementation of field length retrieval.
Definition ProtocolLayerBase.h:744
TDerived ThisLayer
Actual derived class.
Definition ProtocolLayerBase.h:99
comms::ErrorStatus doUpdate(Field &field, TIter &iter, std::size_t size, TNextLayerUpdater &&nextLayerUpdater) const
Default implementation of the "update" functaionality.
Definition ProtocolLayerBase.h:707
typename NextLayer::AllMessages AllMessages
All supported messages.
Definition ProtocolLayerBase.h:87
static auto toMsgPtr(TMsg &msg) -> decltype(toMsgPtrInternal(msg, MsgTypeTag< typename std::decay< decltype(msg)>::type >()))
Get a pointer to the message object.
Definition ProtocolLayerBase.h:878
TNextLayer NextLayer
Type of the next transport layer.
Definition ProtocolLayerBase.h:67
typename std::decay< decltype(std::tuple_cat(std::declval< std::tuple< Field > >(), std::declval< typename TNextLayer::AllFields >())) >::type AllFields
Type of all the fields of all the transport layers wrapped in std::tuple.
Definition ProtocolLayerBase.h:82
void setMsgId(TId val, TExtraValues... extraValues) const
Set the message ID information if such is requested.
Definition ProtocolLayerBase.h:938
comms::ErrorStatus readFieldsCached(TAllFields &allFields, TMsg &msg, TIter &iter, std::size_t size, TExtraValues... extraValues)
Deserialise message from the input data sequence while caching the read transport information fields.
Definition ProtocolLayerBase.h:335
static Field & getField(TAllFields &allFields)
Retrieve reference to a layer specific field out of all fields.
Definition ProtocolLayerBase.h:964
static constexpr std::size_t doFieldLength(const TMsg &)
Default implementation of field length retrieval when message is known.
Definition ProtocolLayerBase.h:757
const ThisLayer & thisLayer() const
Get "const" access to this layer object.
Definition ProtocolLayerBase.h:145
typename NextLayer::MsgFactory MsgFactory
Type of message factory.
Definition ProtocolLayerBase.h:92
constexpr std::size_t length(const TMsg &msg) const
Get remaining length of wrapping transport information + length of the provided message.
Definition ProtocolLayerBase.h:559
comms::ErrorStatus writeFieldsCached(TAllFields &allFields, const TMsg &msg, TIter &iter, std::size_t size) const
Serialise message into output data sequence while caching the written transport information fields.
Definition ProtocolLayerBase.h:515
~ProtocolLayerBase() noexcept=default
Desctructor.
static constexpr bool isMessageObjRef()
Detect whether type is actual message object.
Definition ProtocolLayerBase.h:830
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
details::MsgIdRetriever< TId > msgId(TId &val)
Add "message ID" output parameter to protocol stack's (frame's) "read" operation.
Definition ProtocolLayerBase.h:1588
details::MsgIndexRetriever msgIndex(std::size_t &val)
Add "message index" output parameter to protocol stack's (frame's) "read" operation.
Definition ProtocolLayerBase.h:1626
details::MissingSizeRetriever missingSize(std::size_t &val)
Add "missing size" output parameter to protocol stack's (frame's) "read" operation.
Definition ProtocolLayerBase.h:1561
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.
Contains definition of all the options used by the COMMS library.
Check whether provided type is a variant of std::tuple.
Definition Tuple.h:36
Replacement to some types from standard type_traits.