Go to the documentation of this file.
15 #ifndef _FASTCDR_CDRSIZECALCULATOR_HPP_
16 #define _FASTCDR_CDRSIZECALCULATOR_HPP_
38 class CdrSizeCalculator;
92 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>::type* =
nullptr,
typename =
void>
95 size_t& current_alignment)
108 typename std::enable_if<std::is_enum<_T>::value>::type* =
nullptr,
110 int32_t>::value>::type* =
nullptr>
113 size_t& current_alignment)
126 typename std::enable_if<std::is_enum<_T>::value>::type* =
nullptr,
128 uint32_t>::value>::type* =
nullptr>
131 size_t& current_alignment)
144 typename std::enable_if<std::is_enum<_T>::value>::type* =
nullptr,
146 int16_t>::value>::type* =
nullptr>
149 size_t& current_alignment)
162 typename std::enable_if<std::is_enum<_T>::value>::type* =
nullptr,
164 uint16_t>::value>::type* =
nullptr>
167 size_t& current_alignment)
180 typename std::enable_if<std::is_enum<_T>::value>::type* =
nullptr,
182 int8_t>::value>::type* =
nullptr>
185 size_t& current_alignment)
198 typename std::enable_if<std::is_enum<_T>::value>::type* =
nullptr,
200 uint8_t>::value>::type* =
nullptr>
203 size_t& current_alignment)
217 size_t& current_alignment)
219 static_cast<void>(
data);
233 size_t& current_alignment)
235 static_cast<void>(
data);
249 size_t& current_alignment)
251 static_cast<void>(
data);
265 size_t& current_alignment)
267 static_cast<void>(
data);
281 size_t& current_alignment)
283 static_cast<void>(
data);
284 size_t calculated_size {2 +
alignment(current_alignment, 2)};
285 current_alignment += calculated_size;
286 return calculated_size;
298 size_t& current_alignment)
300 static_cast<void>(
data);
301 size_t calculated_size {2 +
alignment(current_alignment, 2)};
302 current_alignment += calculated_size;
303 return calculated_size;
314 const uint16_t&
data,
315 size_t& current_alignment)
317 static_cast<void>(
data);
318 size_t calculated_size {2 +
alignment(current_alignment, 2)};
319 current_alignment += calculated_size;
320 return calculated_size;
332 size_t& current_alignment)
334 static_cast<void>(
data);
335 size_t calculated_size {4 +
alignment(current_alignment, 4)};
336 current_alignment += calculated_size;
337 return calculated_size;
348 const uint32_t&
data,
349 size_t& current_alignment)
351 static_cast<void>(
data);
352 size_t calculated_size {4 +
alignment(current_alignment, 4)};
353 current_alignment += calculated_size;
354 return calculated_size;
366 size_t& current_alignment)
368 static_cast<void>(
data);
370 current_alignment += calculated_size;
371 return calculated_size;
382 const uint64_t&
data,
383 size_t& current_alignment)
385 static_cast<void>(
data);
387 current_alignment += calculated_size;
388 return calculated_size;
400 size_t& current_alignment)
402 static_cast<void>(
data);
403 size_t calculated_size {4 +
alignment(current_alignment, 4)};
404 current_alignment += calculated_size;
405 return calculated_size;
417 size_t& current_alignment)
419 static_cast<void>(
data);
421 current_alignment += calculated_size;
422 return calculated_size;
433 const long double&
data,
434 size_t& current_alignment)
436 static_cast<void>(
data);
438 current_alignment += calculated_size;
439 return calculated_size;
450 const std::string&
data,
451 size_t& current_alignment)
453 size_t calculated_size {4 +
alignment(current_alignment, 4) +
data.size() + 1};
454 current_alignment += calculated_size;
457 return calculated_size;
468 const std::wstring&
data,
469 size_t& current_alignment)
471 size_t calculated_size {4 +
alignment(current_alignment, 4) +
data.size() * 2};
472 current_alignment += calculated_size;
474 return calculated_size;
483 template <
size_t MAX_CHARS>
486 size_t& current_alignment)
488 size_t calculated_size {4 +
alignment(current_alignment, 4) +
data.size() + 1};
489 current_alignment += calculated_size;
491 return calculated_size;
500 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
501 !std::is_arithmetic<_T>::value>::type* =
nullptr>
503 const std::vector<_T>&
data,
504 size_t& current_alignment)
506 size_t initial_alignment {current_alignment};
511 current_alignment += 4 +
alignment(current_alignment, 4);
514 current_alignment += 4 +
alignment(current_alignment, 4);
516 size_t calculated_size {current_alignment - initial_alignment};
525 return calculated_size;
534 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
535 std::is_arithmetic<_T>::value>::type* =
nullptr>
537 const std::vector<_T>&
data,
538 size_t& current_alignment)
540 size_t initial_alignment {current_alignment};
542 current_alignment += 4 +
alignment(current_alignment, 4);
544 size_t calculated_size {current_alignment - initial_alignment};
549 serialized_member_size_ = get_serialized_member_size<_T>();
552 return calculated_size;
563 const std::vector<bool>&
data,
564 size_t& current_alignment)
566 size_t calculated_size {
data.size() + 4 +
alignment(current_alignment, 4)};
567 current_alignment += calculated_size;
569 return calculated_size;
578 template<
class _T,
size_t _Size>
580 const std::array<_T, _Size>&
data,
581 size_t& current_alignment)
583 size_t initial_alignment {current_alignment};
589 current_alignment += 4 +
alignment(current_alignment, 4);
592 size_t calculated_size {current_alignment - initial_alignment};
602 return calculated_size;
611 template<class _K, class _V, typename std::enable_if<!std::is_enum<_V>::value &&
612 !std::is_arithmetic<_V>::value>::type* =
nullptr>
614 const std::map<_K, _V>&
data,
615 size_t& current_alignment)
617 size_t initial_alignment {current_alignment};
622 current_alignment += 4 +
alignment(current_alignment, 4);
625 current_alignment += 4 +
alignment(current_alignment, 4);
627 size_t calculated_size {current_alignment - initial_alignment};
628 for (
auto it =
data.begin(); it !=
data.end(); ++it)
640 return calculated_size;
649 template<class _K, class _V, typename std::enable_if<std::is_enum<_V>::value ||
650 std::is_arithmetic<_V>::value>::type* =
nullptr>
652 const std::map<_K, _V>&
data,
653 size_t& current_alignment)
655 size_t initial_alignment {current_alignment};
657 current_alignment += 4 +
alignment(current_alignment, 4);
659 size_t calculated_size {current_alignment - initial_alignment};
660 for (
auto it =
data.begin(); it !=
data.end(); ++it)
666 return calculated_size;
675 template<
size_t N,
typename std::enable_if < (N < 9) > ::type* =
nullptr>
676 size_t calculate_serialized_size(
677 const std::bitset<N>& data,
678 size_t& current_alignment)
680 static_cast<
void>(data);
691 template<
size_t N,
typename std::enable_if < (8 < N && N < 17) > ::type* =
nullptr>
692 size_t calculate_serialized_size(
693 const std::bitset<N>& data,
694 size_t& current_alignment)
696 static_cast<
void>(data);
697 size_t calculated_size {2 + alignment(current_alignment, 2)};
698 current_alignment += calculated_size;
699 return calculated_size;
708 template<
size_t N,
typename std::enable_if < (16 < N && N < 33) > ::type* =
nullptr>
709 size_t calculate_serialized_size(
710 const std::bitset<N>& data,
711 size_t& current_alignment)
713 static_cast<
void>(data);
714 size_t calculated_size {4 + alignment(current_alignment, 4)};
715 current_alignment += calculated_size;
716 return calculated_size;
725 template<
size_t N,
typename std::enable_if < (32 < N && N < 65) > ::type* =
nullptr>
726 size_t calculate_serialized_size(
727 const std::bitset<N>& data,
728 size_t& current_alignment)
730 static_cast<
void>(data);
731 size_t calculated_size {8 + alignment(current_alignment, align64_)};
732 current_alignment += calculated_size;
733 return calculated_size;
745 size_t& current_alignment)
747 size_t initial_alignment = current_alignment;
756 size_t calculated_size {current_alignment - initial_alignment};
758 if (
data.has_value())
763 return calculated_size;
776 size_t& current_alignment)
798 size_t& current_alignment)
800 size_t calculated_size {0};
802 for (
size_t count = 0; count < num_elements; ++count)
807 return calculated_size;
821 size_t& current_alignment)
823 static_cast<void>(
data);
824 current_alignment += num_elements;
839 size_t& current_alignment)
841 static_cast<void>(
data);
842 current_alignment += num_elements;
857 size_t& current_alignment)
859 static_cast<void>(
data);
860 current_alignment += num_elements;
875 size_t& current_alignment)
877 static_cast<void>(
data);
878 size_t calculated_size {num_elements* 2 +
alignment(current_alignment, 2)};
879 current_alignment += calculated_size;
880 return calculated_size;
894 size_t& current_alignment)
896 static_cast<void>(
data);
897 size_t calculated_size {num_elements* 2 +
alignment(current_alignment, 2)};
898 current_alignment += calculated_size;
899 return calculated_size;
911 const uint16_t*
data,
913 size_t& current_alignment)
915 static_cast<void>(
data);
916 size_t calculated_size {num_elements* 2 +
alignment(current_alignment, 2)};
917 current_alignment += calculated_size;
918 return calculated_size;
932 size_t& current_alignment)
934 static_cast<void>(
data);
935 size_t calculated_size {num_elements* 4 +
alignment(current_alignment, 4)};
936 current_alignment += calculated_size;
937 return calculated_size;
949 const uint32_t*
data,
951 size_t& current_alignment)
953 static_cast<void>(
data);
954 size_t calculated_size {num_elements* 4 +
alignment(current_alignment, 4)};
955 current_alignment += calculated_size;
956 return calculated_size;
970 size_t& current_alignment)
972 static_cast<void>(
data);
973 size_t calculated_size {num_elements* 8 +
alignment(current_alignment,
align64_)};
974 current_alignment += calculated_size;
975 return calculated_size;
987 const uint64_t*
data,
989 size_t& current_alignment)
991 static_cast<void>(
data);
992 size_t calculated_size {num_elements* 8 +
alignment(current_alignment,
align64_)};
993 current_alignment += calculated_size;
994 return calculated_size;
1007 size_t num_elements,
1008 size_t& current_alignment)
1010 static_cast<void>(
data);
1011 size_t calculated_size {num_elements* 4 +
alignment(current_alignment, 4)};
1012 current_alignment += calculated_size;
1013 return calculated_size;
1026 size_t num_elements,
1027 size_t& current_alignment)
1029 static_cast<void>(
data);
1030 size_t calculated_size {num_elements* 8 +
alignment(current_alignment,
align64_)};
1031 current_alignment += calculated_size;
1032 return calculated_size;
1044 const long double*
data,
1045 size_t num_elements,
1046 size_t& current_alignment)
1048 static_cast<void>(
data);
1049 size_t calculated_size {num_elements* 16 +
alignment(current_alignment,
align64_)};
1050 current_alignment += calculated_size;
1051 return calculated_size;
1061 template<
class _T,
size_t _N>
1063 const std::array<_T, _N>*
data,
1064 size_t num_elements,
1065 size_t& current_alignment)
1076 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1077 std::is_arithmetic<_T>::value>::type* =
nullptr>
1079 const std::vector<_T>&
data,
1080 size_t& current_alignment)
1091 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1092 !std::is_arithmetic<_T>::value>::type* =
nullptr>
1094 const std::vector<_T>&
data,
1095 size_t& current_alignment)
1097 size_t initial_alignment {current_alignment};
1102 current_alignment += 4 +
alignment(current_alignment, 4);
1105 size_t calculated_size {current_alignment - initial_alignment};
1114 return calculated_size;
1125 const std::vector<bool>&
data,
1126 size_t& current_alignment)
1128 current_alignment +=
data.size();
1144 size_t& current_alignment)
1146 size_t initial_alignment {current_alignment};
1152 current_alignment +=
alignment(current_alignment, 4);
1155 size_t prev_size {current_alignment - initial_alignment};
1156 size_t extra_size {0};
1160 current_alignment = 0;
1166 0 < calculated_size)
1169 if (8 < calculated_size)
1174 calculated_size -= 4;
1183 0 < calculated_size)
1187 if (0x3F00 < id.id || calculated_size > std::numeric_limits<uint16_t>::max())
1194 calculated_size += prev_size + extra_size;
1197 current_alignment += extra_size;
1202 return calculated_size;
1217 size_t& current_alignment)
1219 size_t initial_alignment = current_alignment;
1227 current_alignment +=
alignment(current_alignment, 4);
1231 size_t prev_size = {current_alignment - initial_alignment};
1232 size_t extra_size {0};
1237 current_alignment = 0;
1243 0 < calculated_size)
1245 if (8 < calculated_size)
1263 if (0x3F00 < id.id || calculated_size > std::numeric_limits<uint16_t>::max())
1270 calculated_size += prev_size + extra_size;
1273 current_alignment += extra_size;
1277 return calculated_size;
1288 size_t& current_alignment);
1298 size_t& current_alignment);
1322 size_t current_alignment,
1323 size_t data_size)
const
1325 return (data_size - (current_alignment % data_size)) & (data_size - 1);
1328 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1329 std::is_arithmetic<_T>::value>::type* =
nullptr>
1342 #endif // _FASTCDR_CDRSIZECALCULATOR_HPP_
TEMPLATE_SPEC size_t calculate_array_serialized_size(const uint8_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of uint8_t.
size_t calculate_serialized_size(const std::map< _K, _V > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a map of non-primitives.
EncodingAlgorithmFlag current_encoding_
This class is thrown as an exception when an invalid parameter is being serialized.
size_t calculate_serialized_size(const std::array< _T, _Size > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array.
Cdr_DllAPI EncodingAlgorithmFlag get_encoding() const
Retrieves the current encoding algorithm used by the instance.
@ NO_SERIALIZED_MEMBER_SIZE
TEMPLATE_SPEC size_t calculate_serialized_size(const double &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a double.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const int32_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of int32_t.
@ SERIALIZED_MEMBER_SIZE_4
TEMPLATE_SPEC size_t calculate_array_serialized_size(const wchar_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of wchar.
Cdr_DllAPI size_t begin_calculate_type_serialized_size(EncodingAlgorithmFlag new_encoding, size_t ¤t_alignment)
Indicates a new constructed type will be calculated.
size_t calculate_member_serialized_size(const MemberId &id, const _T &data, size_t ¤t_alignment)
Generic template which calculates the encoded size of the constructed type's member of a unknown type...
TEMPLATE_SPEC size_t calculate_serialized_size(const int8_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an int8_t.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const double *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of double.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const uint32_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of uint32_t.
Cdr_DllAPI size_t end_calculate_type_serialized_size(EncodingAlgorithmFlag new_encoding, size_t ¤t_alignment)
Indicates the ending of a constructed type.
TEMPLATE_SPEC size_t calculate_serialized_size(const int64_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a int64_t.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const int64_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of int64_t.
@ PL_CDR
Specifies that the content is PL_CDR,.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const long double *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of long double.
size_t calculate_serialized_size(const optional< _T > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an optional type.
TEMPLATE_SPEC size_t calculate_serialized_size(const long double &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a long double.
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
TEMPLATE_SPEC size_t calculate_serialized_size(const std::wstring &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a std::wstring.
TEMPLATE_SPEC size_t calculate_serialized_size(const uint32_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a uint32_t.
size_t alignment(size_t current_alignment, size_t data_size) const
TEMPLATE_SPEC size_t calculate_serialized_size(const std::vector< bool > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a sequence of bool.
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the version of the encoding algorithm used by the instance.
TEMPLATE_SPEC size_t calculate_serialized_size(const bool &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a bool.
size_t calculate_serialized_size(CdrSizeCalculator &, const _T &, size_t &)
size_t calculate_array_serialized_size(const std::array< _T, _N > *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a multi-dimensional array.
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
TEMPLATE_SPEC size_t calculate_serialized_size(const float &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a float.
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
size_t calculate_array_serialized_size(const std::vector< _T > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an std::vector of primitives as an array.
CdrSizeCalculator()=delete
TEMPLATE_SPEC size_t calculate_serialized_size(const uint64_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a uint64_t.
size_t calculate_array_serialized_size(const _T *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of unknown type.
This class template manages an external member, a member declared to be external to the storage of a ...
size_t calculate_serialized_size(const _T &data, size_t ¤t_alignment)
Generic template which calculates the encoded size of an instance of an unknown type.
constexpr SerializedMemberSizeForNextInt get_serialized_member_size() const
TEMPLATE_SPEC size_t calculate_serialized_size(const std::string &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a std::string.
size_t calculate_member_serialized_size(const MemberId &id, const optional< _T > &data, size_t ¤t_alignment)
Generic template which calculates the encoded size of the constructed type's member of type optional.
This class template manages an optional contained value, i.e. a value that may or may not be present.
constexpr bool is_multi_array_primitive(...)
Basis.
@ SERIALIZED_MEMBER_SIZE_8
TEMPLATE_SPEC size_t calculate_array_serialized_size(const char *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of char.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const uint64_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of uint64_t.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const int16_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of int16_t.
TEMPLATE_SPEC size_t calculate_serialized_size(const int32_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a int32_t.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const uint16_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of uint16_t.
size_t calculate_serialized_size(const external< _T > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an external type.
size_t calculate_serialized_size(const std::vector< _T > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a sequence of non-primitives.
TEMPLATE_SPEC size_t calculate_serialized_size(const uint16_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a uint16_t.
@ XCDRv1
XCDRv1 encoding defined by standard DDS X-Types 1.3.
TEMPLATE_SPEC size_t calculate_serialized_size(const int16_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a int16_t.
TEMPLATE_SPEC size_t calculate_serialized_size(const char &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a char.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const float *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of float.
size_t align64_
Align for types equal or greater than 64bits.
Template class for non-alloc strings.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const int8_t *data, size_t num_elements, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an array of int8_t.
size_t calculate_serialized_size(const fixed_string< MAX_CHARS > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a fixed_string.
enum eprosima::fastcdr::CdrSizeCalculator::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to calculate XCDRv2 member headers.
@ PL_CDR2
Specifies that the content is PL_CDR2.
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
TEMPLATE_SPEC size_t calculate_serialized_size(const uint8_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of an uint8_t.
TEMPLATE_SPEC size_t calculate_array_serialized_size(const std::vector< bool > &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an std::vector of bool as an array.
TEMPLATE_SPEC size_t calculate_serialized_size(const wchar_t &data, size_t ¤t_alignment)
Specific template which calculates the encoded size of an instance of a wchar.
SerializedMemberSizeForNextInt
This class offers an interface to calculate the encoded size of a type serialized using a support enc...
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43