Go to the documentation of this file.
23 using namespace exception;
25 #if FASTCDR_IS_BIG_ENDIAN_TARGET
29 #endif // if FASTCDR_IS_BIG_ENDIAN_TARGET
36 constexpr 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)
57 case SERIALIZED_MEMBER_SIZE_8:
60 case SERIALIZED_MEMBER_SIZE_4:
63 case SERIALIZED_MEMBER_SIZE:
74 size_t member_serialized_size)
77 switch (member_serialized_size)
97 : offset_(cdr.offset_)
98 , origin_(cdr.origin_)
99 , swap_bytes_(cdr.swap_bytes_)
100 , last_data_size_(cdr.last_data_size_)
101 , next_member_id_(cdr.next_member_id_)
102 , previous_encoding_(cdr.current_encoding_)
107 const state& current_state)
113 , previous_encoding_(current_state.previous_encoding_)
140 ,
end_(cdr_buffer.end())
197 uint8_t encapsulation {0};
198 state state_before_error(*
this);
208 throw BadParamException(
"Unexpected non-zero initial byte received in Cdr::read_encapsulation");
213 (*this) >> encapsulation;
217 const uint8_t
endianness = encapsulation & 0x1_8u;
225 const uint8_t encoding_flag = encapsulation &
static_cast<uint8_t
>(~0x1);
226 switch (encoding_flag)
239 "Unexpected encoding algorithm received in Cdr::read_encapsulation. XCDRv2 should be selected.");
251 "Unexpected encoding algorithm received in Cdr::read_encapsulation. XCDRv1 should be selected");
262 throw BadParamException(
"Unexpected encoding algorithm received in Cdr::read_encapsulation for DDS CDR");
287 uint8_t encapsulation = 0;
288 state state_before_error(*
this);
302 (*this) << encapsulation;
342 bool ret_value =
false;
362 const std::array<uint8_t, 2>& options)
385 bool ret_value =
false;
418 const state& current_state)
443 bool ret_value =
false;
485 const int16_t short_t)
488 size_t size_aligned =
sizeof(short_t) +
align;
500 const char*
dst =
reinterpret_cast<const char*
>(&short_t);
518 const int32_t long_t)
521 size_t size_aligned =
sizeof(long_t) +
align;
533 const char*
dst =
reinterpret_cast<const char*
>(&long_t);
553 const int64_t longlong_t)
556 size_t size_aligned =
sizeof(longlong_t) +
align;
568 const char*
dst =
reinterpret_cast<const char*
>(&longlong_t);
595 size_t size_aligned =
sizeof(float_t) +
align;
607 const char*
dst =
reinterpret_cast<const char*
>(&float_t);
627 const double double_t)
630 size_t size_aligned =
sizeof(double_t) +
align;
642 const char*
dst =
reinterpret_cast<const char*
>(&double_t);
666 const long double ldouble_t)
669 size_t size_aligned =
sizeof(ldouble_t) +
align;
681 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
682 __float128 tmp = ldouble_t;
683 const char*
dst =
reinterpret_cast<const char*
>(&tmp);
685 const char*
dst =
reinterpret_cast<const char*
>(&ldouble_t);
686 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
687 #if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
705 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
707 offset_++ <<
static_cast<char>(0);
708 offset_++ <<
static_cast<char>(0);
709 offset_++ <<
static_cast<char>(0);
710 offset_++ <<
static_cast<char>(0);
711 offset_++ <<
static_cast<char>(0);
712 offset_++ <<
static_cast<char>(0);
713 offset_++ <<
static_cast<char>(0);
714 offset_++ <<
static_cast<char>(0);
724 #error unsupported long double type and no __float128 available
725 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
726 #endif // FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
730 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
731 __float128 tmp = ldouble_t;
735 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
736 offset_ << static_cast<long double>(0);
738 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
739 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
743 #error unsupported long double type and no __float128 available
744 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
745 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
764 offset_++ <<
static_cast<uint8_t
>(1);
768 offset_++ <<
static_cast<uint8_t
>(0);
778 const char* string_t)
782 if (string_t !=
nullptr)
817 const wchar_t* string_t)
819 uint32_t bytes_length = 0;
822 if (string_t !=
nullptr)
824 wstrlen = wcslen(string_t);
828 if (bytes_length > 0)
855 size_t total_size =
sizeof(*bool_t) * num_elements;
862 for (
size_t count = 0; count < num_elements; ++count)
883 size_t total_size =
sizeof(*char_t) * num_elements;
899 const int16_t* short_t,
902 if (num_elements == 0)
908 size_t total_size =
sizeof(*short_t) * num_elements;
909 size_t size_aligned = total_size +
align;
924 const char*
dst =
reinterpret_cast<const char*
>(short_t);
925 const char* end =
dst + total_size;
927 for (;
dst < end;
dst +=
sizeof(*short_t))
946 const int32_t* long_t,
949 if (num_elements == 0)
955 size_t total_size =
sizeof(*long_t) * num_elements;
956 size_t size_aligned = total_size +
align;
971 const char*
dst =
reinterpret_cast<const char*
>(long_t);
972 const char* end =
dst + total_size;
974 for (;
dst < end;
dst +=
sizeof(*long_t))
995 const wchar_t* wchar,
998 if (num_elements == 0)
1003 for (
size_t count = 0; count < num_elements; ++count)
1011 const int64_t* longlong_t,
1012 size_t num_elements)
1014 if (num_elements == 0)
1020 size_t total_size =
sizeof(*longlong_t) * num_elements;
1021 size_t size_aligned = total_size +
align;
1036 const char*
dst =
reinterpret_cast<const char*
>(longlong_t);
1037 const char* end =
dst + total_size;
1039 for (;
dst < end;
dst +=
sizeof(*longlong_t))
1064 const float* float_t,
1065 size_t num_elements)
1067 if (num_elements == 0)
1073 size_t total_size =
sizeof(*float_t) * num_elements;
1074 size_t size_aligned = total_size +
align;
1089 const char*
dst =
reinterpret_cast<const char*
>(float_t);
1090 const char* end =
dst + total_size;
1092 for (;
dst < end;
dst +=
sizeof(*float_t))
1113 const double* double_t,
1114 size_t num_elements)
1116 if (num_elements == 0)
1122 size_t total_size =
sizeof(*double_t) * num_elements;
1123 size_t size_aligned = total_size +
align;
1138 const char*
dst =
reinterpret_cast<const char*
>(double_t);
1139 const char* end =
dst + total_size;
1141 for (;
dst < end;
dst +=
sizeof(*double_t))
1166 const long double* ldouble_t,
1167 size_t num_elements)
1169 if (num_elements == 0)
1176 size_t total_size = 16 * num_elements;
1177 size_t size_aligned = total_size +
align;
1190 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1193 for (
size_t i = 0; i < num_elements; ++i, ++ldouble_t)
1195 __float128 tmp = *ldouble_t;
1196 const char*
dst =
reinterpret_cast<const char*
>(&tmp);
1217 for (
size_t i = 0; i < num_elements; ++i, ++ldouble_t)
1219 __float128 tmp = *ldouble_t;
1225 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1228 const char*
dst =
reinterpret_cast<const char*
>(ldouble_t);
1229 const char* end =
dst + total_size;
1231 for (;
dst < end;
dst +=
sizeof(*ldouble_t))
1233 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1243 offset_++ <<
static_cast<char>(0);
1244 offset_++ <<
static_cast<char>(0);
1245 offset_++ <<
static_cast<char>(0);
1246 offset_++ <<
static_cast<char>(0);
1247 offset_++ <<
static_cast<char>(0);
1248 offset_++ <<
static_cast<char>(0);
1249 offset_++ <<
static_cast<char>(0);
1250 offset_++ <<
static_cast<char>(0);
1251 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
1264 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
1268 for (
size_t i = 0; i < num_elements; ++i)
1270 offset_ << static_cast<long double>(0);
1275 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
1278 #error unsupported long double type and no __float128 available
1279 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1280 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1307 size_t size_aligned =
sizeof(short_t) +
align;
1319 char*
dst =
reinterpret_cast<char*
>(&short_t);
1340 size_t size_aligned =
sizeof(long_t) +
align;
1352 char*
dst =
reinterpret_cast<char*
>(&long_t);
1372 int64_t& longlong_t)
1375 size_t size_aligned =
sizeof(longlong_t) +
align;
1387 char*
dst =
reinterpret_cast<char*
>(&longlong_t);
1401 offset_ +=
sizeof(longlong_t);
1414 size_t size_aligned =
sizeof(float_t) +
align;
1426 char*
dst =
reinterpret_cast<char*
>(&float_t);
1449 size_t size_aligned =
sizeof(double_t) +
align;
1461 char*
dst =
reinterpret_cast<char*
>(&double_t);
1485 long double& ldouble_t)
1488 size_t size_aligned =
sizeof(ldouble_t) +
align;
1500 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1501 __float128 tmp = ldouble_t;
1502 char*
dst =
reinterpret_cast<char*
>(&tmp);
1504 char*
dst =
reinterpret_cast<char*
>(&ldouble_t);
1505 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1506 #if FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1523 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1524 ldouble_t =
static_cast<long double>(tmp);
1525 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1527 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1538 #error unsupported long double type and no __float128 available
1539 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
1540 #endif // FASTCDR_HAVE_FLOAT128 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1544 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1548 ldouble_t =
static_cast<long double>(tmp);
1550 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1551 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8
1553 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8
1556 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
1557 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
1583 else if (value == 0)
1589 throw BadParamException(
"Unexpected byte value in Cdr::deserialize(bool), expected 0 or 1");
1598 uint32_t length = 0;
1615 reinterpret_cast<char*
>(calloc(length + ((&
offset_)[length - 1] ==
'\0' ? 0 : 1),
1617 memcpy(string_t, &
offset_, length);
1629 uint32_t length = 0;
1644 string_t =
reinterpret_cast<wchar_t*
>(calloc(length + 1,
sizeof(
wchar_t)));
1658 const char* ret_value =
"";
1659 state state_before_error(*
this);
1674 if (ret_value[length - 1] ==
'\0')
1689 std::wstring ret_value = L
"";
1690 state state_(*
this);
1693 uint32_t bytes_length = length * 2;
1695 if (bytes_length == 0)
1704 ret_value.resize(length);
1706 if (ret_value[length - 1] == L
'\0')
1709 ret_value.erase(length);
1721 size_t num_elements)
1723 size_t total_size =
sizeof(*bool_t) * num_elements;
1730 for (
size_t count = 0; count < num_elements; ++count)
1737 bool_t[count] =
true;
1739 else if (value == 0)
1741 bool_t[count] =
false;
1753 size_t num_elements)
1755 size_t total_size =
sizeof(*char_t) * num_elements;
1772 size_t num_elements)
1774 if (num_elements == 0)
1780 size_t total_size =
sizeof(*short_t) * num_elements;
1781 size_t size_aligned = total_size +
align;
1796 char*
dst =
reinterpret_cast<char*
>(short_t);
1797 char* end =
dst + total_size;
1799 for (;
dst < end;
dst +=
sizeof(*short_t))
1819 size_t num_elements)
1821 if (num_elements == 0)
1827 size_t total_size =
sizeof(*long_t) * num_elements;
1828 size_t size_aligned = total_size +
align;
1843 char*
dst =
reinterpret_cast<char*
>(long_t);
1844 char* end =
dst + total_size;
1846 for (;
dst < end;
dst +=
sizeof(*long_t))
1868 size_t num_elements)
1870 if (num_elements == 0)
1876 for (
size_t count = 0; count < num_elements; ++count)
1879 wchar[count] =
static_cast<wchar_t>(value);
1885 int64_t* longlong_t,
1886 size_t num_elements)
1888 if (num_elements == 0)
1894 size_t total_size =
sizeof(*longlong_t) * num_elements;
1895 size_t size_aligned = total_size +
align;
1910 char*
dst =
reinterpret_cast<char*
>(longlong_t);
1911 char* end =
dst + total_size;
1913 for (;
dst < end;
dst +=
sizeof(*longlong_t))
1939 size_t num_elements)
1941 if (num_elements == 0)
1947 size_t total_size =
sizeof(*float_t) * num_elements;
1948 size_t size_aligned = total_size +
align;
1963 char*
dst =
reinterpret_cast<char*
>(float_t);
1964 char* end =
dst + total_size;
1966 for (;
dst < end;
dst +=
sizeof(*float_t))
1988 size_t num_elements)
1990 if (num_elements == 0)
1996 size_t total_size =
sizeof(*double_t) * num_elements;
1997 size_t size_aligned = total_size +
align;
2012 char*
dst =
reinterpret_cast<char*
>(double_t);
2013 char* end =
dst + total_size;
2015 for (;
dst < end;
dst +=
sizeof(*double_t))
2040 long double* ldouble_t,
2041 size_t num_elements)
2043 if (num_elements == 0)
2050 size_t total_size = 16 * num_elements;
2051 size_t size_aligned = total_size +
align;
2064 #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2067 for (
size_t i = 0; i < num_elements; ++i)
2070 char*
dst =
reinterpret_cast<char*
>(&tmp);
2087 ldouble_t[i] =
static_cast<long double>(tmp);
2092 for (
size_t i = 0; i < num_elements; ++i)
2097 ldouble_t[i] =
static_cast<long double>(tmp);
2101 #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2104 char*
dst =
reinterpret_cast<char*
>(ldouble_t);
2105 char* end =
dst + num_elements *
sizeof(*ldouble_t);
2107 for (;
dst < end;
dst +=
sizeof(*ldouble_t))
2109 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2120 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
2133 #if FASTCDR_SIZEOF_LONG_DOUBLE == 16
2137 for (
size_t i = 0; i < num_elements; ++i)
2143 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 16
2145 #endif // FASTCDR_SIZEOF_LONG_DOUBLE == 8 || FASTCDR_SIZEOF_LONG_DOUBLE == 16
2146 #endif // FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16
2155 const std::vector<bool>& vector_t)
2157 state state_before_error(*
this);
2159 size_t total_size = vector_t.size() *
sizeof(bool);
2166 for (
size_t count = 0; count < vector_t.size(); ++count)
2169 std::vector<bool>::const_reference ref = vector_t[count];
2193 const std::vector<bool>& vector_t)
2195 state state_before_error(*
this);
2197 *this << static_cast<int32_t>(vector_t.size());
2199 size_t total_size = vector_t.size() *
sizeof(bool);
2206 for (
size_t count = 0; count < vector_t.size(); ++count)
2209 std::vector<bool>::const_reference ref = vector_t[count];
2233 std::vector<bool>& vector_t)
2235 state state_before_error(*
this);
2237 size_t total_size = vector_t.size() *
sizeof(bool);
2244 for (uint32_t count = 0; count < vector_t.size(); ++count)
2251 vector_t[count] =
true;
2253 else if (value == 0)
2255 vector_t[count] =
false;
2259 throw BadParamException(
"Unexpected byte value in Cdr::deserialize_bool_sequence, expected 0 or 1");
2273 std::vector<bool>& vector_t)
2275 uint32_t sequence_length {0};
2276 state state_before_error(*
this);
2278 *
this >> sequence_length;
2280 size_t total_size = sequence_length *
sizeof(bool);
2284 vector_t.resize(sequence_length);
2288 for (uint32_t count = 0; count < sequence_length; ++count)
2295 vector_t[count] =
true;
2297 else if (value == 0)
2299 vector_t[count] =
false;
2303 throw BadParamException(
"Unexpected byte value in Cdr::deserialize_bool_sequence, expected 0 or 1");
2317 std::string*& sequence_t,
2318 size_t& num_elements)
2320 uint32_t sequence_length {0};
2324 uint32_t dheader {0};
2333 sequence_t =
new std::string[sequence_length];
2336 while (
offset_ - offset < dheader && count < sequence_length)
2342 if (
offset_ - offset != dheader)
2349 delete [] sequence_t;
2350 sequence_t =
nullptr;
2356 state state_before_error(*
this);
2362 sequence_t =
new std::string[sequence_length];
2367 delete [] sequence_t;
2368 sequence_t =
nullptr;
2374 num_elements = sequence_length;
2379 std::wstring*& sequence_t,
2380 size_t& num_elements)
2382 uint32_t sequence_length {0};
2386 uint32_t dheader {0};
2395 sequence_t =
new std::wstring[sequence_length];
2398 while (
offset_ - offset < dheader && count < sequence_length)
2404 if (
offset_ - offset != dheader)
2411 delete [] sequence_t;
2412 sequence_t =
nullptr;
2418 state state_before_error(*
this);
2424 sequence_t =
new std::wstring[sequence_length];
2429 delete [] sequence_t;
2430 sequence_t =
nullptr;
2436 num_elements = sequence_length;
2450 uint16_t flags_and_member_id =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2451 static_cast<uint16_t
>(member_id.
id);
2460 size_t member_serialized_size)
2462 static_cast<void>(member_id);
2464 assert(std::numeric_limits<uint16_t>::max() >= member_serialized_size );
2466 jump(
sizeof(uint16_t));
2467 uint16_t
size =
static_cast<uint16_t
>(member_serialized_size);
2476 uint16_t flags_and_extended_pid =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2481 uint32_t
id = member_id.
id;
2490 size_t member_serialized_size)
2492 jump(
sizeof(uint16_t) +
sizeof(uint16_t) +
sizeof(uint32_t));
2493 uint32_t msize =
static_cast<uint32_t
>(member_serialized_size);
2499 size_t member_serialized_size)
2502 assert(std::numeric_limits<uint16_t>::max() >= member_serialized_size );
2504 uint16_t flags_and_member_id =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2505 static_cast<uint16_t
>(member_id.
id);
2507 uint16_t
size =
static_cast<uint16_t
>(member_serialized_size);
2514 size_t member_serialized_size)
2516 if (0 < (
end_ -
offset_ - member_serialized_size - 11))
2524 uint16_t flags_and_extended_pid =
static_cast<uint16_t
>(member_id.
must_understand ? 0x4000 : 0x0) |
2529 uint32_t
id = member_id.
id;
2531 uint32_t msize =
static_cast<uint32_t
>(member_serialized_size);
2539 bool ret_value =
true;
2541 uint16_t flags_and_member_id = 0;
2544 uint16_t
id = (flags_and_member_id & 0x3FFF);
2591 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | member_id.
id;
2597 size_t member_serialized_size)
2600 assert(8 >= member_serialized_size);
2603 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2612 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | member_id.
id;
2620 size_t member_serialized_size)
2624 uint32_t lc = 0 == member_serialized_size ?
get_long_lc(serialized_member_size_) : 0x40000000;
2625 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2627 if (0 < member_serialized_size)
2629 uint32_t
size =
static_cast<uint32_t
>(member_serialized_size);
2636 size_t member_serialized_size)
2639 assert(8 >= member_serialized_size);
2642 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2649 size_t member_serialized_size)
2653 if (0 < (
end_ -
offset_ - member_serialized_size - 7))
2661 uint32_t lc =
get_long_lc(serialized_member_size_);
2662 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2664 uint32_t
size =
static_cast<uint32_t
>(member_serialized_size);
2675 uint32_t lc =
get_long_lc(serialized_member_size_);
2676 uint32_t flags_and_member_id = (member_id.
must_understand ? 0x80000000 : 0x0) | lc | member_id.
id;
2686 static_cast<void>(is_present);
2696 if (0x3F00 >= member_id.
id)
2698 switch (header_selection)
2700 case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2701 case XCdrHeaderSelection::SHORT_HEADER:
2705 case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2706 case XCdrHeaderSelection::LONG_HEADER:
2714 switch (header_selection)
2716 case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2717 case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2718 case XCdrHeaderSelection::LONG_HEADER:
2724 "Cannot encode XCDRv1 ShortMemberHeader when member_id is bigger than 0x3F00");
2748 const size_t member_serialized_size = last_offset -
offset_ -
2750 if (member_serialized_size > std::numeric_limits<uint16_t>::max())
2754 case XCdrHeaderSelection::SHORT_HEADER:
2763 "Cannot encode XCDRv1 ShortMemberHeader when serialized member size is greater than 0xFFFF");
2766 case XCdrHeaderSelection::LONG_HEADER:
2777 case XCdrHeaderSelection::SHORT_HEADER:
2780 case XCdrHeaderSelection::LONG_HEADER:
2797 jump(member_serialized_size);
2819 if (0x3F00 >= member_id.
id)
2821 switch (header_selection)
2823 case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2824 case XCdrHeaderSelection::SHORT_HEADER:
2828 case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2829 case XCdrHeaderSelection::LONG_HEADER:
2837 switch (header_selection)
2839 case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2840 case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2841 case XCdrHeaderSelection::LONG_HEADER:
2847 "Cannot encode XCDRv1 ShortMemberHeader when member_id is bigger than 0x3F00");
2872 const size_t member_serialized_size = last_offset -
offset_ -
2874 if (member_serialized_size > std::numeric_limits<uint16_t>::max())
2878 case XCdrHeaderSelection::SHORT_HEADER:
2887 "Cannot encode XCDRv1 ShortMemberHeader when serialized member size is greater than 0xFFFF");
2890 case XCdrHeaderSelection::LONG_HEADER:
2901 case XCdrHeaderSelection::SHORT_HEADER:
2904 case XCdrHeaderSelection::LONG_HEADER:
2921 jump(member_serialized_size);
2944 if (0x10000000 <= member_id.
id)
2946 throw BadParamException(
"Cannot serialize a member identifier equal or greater than 0x10000000");
2949 switch (header_selection)
2951 case XCdrHeaderSelection::SHORT_HEADER:
2952 case XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT:
2956 case XCdrHeaderSelection::LONG_HEADER:
2957 case XCdrHeaderSelection::AUTO_WITH_LONG_HEADER_BY_DEFAULT:
2987 const size_t member_serialized_size = last_offset -
offset_ -
2989 if (8 < member_serialized_size)
2993 case XCdrHeaderSelection::SHORT_HEADER:
3003 case XCdrHeaderSelection::LONG_HEADER:
3014 case XCdrHeaderSelection::SHORT_HEADER:
3017 case XCdrHeaderSelection::LONG_HEADER:
3032 jump(member_serialized_size);
3039 case XCdrHeaderSelection::SHORT_HEADER:
3050 case XCdrHeaderSelection::LONG_HEADER:
3073 uint32_t flags_and_member_id = 0;
3076 uint32_t mid = (flags_and_member_id & 0x0FFFFFFF);
3077 uint32_t lc = (flags_and_member_id & 0x70000000) >> 28;
3113 current_state.
member_size_ = 4 + (
size * (5 == lc ? 1 : (6 == lc ? 4 : 8)));
3128 current_state.previous_encoding_ = current_encoding_;
3129 current_encoding_ = type_encoding;
3164 uint32_t dheader {0};
3183 const size_t member_serialized_size = last_offset -
offset_ - 4 -
alignment(4);
3184 serialize(
static_cast<uint32_t
>(member_serialized_size));
3185 jump(member_serialized_size);
3194 std::function<
bool (
Cdr&,
const MemberId&)> functor)
3211 throw BadParamException(
"Cannot deserialize a member with flag must_understand");
3222 "Member size provided by member header is not equal to the real decoded member size");
3243 std::function<
bool (
Cdr&,
const MemberId&)> functor)
3252 uint32_t dheader {0};
3274 throw BadParamException(
"Cannot deserialize a member with flag must_understand");
3290 "Member size provided by member header is not equal to the real decoded size");
3347 static_cast<void>(type_encoding);
3363 std::function<
bool (
Cdr&,
const MemberId&)> functor)
3365 static_cast<void>(type_encoding);
3387 uint32_t dheader {0};
3391 return dheader_state;
3403 serialize(
static_cast<uint32_t
>(dheader));
EncodingAlgorithmFlag previous_encoding_
Not related with the state. Used by encoding algorithms to store the previous encoding algorithm.
Cdr & xcdr1_end_serialize_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
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.
Cdr_DllAPI void change_endianness(Endianness endianness)
This function sets the current endianness used by the CDR type.
MemberId next_member_id_
Not related with the state. Next member id which will be encoded.
uint8_t endianness_
The endianness that will be applied over the buffer.
This class is thrown as an exception when an invalid parameter is being serialized.
void memcopy(const void *src, const size_t size)
This function copies a buffer into the raw buffer.
Cdr_DllAPI Cdr & deserialize_string_sequence(std::string *&sequence_t, size_t &num_elements)
constexpr uint16_t PID_SENTINEL_LENGTH
FastBuffer::iterator origin_
The position from where the alignment is calculated.
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 bool set_encoding_flag(EncodingAlgorithmFlag encoding_flag)
Sets the EncodingAlgorithmFlag for the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
begin_serialize_opt_member_functor begin_serialize_opt_member_
Cdr_DllAPI state(const Cdr &cdr)
Default constructor.
uint32_t get_long_lc(SerializedMemberSizeForNextInt serialized_member_size)
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_DllAPI bool operator==(const state &other_state) const
Compares two states.
end_serialize_type_functor end_serialize_type_
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_opt_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
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.
void rmemcopy(void *dst, const size_t size)
This function copies from the raw buffer to a external buffer.
constexpr uint16_t PID_EXTENDED
XCdrHeaderSelection header_selection_
Not related with the state. Used by encoding algorithms to store the selected member header version.
@ AUTO_WITH_LONG_HEADER_BY_DEFAULT
Initially a long member header is allocated but can be changed to the shorter version.
void xcdr2_serialize_short_member_header(const MemberId &member_id)
Encodes a short member header of a member according to XCDRv2.
Cdr & cdr_end_serialize_member(const Cdr::state ¤t_state)
Cdr & deserialize_array(_T *value, size_t num_elements)
Decodes an array of a type not managed by this encoder from the buffer.
Endianness
This enumeration represents endianness types.
void reset_alignment()
This function resets the alignment to the current position in the buffer.
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.
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.
Cdr_DllAPI bool jump(size_t num_bytes)
This function skips a number of bytes in the CDR stream buffer.
iterator begin()
This function returns a iterator that points to the begining of the stream.
@ PL_CDR
Specifies that the content is PL_CDR,.
Cdr_DllAPI bool xcdr1_deserialize_member_header(MemberId &member_id, Cdr::state ¤t_state)
Decodes a member header according to XCDRv1.
Cdr_DllAPI size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
Cdr & cdr_begin_serialize_type(Cdr::state ¤t_state, EncodingAlgorithmFlag type_encoding)
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
size_t alignment_on_state(const FastBuffer::iterator &origin, const FastBuffer::iterator &offset, size_t data_size)
EncodingAlgorithmFlag encoding_flag_
Stores the main encoding algorithm.
Cdr_DllAPI bool move_alignment_forward(size_t num_bytes)
This function moves the alignment forward.
@ CORBA_CDR
Common CORBA CDR serialization.
This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an...
Cdr & xcdr2_end_serialize_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
begin_serialize_type_functor begin_serialize_type_
MemberId next_member_id_
Next member identifier to be processed.
Cdr & serialize_array(const _T *value, size_t num_elements)
Encodes an array of a type not managed by this encoder into the buffer.
bool resize(size_t min_size_inc)
This function resizes the raw buffer. It will call the user's defined function for this purpose.
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...
span_constexpr std::size_t size(span< T, Extent > const &spn)
@ PLAIN_CDR
Specifies that the content is PLAIN_CDR.
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 & 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 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 Cdr & deserialize_bool_sequence(std::vector< bool > &vector_t)
begin_serialize_member_functor begin_serialize_member_
@ PLAIN_CDR2
Specifies that the content is PLAIN_CDR2.
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
Cdr_DllAPI Cdr & serialize_encapsulation()
This function writes the encapsulation of the CDR stream. If the CDR stream should contain an encapsu...
const FastBuffer::iterator origin_
The position from the alignment is calculated, when the state was created.
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 xcdr2_deserialize_member_header(MemberId &member_id, Cdr::state ¤t_state)
Decodes a member header according to XCDRv2.
Cdr_DllAPI Endianness endianness() const
This function returns the current endianness used by the CDR type.
const Cdr_DllAPI std::wstring read_wstring(uint32_t &length)
uint32_t size_to_uint32(size_t val)
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 state allocate_xcdrv2_dheader()
Encodes an empty DHEADER if the encoding version is XCDRv2. After serializing the members's type,...
Cdr_DllAPI Cdr & deserialize_bool_array(std::vector< bool > &vector_t)
Cdr_DllAPI char * get_current_position()
This function returns the current position in the CDR stream.
Cdr_DllAPI Cdr & deserialize_wstring_sequence(std::wstring *&sequence_t, size_t &num_elements)
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.
@ LONG_HEADER
Initially a long member header is allocated and cannot be changed.
size_t last_data_size_
Stores the last datasize serialized/deserialized when the state was created.
static const MemberId MEMBER_ID_INVALID
@ DELIMIT_CDR2
Specifies that the content is DELIMIT_CDR2.
size_t last_data_size_
Stores the last datasize serialized/deserialized. It's used to optimize.
Cdr_DllAPI void reset()
This function resets the current position in the buffer to the beginning.
Cdr & xcdr2_end_serialize_type(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the type.
enum eprosima::fastcdr::Cdr::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to optimize XCDRv2 member headers.
void xcdr1_serialize_short_member_header(const MemberId &member_id)
XCDR extensions.
This abstract class is used to create exceptions.
CdrVersion cdr_version_
The type of CDR that will be use in serialization/deserialization.
constexpr uint16_t PID_EXTENDED_LENGTH
Cdr & cdr_begin_serialize_member(const MemberId &member_id, bool is_present, Cdr::state ¤t_state, XCdrHeaderSelection header_selection)
Cdr_DllAPI state get_state() const
Returns the current state of the CDR serialization process.
end_serialize_member_functor end_serialize_member_
#define assert(condition)
deserialize_type_functor deserialize_type_
Cdr_DllAPI Cdr & read_encapsulation()
This function reads the encapsulation of the CDR stream. If the CDR stream contains an encapsulation,...
void reset_callbacks()
Resets the internal callbacks depending on the current selected Cdr version.
bool swap_bytes_
This attribute specifies if it is needed to swap the bytes.
XCdrHeaderSelection header_serialized_
Not related with the state. Used by encoding algorithms to store the allocated member header version.
EncodingAlgorithmFlag current_encoding_
Stores the current encoding algorithm.
Cdr_DllAPI EncodingAlgorithmFlag get_encoding_flag() const
Returns the EncodingAlgorithmFlag set in the encapsulation when the CDR type is CdrVersion::DDS_CDR,...
static const Cdr_DllAPI Endianness DEFAULT_ENDIAN
Default endianess in the system.
@ AUTO_WITH_SHORT_HEADER_BY_DEFAULT
Initially a short member header is allocated but can be changed to the longer version.
char * getBuffer() const
This function returns the stream that the eprosima::fastcdr::FastBuffers uses to serialize data.
@ XCDRv1
XCDRv1 encoding defined by standard DDS X-Types 1.3.
FastBuffer::iterator end_
The last position in the buffer;.
This class is thrown as an exception when the buffer's internal memory reachs its size limit.
Cdr & cdr_end_serialize_type(const Cdr::state ¤t_state)
bool resize(size_t min_size_inc)
This function resizes the internal buffer. It only applies if the FastBuffer object was created with ...
@ SERIALIZED_MEMBER_SIZE
Default. No serialized member size in a DHEADER.
Cdr_DllAPI void set_state(const state &state)
Sets a previous state of the CDR serialization process;.
std::array< uint8_t, 2 > options_
This attribute stores the option flags when the CDR type is DDS_CDR;.
end_serialize_member_functor end_serialize_opt_member_
const Cdr_DllAPI char * read_string(uint32_t &length)
virtual Cdr_DllAPI void raise() const =0
This function throws the object as exception.
Cdr_DllAPI Cdr & serialize_bool_sequence(const std::vector< bool > &vector_t)
SerializedMemberSizeForNextInt
Cdr_DllAPI Cdr & serialize_bool_array(const std::vector< bool > &vector_t)
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.
Cdr & serialize(const _T &value)
Encodes the value of a type into the buffer.
Cdr & deserialize(_T &value)
Decodes the value of a type from the buffer.
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.
This class represents a stream of bytes that contains (or will contain) serialized data....
Cdr & cdr_deserialize_type(EncodingAlgorithmFlag type_encoding, std::function< bool(Cdr &, const MemberId &)> functor)
FastBuffer & cdr_buffer_
Reference to the buffer that will be serialized/deserialized.
uint32_t member_size_
Not related with the state. Used by encoding algorithms to set the encoded member size.
@ PL_CDR2
Specifies that the content is PL_CDR2.
bool swap_bytes_
This attribute specifies if it is needed to swap the bytes when the state is created.
void make_alignment(size_t align)
This function jumps the number of bytes of the alignment. These bytes should be calculated with the f...
EncodingAlgorithmFlag
This enumeration represents the supported XCDR encoding algorithms.
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_long_member_header(const MemberId &member_id)
Encodes a long member header of a member according to XCDRv2.
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.
uint32_t get_short_lc(size_t member_serialized_size)
typename detail::char_t_impl< S >::type char_t
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.
This class stores the current state of a CDR serialization.
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the CdrVersion used by the instance.
void xcdr1_serialize_long_member_header(const MemberId &member_id)
Encodes a long member header of a member according to XCDRv1.
constexpr uint16_t PID_SENTINEL
iterator end()
This function returns a iterator that points to the end of the stream.
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.
FastBuffer::iterator offset_
The current position in the serialization/deserialization process.
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.
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.
Cdr & xcdr1_end_serialize_type(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the type.
This class implements the iterator used to go through a FastBuffer.
static const Cdr_DllAPI char *const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT
Default message used in the library.
const FastBuffer::iterator offset_
The position in the buffer when the state was created.
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43