23using namespace exception;
25#if FASTCDR_IS_BIG_ENDIAN_TARGET
36constexpr uint8_t
operator ""_8u(
37 unsigned long long int value)
39 return static_cast<uint8_t
>(value);
47 return (data_size - ((offset - origin) % data_size)) & (data_size - 1);
53 uint32_t lc {0x40000000};
55 switch (serialized_member_size)
74 size_t member_serialized_size)
76 uint32_t lc {0xFFFFFFFFu};
77 switch (member_serialized_size)
100 : offset_(cdr.offset_)
101 , origin_(cdr.origin_)
102 , swap_bytes_(cdr.swap_bytes_)
103 , last_data_size_(cdr.last_data_size_)
104 , next_member_id_(cdr.next_member_id_)
105 , previous_encoding_(cdr.current_encoding_)
110 const state& current_state)
116 , previous_encoding_(current_state.previous_encoding_)
143 ,
end_(cdr_buffer.end())
201 uint8_t encapsulation {0};
202 state state_before_error(*
this);
212 throw BadParamException(
"Unexpected non-zero initial byte received in Cdr::read_encapsulation");
217 (*this) >> encapsulation;
221 const uint8_t
endianness = encapsulation & 0x1_8u;
229 const uint8_t encoding_flag = encapsulation &
static_cast<uint8_t
>(~0x1);
230 switch (encoding_flag)
243 "Unexpected encoding algorithm received in Cdr::read_encapsulation. XCDRv2 should be selected.");
255 "Unexpected encoding algorithm received in Cdr::read_encapsulation. XCDRv1 should be selected");
266 throw BadParamException(
"Unexpected encoding algorithm received in Cdr::read_encapsulation for DDS CDR");
277 uint8_t option_align {
static_cast<uint8_t
>(
options_[1] & 0x3u)};
279 if (0 < option_align)
282 auto alignment = ((length + 3u) & ~3u) - length;
286 end_ -= option_align;
305 uint8_t encapsulation = 0;
306 state state_before_error(*
this);
320 (*this) << encapsulation;
361 bool ret_value =
false;
389 auto alignment = ((length + 3u) & ~3u) - length;
395 state previous_state(*
this);
423 bool ret_value =
false;
456 const state& current_state)
481 bool ret_value =
false;
508 const uint8_t& octet_t)
510 return serialize(
static_cast<char>(octet_t));
531 return serialize(
static_cast<char>(int8));
535 const uint16_t ushort_t)
537 return serialize(
static_cast<int16_t
>(ushort_t));
541 const int16_t short_t)
543 size_t align =
alignment(
sizeof(short_t));
544 size_t size_aligned =
sizeof(short_t) + align;
556 const char* dst =
reinterpret_cast<const char*
>(&short_t);
574 const uint32_t ulong_t)
576 return serialize(
static_cast<int32_t
>(ulong_t));
580 const int32_t long_t)
582 size_t align =
alignment(
sizeof(long_t));
583 size_t size_aligned =
sizeof(long_t) + align;
595 const char* dst =
reinterpret_cast<const char*
>(&long_t);
617 return serialize(
static_cast<uint16_t
>(wchar));
621 const uint64_t ulonglong_t)
623 return serialize(
static_cast<int64_t
>(ulonglong_t));
627 const int64_t longlong_t)
630 size_t size_aligned =
sizeof(longlong_t) + align;
642 const char* dst =
reinterpret_cast<const char*
>(&longlong_t);
668 size_t align =
alignment(
sizeof(float_t));
669 size_t size_aligned =
sizeof(float_t) + align;
681 const char* dst =
reinterpret_cast<const char*
>(&float_t);
701 const double double_t)
704 size_t size_aligned =
sizeof(double_t) + align;
716 const char* dst =
reinterpret_cast<const char*
>(&double_t);
740 const long double ldouble_t)
743 size_t size_aligned =
sizeof(ldouble_t) + align;
755#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
756 __float128 tmp = ldouble_t;
757 const char* dst =
reinterpret_cast<const char*
>(&tmp);
759 const char* dst =
reinterpret_cast<const char*
>(&ldouble_t);
761#if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
779#if FASTCDR_SIZEOF_LONG_DOUBLE == 8
781 offset_++ <<
static_cast<char>(0);
782 offset_++ <<
static_cast<char>(0);
783 offset_++ <<
static_cast<char>(0);
784 offset_++ <<
static_cast<char>(0);
785 offset_++ <<
static_cast<char>(0);
786 offset_++ <<
static_cast<char>(0);
787 offset_++ <<
static_cast<char>(0);
788 offset_++ <<
static_cast<char>(0);
798#error unsupported long double type and no __float128 available
804#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
805 __float128 tmp = ldouble_t;
809#if FASTCDR_SIZEOF_LONG_DOUBLE == 8
810 offset_ << static_cast<long double>(0);
813#if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
817#error unsupported long double type and no __float128 available
838 offset_++ <<
static_cast<uint8_t
>(1);
842 offset_++ <<
static_cast<uint8_t
>(0);
854 return serialize(
static_cast<const char*
>(string_t));
858 const char* string_t)
862 if (string_t !=
nullptr)
897 const wchar_t* string_t)
899 uint32_t bytes_length = 0;
902 if (string_t !=
nullptr)
904 wstrlen = wcslen(string_t);
908 if (bytes_length > 0)
935 size_t total_size =
sizeof(*bool_t) * num_elements;
942 for (
size_t count = 0; count < num_elements; ++count)
963 size_t total_size =
sizeof(*char_t) * num_elements;
979 const int16_t* short_t,
982 if (num_elements == 0)
987 size_t align =
alignment(
sizeof(*short_t));
988 size_t total_size =
sizeof(*short_t) * num_elements;
989 size_t size_aligned = total_size + align;
1004 const char* dst =
reinterpret_cast<const char*
>(short_t);
1005 const char* end = dst + total_size;
1007 for (; dst < end; dst +=
sizeof(*short_t))
1026 const int32_t* long_t,
1027 size_t num_elements)
1029 if (num_elements == 0)
1034 size_t align =
alignment(
sizeof(*long_t));
1035 size_t total_size =
sizeof(*long_t) * num_elements;
1036 size_t size_aligned = total_size + align;
1051 const char* dst =
reinterpret_cast<const char*
>(long_t);
1052 const char* end = dst + total_size;
1054 for (; dst < end; dst +=
sizeof(*long_t))
1075 const wchar_t* wchar,
1076 size_t num_elements)
1078 if (num_elements == 0)
1083 for (
size_t count = 0; count < num_elements; ++count)
1091 const int64_t* longlong_t,
1092 size_t num_elements)
1094 if (num_elements == 0)
1100 size_t total_size =
sizeof(*longlong_t) * num_elements;
1101 size_t size_aligned = total_size + align;
1116 const char* dst =
reinterpret_cast<const char*
>(longlong_t);
1117 const char* end = dst + total_size;
1119 for (; dst < end; dst +=
sizeof(*longlong_t))
1144 const float* float_t,
1145 size_t num_elements)
1147 if (num_elements == 0)
1152 size_t align =
alignment(
sizeof(*float_t));
1153 size_t total_size =
sizeof(*float_t) * num_elements;
1154 size_t size_aligned = total_size + align;
1169 const char* dst =
reinterpret_cast<const char*
>(float_t);
1170 const char* end = dst + total_size;
1172 for (; dst < end; dst +=
sizeof(*float_t))
1193 const double* double_t,
1194 size_t num_elements)
1196 if (num_elements == 0)
1202 size_t total_size =
sizeof(*double_t) * num_elements;
1203 size_t size_aligned = total_size + align;
1218 const char* dst =
reinterpret_cast<const char*
>(double_t);
1219 const char* end = dst + total_size;
1221 for (; dst < end; dst +=
sizeof(*double_t))
1246 const long double* ldouble_t,
1247 size_t num_elements)
1249 if (num_elements == 0)
1256 size_t total_size = 16 * num_elements;
1257 size_t size_aligned = total_size + align;
1270#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1273 for (
size_t i = 0; i < num_elements; ++i, ++ldouble_t)
1275 __float128 tmp = *ldouble_t;
1276 const char* dst =
reinterpret_cast<const char*
>(&tmp);
1297 for (
size_t i = 0; i < num_elements; ++i, ++ldouble_t)
1299 __float128 tmp = *ldouble_t;
1305#if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1308 const char* dst =
reinterpret_cast<const char*
>(ldouble_t);
1309 const char* end = dst + total_size;
1311 for (; dst < end; dst +=
sizeof(*ldouble_t))
1313#if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1323 offset_++ <<
static_cast<char>(0);
1324 offset_++ <<
static_cast<char>(0);
1325 offset_++ <<
static_cast<char>(0);
1326 offset_++ <<
static_cast<char>(0);
1327 offset_++ <<
static_cast<char>(0);
1328 offset_++ <<
static_cast<char>(0);
1329 offset_++ <<
static_cast<char>(0);
1330 offset_++ <<
static_cast<char>(0);
1344#if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1348 for (
size_t i = 0; i < num_elements; ++i)
1350 offset_ << static_cast<long double>(0);
1358#error unsupported long double type and no __float128 available
1386 size_t align =
alignment(
sizeof(short_t));
1387 size_t size_aligned =
sizeof(short_t) + align;
1399 char* dst =
reinterpret_cast<char*
>(&short_t);
1419 size_t align =
alignment(
sizeof(long_t));
1420 size_t size_aligned =
sizeof(long_t) + align;
1432 char* dst =
reinterpret_cast<char*
>(&long_t);
1452 int64_t& longlong_t)
1455 size_t size_aligned =
sizeof(longlong_t) + align;
1467 char* dst =
reinterpret_cast<char*
>(&longlong_t);
1481 offset_ +=
sizeof(longlong_t);
1493 size_t align =
alignment(
sizeof(float_t));
1494 size_t size_aligned =
sizeof(float_t) + align;
1506 char* dst =
reinterpret_cast<char*
>(&float_t);
1529 size_t size_aligned =
sizeof(double_t) + align;
1541 char* dst =
reinterpret_cast<char*
>(&double_t);
1565 long double& ldouble_t)
1568 size_t size_aligned =
sizeof(ldouble_t) + align;
1580#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1581 __float128 tmp = ldouble_t;
1582 char* dst =
reinterpret_cast<char*
>(&tmp);
1584 char* dst =
reinterpret_cast<char*
>(&ldouble_t);
1586#if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1603#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1604 ldouble_t =
static_cast<long double>(tmp);
1607#if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1618#error unsupported long double type and no __float128 available
1624#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1628 ldouble_t =
static_cast<long double>(tmp);
1630#if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1631#if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1663 else if (value == 0)
1669 throw BadParamException(
"Unexpected byte value in Cdr::deserialize(bool), expected 0 or 1");
1678 uint32_t length = 0;
1695 reinterpret_cast<char*
>(calloc(length + ((&
offset_)[length - 1] ==
'\0' ? 0 : 1),
1697 memcpy(string_t, &
offset_, length);
1709 uint32_t length = 0;
1724 string_t =
reinterpret_cast<wchar_t*
>(calloc(length + 1,
sizeof(
wchar_t)));
1738 const char* ret_value =
"";
1739 state state_before_error(*
this);
1754 if (ret_value[length - 1] ==
'\0')
1770 state state_(*
this);
1773 uint32_t bytes_length = length * 2;
1775 if (bytes_length == 0)
1784 ret_value.
resize(length);
1786 if (ret_value[length - 1] == L
'\0')
1789 ret_value.
erase(length);
1801 size_t num_elements)
1803 size_t total_size =
sizeof(*bool_t) * num_elements;
1810 for (
size_t count = 0; count < num_elements; ++count)
1817 bool_t[count] =
true;
1819 else if (value == 0)
1821 bool_t[count] =
false;
1833 size_t num_elements)
1835 size_t total_size =
sizeof(*char_t) * num_elements;
1852 size_t num_elements)
1854 if (num_elements == 0)
1859 size_t align =
alignment(
sizeof(*short_t));
1860 size_t total_size =
sizeof(*short_t) * num_elements;
1861 size_t size_aligned = total_size + align;
1876 char* dst =
reinterpret_cast<char*
>(short_t);
1877 char* end = dst + total_size;
1879 for (; dst < end; dst +=
sizeof(*short_t))
1899 size_t num_elements)
1901 if (num_elements == 0)
1906 size_t align =
alignment(
sizeof(*long_t));
1907 size_t total_size =
sizeof(*long_t) * num_elements;
1908 size_t size_aligned = total_size + align;
1923 char* dst =
reinterpret_cast<char*
>(long_t);
1924 char* end = dst + total_size;
1926 for (; dst < end; dst +=
sizeof(*long_t))
1948 size_t num_elements)
1950 if (num_elements == 0)
1956 for (
size_t count = 0; count < num_elements; ++count)
1959 wchar[count] =
static_cast<wchar_t>(value);
1965 int64_t* longlong_t,
1966 size_t num_elements)
1968 if (num_elements == 0)
1974 size_t total_size =
sizeof(*longlong_t) * num_elements;
1975 size_t size_aligned = total_size + align;
1990 char* dst =
reinterpret_cast<char*
>(longlong_t);
1991 char* end = dst + total_size;
1993 for (; dst < end; dst +=
sizeof(*longlong_t))
2019 size_t num_elements)
2021 if (num_elements == 0)
2026 size_t align =
alignment(
sizeof(*float_t));
2027 size_t total_size =
sizeof(*float_t) * num_elements;
2028 size_t size_aligned = total_size + align;
2043 char* dst =
reinterpret_cast<char*
>(float_t);
2044 char* end = dst + total_size;
2046 for (; dst < end; dst +=
sizeof(*float_t))
2068 size_t num_elements)
2070 if (num_elements == 0)
2076 size_t total_size =
sizeof(*double_t) * num_elements;
2077 size_t size_aligned = total_size + align;
2092 char* dst =
reinterpret_cast<char*
>(double_t);
2093 char* end = dst + total_size;
2095 for (; dst < end; dst +=
sizeof(*double_t))
2120 long double* ldouble_t,
2121 size_t num_elements)
2123 if (num_elements == 0)
2130 size_t total_size = 16 * num_elements;
2131 size_t size_aligned = total_size + align;
2144#if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2147 for (
size_t i = 0; i < num_elements; ++i)
2150 char* dst =
reinterpret_cast<char*
>(&tmp);
2167 ldouble_t[i] =
static_cast<long double>(tmp);
2172 for (
size_t i = 0; i < num_elements; ++i)
2177 ldouble_t[i] =
static_cast<long double>(tmp);
2181#if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2184 char* dst =
reinterpret_cast<char*
>(ldouble_t);
2185 char* end = dst + num_elements *
sizeof(*ldouble_t);
2187 for (; dst < end; dst +=
sizeof(*ldouble_t))
2189#if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2213#if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2217 for (
size_t i = 0; i < num_elements; ++i)
2269 state state_before_error(*
this);
2271 size_t total_size = vector_t.
size() *
sizeof(bool);
2278 for (
size_t count = 0; count < vector_t.
size(); ++count)
2307 state state_before_error(*
this);
2309 *this << static_cast<int32_t>(vector_t.
size());
2311 size_t total_size = vector_t.
size() *
sizeof(bool);
2318 for (
size_t count = 0; count < vector_t.
size(); ++count)
2347 state state_before_error(*
this);
2349 size_t total_size = vector_t.
size() *
sizeof(bool);
2356 for (uint32_t count = 0; count < vector_t.
size(); ++count)
2363 vector_t[count] =
true;
2365 else if (value == 0)
2367 vector_t[count] =
false;
2371 throw BadParamException(
"Unexpected byte value in Cdr::deserialize_bool_sequence, expected 0 or 1");
2387 uint32_t sequence_length {0};
2388 state state_before_error(*
this);
2390 *
this >> sequence_length;
2392 size_t total_size = sequence_length *
sizeof(bool);
2396 vector_t.
resize(sequence_length);
2400 for (uint32_t count = 0; count < sequence_length; ++count)
2407 vector_t[count] =
true;
2409 else if (value == 0)
2411 vector_t[count] =
false;
2415 throw BadParamException(
"Unexpected byte value in Cdr::deserialize_bool_sequence, expected 0 or 1");
2430 size_t& num_elements)
2432 uint32_t sequence_length {0};
2436 uint32_t dheader {0};
2448 while (
offset_ - offset < dheader && count < sequence_length)
2454 if (
offset_ - offset != dheader)
2461 delete [] sequence_t;
2462 sequence_t =
nullptr;
2468 state state_before_error(*
this);
2479 delete [] sequence_t;
2480 sequence_t =
nullptr;
2486 num_elements = sequence_length;
2492 size_t& num_elements)
2494 uint32_t sequence_length {0};
2498 uint32_t dheader {0};
2510 while (
offset_ - offset < dheader && count < sequence_length)
2516 if (
offset_ - offset != dheader)
2523 delete [] sequence_t;
2524 sequence_t =
nullptr;
2530 state state_before_error(*
this);
2541 delete [] sequence_t;
2542 sequence_t =
nullptr;
2548 num_elements = sequence_length;
2558 assert(0x3F00 >= member_id.
id);
2562 uint16_t flags_and_member_id =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2563 static_cast<uint16_t
>(member_id.
id);
2572 size_t member_serialized_size)
2574 static_cast<void>(member_id);
2575 assert(0x3F00 >= member_id.
id);
2578 jump(
sizeof(uint16_t));
2579 uint16_t size =
static_cast<uint16_t
>(member_serialized_size);
2588 uint16_t flags_and_extended_pid =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2593 uint32_t
id = member_id.
id;
2602 size_t member_serialized_size)
2604 jump(
sizeof(uint16_t) +
sizeof(uint16_t) +
sizeof(uint32_t));
2605 uint32_t msize =
static_cast<uint32_t
>(member_serialized_size);
2611 size_t member_serialized_size)
2613 assert(0x3F00 >= member_id.
id);
2616 uint16_t flags_and_member_id =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2617 static_cast<uint16_t
>(member_id.
id);
2619 uint16_t size =
static_cast<uint16_t
>(member_serialized_size);
2626 size_t member_serialized_size)
2628 if (0 < (
end_ -
offset_ - member_serialized_size - 11))
2636 uint16_t flags_and_extended_pid =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2641 uint32_t
id = member_id.
id;
2643 uint32_t msize =
static_cast<uint32_t
>(member_serialized_size);
2651 bool ret_value =
true;
2653 uint16_t flags_and_member_id = 0;
2656 uint16_t
id = (flags_and_member_id & 0x3FFF);
2701 assert(0x10000000 > member_id.
id);
2703 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | member_id.
id;
2709 size_t member_serialized_size)
2711 assert(0x10000000 > member_id.
id);
2712 assert(8 >= member_serialized_size);
2715 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2722 assert(0x10000000 > member_id.
id);
2724 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | member_id.
id;
2732 size_t member_serialized_size)
2734 assert(0x10000000 > member_id.
id);
2736 uint32_t lc = 0 == member_serialized_size ?
get_long_lc(serialized_member_size_) : 0x40000000;
2737 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2739 if (0 < member_serialized_size)
2741 uint32_t size =
static_cast<uint32_t
>(member_serialized_size);
2748 size_t member_serialized_size)
2750 assert(0x10000000 > member_id.
id);
2751 assert(8 >= member_serialized_size);
2754 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2761 size_t member_serialized_size)
2763 assert(0x10000000 > member_id.
id);
2765 if (0 < (
end_ -
offset_ - member_serialized_size - 7))
2773 uint32_t lc =
get_long_lc(serialized_member_size_);
2774 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2776 uint32_t size =
static_cast<uint32_t
>(member_serialized_size);
2784 assert(0x10000000 > member_id.
id);
2787 uint32_t lc =
get_long_lc(serialized_member_size_);
2788 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2798 static_cast<void>(is_present);
2808 if (0x3F00 >= member_id.
id)
2810 switch (header_selection)
2826 switch (header_selection)
2836 "Cannot encode XCDRv1 ShortMemberHeader when member_id is bigger than 0x3F00");
2860 const size_t member_serialized_size = last_offset -
offset_ -
2875 "Cannot encode XCDRv1 ShortMemberHeader when serialized member size is greater than 0xFFFF");
2909 jump(member_serialized_size);
2931 if (0x3F00 >= member_id.
id)
2933 switch (header_selection)
2949 switch (header_selection)
2959 "Cannot encode XCDRv1 ShortMemberHeader when member_id is bigger than 0x3F00");
2984 const size_t member_serialized_size = last_offset -
offset_ -
2999 "Cannot encode XCDRv1 ShortMemberHeader when serialized member size is greater than 0xFFFF");
3033 jump(member_serialized_size);
3056 if (0x10000000 <= member_id.
id)
3058 throw BadParamException(
"Cannot serialize a member identifier equal or greater than 0x10000000");
3061 switch (header_selection)
3099 const size_t member_serialized_size = last_offset -
offset_ -
3101 if (8 < member_serialized_size || 0xFFFFFFFFu ==
get_short_lc(member_serialized_size))
3144 jump(member_serialized_size);
3185 uint32_t flags_and_member_id = 0;
3188 uint32_t mid = (flags_and_member_id & 0x0FFFFFFF);
3189 uint32_t lc = (flags_and_member_id & 0x70000000) >> 28;
3225 current_state.
member_size_ = 4 + (size * (5 == lc ? 1 : (6 == lc ? 4 : 8)));
3240 current_state.previous_encoding_ = current_encoding_;
3241 current_encoding_ = type_encoding;
3276 uint32_t dheader {0};
3295 const size_t member_serialized_size = last_offset -
offset_ - 4 -
alignment(4);
3296 serialize(
static_cast<uint32_t
>(member_serialized_size));
3297 jump(member_serialized_size);
3324 throw BadParamException(
"Cannot deserialize a member with flag must_understand");
3335 "Member size provided by member header is not equal to the real decoded member size");
3366 uint32_t dheader {0};
3389 throw BadParamException(
"Cannot deserialize a member with flag must_understand");
3405 "Member size provided by member header is not equal to the real decoded size");
3466 static_cast<void>(type_encoding);
3484 static_cast<void>(type_encoding);
3506 uint32_t dheader {0};
3510 return dheader_state;
3522 serialize(
static_cast<uint32_t
>(dheader));
uint32_t size_to_uint32(size_t val)
This class stores the current state of a CDR serialization.
const FastBuffer::iterator origin_
The position from the alignment is calculated, when the state was created.
Cdr_DllAPI state(const Cdr &cdr)
Default constructor.
size_t last_data_size_
Stores the last datasize serialized/deserialized when the state was created.
const FastBuffer::iterator offset_
The position in the buffer when the state was created.
EncodingAlgorithmFlag previous_encoding_
Not related with the state. Used by encoding algorithms to store the previous encoding algorithm.
uint32_t member_size_
Not related with the state. Used by encoding algorithms to set the encoded member size.
bool swap_bytes_
This attribute specifies if it is needed to swap the bytes when the state is created.
XCdrHeaderSelection header_selection_
Not related with the state. Used by encoding algorithms to store the selected member header version.
MemberId next_member_id_
Not related with the state. Next member id which will be encoded.
Cdr_DllAPI bool operator==(const state &other_state) const
Compares two states.
XCdrHeaderSelection header_serialized_
Not related with the state. Used by encoding algorithms to store the allocated member header version.
This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an...
uint8_t endianness_
The endianness that will be applied over the buffer.
Cdr & xcdr2_end_serialize_type(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the type.
end_serialize_member_functor end_serialize_member_
Cdr & xcdr2_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Tells to the encoder a new type and its members start to be decoded according to XCDRv2.
void reset_alignment()
This function resets the alignment to the current position in the buffer.
Cdr_DllAPI std::array< uint8_t, 2 > get_dds_cdr_options() const
This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
Cdr & xcdr1_end_serialize_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
void xcdr2_change_to_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded long header to a short header according to XCDRv2.
Cdr & serialize(const _T &value)
Encodes the value of a type into the buffer.
void xcdr2_end_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a short member header of a member according to XCDRv2.
Cdr_DllAPI bool set_encoding_flag(EncodingAlgorithmFlag encoding_flag)
Sets the EncodingAlgorithmFlag for the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
Cdr_DllAPI bool move_alignment_forward(size_t num_bytes)
This function moves the alignment forward.
std::array< uint8_t, 2 > options_
This attribute stores the option flags when the CDR type is DDS_CDR;.
static size_t alignment(size_t current_alignment, size_t data_size)
Returns the number of bytes needed to align a position to certain data size.
EncodingAlgorithmFlag encoding_flag_
Stores the main encoding algorithm.
Cdr_DllAPI Cdr & deserialize_bool_array(std::vector< bool > &vector_t)
Cdr_DllAPI Cdr & deserialize_bool_sequence(std::vector< bool > &vector_t)
Cdr_DllAPI const char * read_string(uint32_t &length)
Cdr_DllAPI const std::wstring read_wstring(uint32_t &length)
Cdr & cdr_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Cdr_DllAPI state allocate_xcdrv2_dheader()
Encodes an empty DHEADER if the encoding version is XCDRv2. After serializing the members's type,...
Cdr_DllAPI Cdr(FastBuffer &cdr_buffer, const Endianness endianness=DEFAULT_ENDIAN, const CdrVersion cdr_version=XCDRv2)
This constructor creates an eprosima::fastcdr::Cdr object that can serialize/deserialize the assigned...
@ AUTO_WITH_SHORT_HEADER_BY_DEFAULT
Initially a short member header is allocated but can be changed to the longer version.
@ LONG_HEADER
Initially a long member header is allocated and cannot be changed.
@ SHORT_HEADER
Initially a short member header is allocated and cannot be changed. This option may cause an exceptio...
@ AUTO_WITH_LONG_HEADER_BY_DEFAULT
Initially a long member header is allocated but can be changed to the shorter version.
size_t align64_
Align for types equal or greater than 64bits.
Cdr_DllAPI char * get_buffer_pointer()
This function returns the pointer to the current used buffer.
Cdr & xcdr2_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state ¤t_state, XCdrHeaderSelection header_selection)
Tells to the encoder a member starts to be encoded according to XCDRv2.
Cdr_DllAPI Cdr & begin_serialize_type(Cdr::state ¤t_state, EncodingAlgorithmFlag type_encoding)
Tells to the encoder a new type and its members starts to be encoded.
end_serialize_member_functor end_serialize_opt_member_
Cdr & cdr_end_serialize_member(const Cdr::state ¤t_state)
Cdr_DllAPI Cdr & serialize_encapsulation()
This function writes the encapsulation of the CDR stream. If the CDR stream should contain an encapsu...
bool resize(size_t min_size_inc)
This function resizes the internal buffer. It only applies if the FastBuffer object was created with ...
SerializedMemberSizeForNextInt
@ SERIALIZED_MEMBER_SIZE_4
Serialized member size in a DHEADER.
@ SERIALIZED_MEMBER_SIZE
Default. No serialized member size in a DHEADER.
@ SERIALIZED_MEMBER_SIZE_8
Serialized member size (which is a multiple of 4) in a DHEADER.
Cdr & xcdr1_begin_serialize_opt_member(const MemberId &member_id, bool is_present, Cdr::state ¤t_state, XCdrHeaderSelection header_selection)
Tells to the encoder a member starts to be encoded according to XCDRv1.
FastBuffer::iterator end_
The last position in the buffer;.
void xcdr2_deserialize_member_header(MemberId &member_id, Cdr::state ¤t_state)
Decodes a member header according to XCDRv2.
Cdr & xcdr1_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Tells to the encoder a new type and its members start to be decoded according to XCDRv1.
static Cdr_DllAPI const Endianness DEFAULT_ENDIAN
Default endianess in the system.
Cdr & xcdr1_begin_serialize_type(Cdr::state ¤t_state, EncodingAlgorithmFlag type_encoding) noexcept
Tells to the encoder a new type and its members start to be encoded according to XCDRv1.
void xcdr1_end_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a short member header of a member according to XCDRv1.
void xcdr2_serialize_long_member_header(const MemberId &member_id)
Encodes a long member header of a member according to XCDRv2.
begin_serialize_member_functor begin_serialize_member_
void reset_callbacks()
Resets the internal callbacks depending on the current selected Cdr version.
Cdr & xcdr1_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state ¤t_state, XCdrHeaderSelection header_selection)
Tells to the encoder a member starts to be encoded according to XCDRv1.
void xcdr1_change_to_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded long header to a short header according to XCDRv1.
FastBuffer & cdr_buffer_
Reference to the buffer that will be serialized/deserialized.
begin_serialize_opt_member_functor begin_serialize_opt_member_
void xcdr1_serialize_short_member_header(const MemberId &member_id)
XCDR extensions.
Cdr & cdr_begin_serialize_type(Cdr::state ¤t_state, EncodingAlgorithmFlag type_encoding)
Cdr & serialize_array(const _T *value, size_t num_elements)
Encodes an array of a type not managed by this encoder into the buffer.
Cdr & xcdr1_end_serialize_opt_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
Cdr_DllAPI bool jump(size_t num_bytes)
This function skips a number of bytes in the CDR stream buffer.
state initial_state_
Stores the initial state.
FastBuffer::iterator origin_
The position from where the alignment is calculated.
Cdr_DllAPI void set_dds_cdr_options(const std::array< uint8_t, 2 > &options)
This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
uint32_t get_long_lc(SerializedMemberSizeForNextInt serialized_member_size)
size_t last_data_size_
Stores the last datasize serialized/deserialized. It's used to optimize.
Cdr & deserialize_array(_T *value, size_t num_elements)
Decodes an array of a type not managed by this encoder from the buffer.
begin_serialize_type_functor begin_serialize_type_
Cdr & deserialize(_T &value)
Decodes the value of a type from the buffer.
bool encapsulation_serialized_
Whether the encapsulation was serialized.
Cdr_DllAPI Cdr & serialize_bool_array(const std::vector< bool > &vector_t)
Cdr & cdr_end_serialize_type(const Cdr::state ¤t_state)
Cdr_DllAPI Cdr & deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
Tells to the encoder a new type and its members starts to be decoded.
Cdr_DllAPI char * get_current_position()
This function returns the current position in the CDR stream.
Cdr_DllAPI EncodingAlgorithmFlag get_encoding_flag() const
Returns the EncodingAlgorithmFlag set in the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the CdrVersion used by the instance.
Cdr_DllAPI void change_endianness(Endianness endianness)
This function sets the current endianness used by the CDR type.
Cdr & xcdr2_begin_serialize_type(Cdr::state ¤t_state, EncodingAlgorithmFlag type_encoding)
Tells to the encoder a new type and its members start to be encoded according to XCDRv2.
void xcdr1_end_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a long member header of a member according to XCDRv1.
Cdr_DllAPI void reset()
This function resets the current position in the buffer to the beginning.
void xcdr2_shrink_to_long_member_header(const MemberId &member_id, const FastBuffer::iterator &offset)
Join the previous encoded long header with the next DHEADER which was serialized after.
Cdr_DllAPI Cdr & deserialize_wstring_sequence(std::wstring *&sequence_t, size_t &num_elements)
Endianness
This enumeration represents endianness types.
Cdr & xcdr1_end_serialize_type(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the type.
uint32_t get_short_lc(size_t member_serialized_size)
enum eprosima::fastcdr::Cdr::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to optimize XCDRv2 member headers.
CdrVersion cdr_version_
The type of CDR that will be use in serialization/deserialization.
void xcdr1_serialize_long_member_header(const MemberId &member_id)
Encodes a long member header of a member according to XCDRv1.
Cdr & xcdr2_end_serialize_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
Cdr_DllAPI void set_state(const state &state)
Sets a previous state of the CDR serialization process;.
void xcdr2_end_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Finish the encoding of a long member header of a member according to XCDRv2.
Cdr & operator<<(const _T &value)
Encodes the value into the buffer.
MemberId next_member_id_
Next member identifier to be processed.
Cdr_DllAPI Cdr & read_encapsulation()
This function reads the encapsulation of the CDR stream. If the CDR stream contains an encapsulation,...
deserialize_type_functor deserialize_type_
FastBuffer::iterator offset_
The current position in the serialization/deserialization process.
Cdr_DllAPI bool xcdr1_deserialize_member_header(MemberId &member_id, Cdr::state ¤t_state)
Decodes a member header according to XCDRv1.
Cdr_DllAPI Cdr & serialize_bool_sequence(const std::vector< bool > &vector_t)
bool swap_bytes_
This attribute specifies if it is needed to swap the bytes.
EncodingAlgorithmFlag current_encoding_
Stores the current encoding algorithm.
Cdr_DllAPI size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
Cdr_DllAPI void set_xcdrv2_dheader(const state &state)
Uses the state to calculate the member's type size and serialize the value in the previous allocated ...
void xcdr2_serialize_short_member_header(const MemberId &member_id)
Encodes a short member header of a member according to XCDRv2.
Cdr_DllAPI Cdr & deserialize_string_sequence(std::string *&sequence_t, size_t &num_elements)
void make_alignment(size_t align)
This function jumps the number of bytes of the alignment. These bytes should be calculated with the f...
Cdr & cdr_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state ¤t_state, XCdrHeaderSelection header_selection)
void xcdr1_change_to_long_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded short header to a long header according to XCDRv1.
void xcdr2_change_to_short_member_header(const MemberId &member_id, size_t member_serialized_size)
Changes the previous encoded long header to a short header according to XCDRv2.
Cdr_DllAPI Endianness endianness() const
This function returns the current endianness used by the CDR type.
Cdr_DllAPI Cdr & end_serialize_type(Cdr::state ¤t_state)
Tells to the encoder the encoding of the type finishes.
Cdr_DllAPI state get_state() const
Returns the current state of the CDR serialization process.
end_serialize_type_functor end_serialize_type_
This class represents a stream of bytes that contains (or will contain) serialized data....
bool resize(size_t min_size_inc)
This function resizes the raw buffer. It will call the user's defined function for this purpose.
iterator begin()
This function returns a iterator that points to the begining of the stream.
char * getBuffer() const
This function returns the stream that the eprosima::fastcdr::FastBuffers uses to serialize data.
iterator end()
This function returns a iterator that points to the end of the stream.
This class implements the iterator used to go through a FastBuffer.
void memcopy(const void *src, const size_t size)
This function copies a buffer into the raw buffer.
void rmemcopy(void *dst, const size_t size)
This function copies from the raw buffer to a external buffer.
This class is thrown as an exception when an invalid parameter is being serialized.
This abstract class is used to create exceptions.
virtual Cdr_DllAPI void raise() const =0
This function throws the object as exception.
This class is thrown as an exception when the buffer's internal memory reachs its size limit.
static Cdr_DllAPI const char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
constexpr uint16_t PID_EXTENDED_LENGTH
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
@ PL_CDR2
Specifies that the content is PL_CDR2.
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
@ DELIMIT_CDR2
Specifies that the content is DELIMIT_CDR2.
@ PL_CDR
Specifies that the content is PL_CDR,.
size_t alignment_on_state(const FastBuffer::iterator &origin, const FastBuffer::iterator &offset, size_t data_size)
constexpr uint16_t PID_SENTINEL_LENGTH
static const MemberId MEMBER_ID_INVALID
constexpr uint16_t PID_EXTENDED
constexpr uint16_t PID_SENTINEL
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
@ CORBA_CDR
Common CORBA CDR serialization.
@ XCDRv1
XCDRv1 encoding defined by standard DDS X-Types 1.3.
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.