Go to the documentation of this file.
15 #ifndef _FASTCDR_CDR_H_
16 #define _FASTCDR_CDR_H_
25 #include <type_traits>
42 #if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
46 #endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
74 typedef enum : uint8_t
121 const state& other_state)
const;
222 const std::array<uint8_t, 2>& options);
275 size_t current_alignment,
278 return (data_size - (current_alignment % data_size)) & (data_size - 1);
379 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>
::type* =
nullptr,
typename =
void>
427 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
429 int32_t>::value>
::type* =
nullptr>
433 return serialize(
static_cast<int32_t
>(value));
445 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
447 uint32_t>::value>
::type* =
nullptr>
451 return serialize(
static_cast<uint32_t
>(value));
463 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
465 int16_t>::value>
::type* =
nullptr>
469 return serialize(
static_cast<int16_t
>(value));
481 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
483 uint16_t>::value>
::type* =
nullptr>
487 return serialize(
static_cast<uint16_t
>(value));
499 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
501 int8_t>::value>
::type* =
nullptr>
505 return serialize(
static_cast<int8_t
>(value));
517 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
519 uint8_t>::value>
::type* =
nullptr>
523 return serialize(
static_cast<uint8_t
>(value));
533 const uint8_t& octet_t)
535 return serialize(
static_cast<char>(octet_t));
556 return serialize(
static_cast<char>(int8));
566 const uint16_t ushort_t)
568 return serialize(
static_cast<int16_t
>(ushort_t));
578 const int16_t short_t);
587 const uint32_t ulong_t)
589 return serialize(
static_cast<int32_t
>(ulong_t));
599 const int32_t long_t);
610 return serialize(
static_cast<uint16_t
>(wchar));
620 const uint64_t ulonglong_t)
622 return serialize(
static_cast<int64_t
>(ulonglong_t));
632 const int64_t longlong_t);
641 const float float_t);
650 const double double_t);
660 const long double ldouble_t);
680 return serialize(
static_cast<const char*
>(string_t));
690 const char* string_t);
699 const wchar_t* string_t);
709 const std::string& string_t)
722 const std::wstring& string_t)
734 template <
size_t MAX_CHARS>
747 template<
class _T,
size_t _Size>
749 const std::array<_T, _Size>& array_t)
773 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
774 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
776 const std::vector<_T>& vector_t)
780 serialize(
static_cast<int32_t
>(vector_t.size()));
803 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
804 std::is_arithmetic<_T>::value>
::type* =
nullptr>
806 const std::vector<_T>& vector_t)
808 state state_before_error(*
this);
810 serialize(
static_cast<int32_t
>(vector_t.size()));
824 serialized_member_size_ = get_serialized_member_size<_T>();
838 const std::vector<bool>& vector_t)
849 template<class _K, class _T, typename std::enable_if<!std::is_enum<_T>::value &&
850 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
852 const std::map<_K, _T>& map_t)
856 serialize(
static_cast<int32_t
>(map_t.size()));
860 for (
auto it_pair = map_t.begin(); it_pair != map_t.end(); ++it_pair)
883 template<class _K, class _T, typename std::enable_if<std::is_enum<_T>::value ||
884 std::is_arithmetic<_T>::value>
::type* =
nullptr>
886 const std::map<_K, _T>& map_t)
890 serialize(
static_cast<int32_t
>(map_t.size()));
894 for (
auto it_pair = map_t.begin(); it_pair != map_t.end(); ++it_pair)
917 template<
size_t N,
typename std::enable_if < (N < 9) > ::type* =
nullptr>
919 const std::bitset<N>& value)
921 return serialize(static_cast<u
int8_t>(value.to_u
long()));
924 template<
size_t N,
typename std::enable_if < (8 < N && N < 17) > ::type* =
nullptr>
926 const std::bitset<N>& value)
928 return serialize(static_cast<u
int16_t>(value.to_u
long()));
931 template<
size_t N,
typename std::enable_if < (16 < N && N < 33) > ::type* =
nullptr>
933 const std::bitset<N>& value)
935 return serialize(static_cast<u
int32_t>(value.to_u
long()));
938 template<
size_t N,
typename std::enable_if < (32 < N && N < 65) > ::type* =
nullptr>
940 const std::bitset<N>& value)
942 return serialize(static_cast<u
int64_t>(value.to_ul
long()));
1009 const uint8_t* octet_t,
1010 size_t num_elements)
1012 return serialize_array(
reinterpret_cast<const char*
>(octet_t), num_elements);
1024 size_t num_elements);
1036 size_t num_elements)
1038 return serialize_array(
reinterpret_cast<const char*
>(int8), num_elements);
1050 const uint16_t* ushort_t,
1051 size_t num_elements)
1053 return serialize_array(
reinterpret_cast<const int16_t*
>(ushort_t), num_elements);
1064 const int16_t* short_t,
1065 size_t num_elements);
1076 const uint32_t* ulong_t,
1077 size_t num_elements)
1079 return serialize_array(
reinterpret_cast<const int32_t*
>(ulong_t), num_elements);
1090 const int32_t* long_t,
1091 size_t num_elements);
1101 const wchar_t* wchar,
1102 size_t num_elements);
1113 const uint64_t* ulonglong_t,
1114 size_t num_elements)
1116 return serialize_array(
reinterpret_cast<const int64_t*
>(ulonglong_t), num_elements);
1127 const int64_t* longlong_t,
1128 size_t num_elements);
1138 const float* float_t,
1139 size_t num_elements);
1149 const double* double_t,
1150 size_t num_elements);
1161 const long double* ldouble_t,
1162 size_t num_elements);
1173 size_t num_elements);
1184 const std::string* string_t,
1185 size_t num_elements)
1203 const std::wstring* string_t,
1204 size_t num_elements)
1221 template<
size_t MAX_CHARS>
1224 size_t num_elements)
1240 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1241 std::is_arithmetic<_T>::value>
::type* =
nullptr>
1243 const std::vector<_T>& value)
1257 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1258 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
1260 const std::vector<_T>& value)
1281 const std::vector<_T>& value,
1311 const std::vector<bool>& value)
1325 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1326 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
1328 const _T* sequence_t,
1329 size_t num_elements)
1333 serialize(
static_cast<int32_t
>(num_elements));
1357 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1358 std::is_arithmetic<_T>::value>
::type* =
nullptr>
1360 const _T* sequence_t,
1361 size_t num_elements)
1363 state state_before_error(*
this);
1365 serialize(
static_cast<int32_t
>(num_elements));
1379 serialized_member_size_ = get_serialized_member_size<_T>();
1395 const _T* sequence_t,
1396 size_t num_elements,
1427 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>
::type* =
nullptr,
typename =
void>
1474 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
1476 int32_t>::value>
::type* =
nullptr>
1480 int32_t decode_value {0};
1482 value =
static_cast<_T
>(decode_value);
1494 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
1496 uint32_t>::value>
::type* =
nullptr>
1500 uint32_t decode_value {0};
1502 value =
static_cast<_T
>(decode_value);
1514 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
1516 int16_t>::value>
::type* =
nullptr>
1520 int16_t decode_value {0};
1522 value =
static_cast<_T
>(decode_value);
1534 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
1536 uint16_t>::value>
::type* =
nullptr>
1540 uint16_t decode_value {0};
1542 value =
static_cast<_T
>(decode_value);
1554 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
1556 int8_t>::value>
::type* =
nullptr>
1560 int8_t decode_value {0};
1562 value =
static_cast<_T
>(decode_value);
1574 typename std::enable_if<std::is_enum<_T>::value>
::type* =
nullptr,
1576 uint8_t>::value>
::type* =
nullptr>
1580 uint8_t decode_value {0};
1582 value =
static_cast<_T
>(decode_value);
1596 return deserialize(
reinterpret_cast<char&
>(octet_t));
1618 return deserialize(
reinterpret_cast<char&
>(int8));
1631 return deserialize(
reinterpret_cast<int16_t&
>(ushort_t));
1653 return deserialize(
reinterpret_cast<int32_t&
>(ulong_t));
1677 wchar =
static_cast<wchar_t>(
ret);
1689 uint64_t& ulonglong_t)
1691 return deserialize(
reinterpret_cast<int64_t&
>(ulonglong_t));
1701 int64_t& longlong_t);
1729 long double& ldouble_t);
1761 wchar_t*& string_t);
1771 std::string& string_t)
1773 uint32_t length = 0;
1775 string_t.assign(str, length);
1787 std::wstring& string_t)
1789 uint32_t length = 0;
1801 template <
size_t MAX_CHARS>
1805 uint32_t length = 0;
1807 value = std::string(str, length);
1817 template<
class _T,
size_t _Size>
1819 std::array<_T, _Size>& array_t)
1823 uint32_t dheader {0};
1834 if (
offset_ - offset != dheader)
1853 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1854 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
1856 std::vector<_T>& vector_t)
1858 uint32_t sequence_length {0};
1862 uint32_t dheader {0};
1869 if (0 == sequence_length)
1876 vector_t.resize(sequence_length);
1880 while (
offset_ - offset < dheader &&
count < sequence_length)
1886 if (
offset_ - offset != dheader)
1893 state state_before_error(*
this);
1897 if (sequence_length == 0)
1912 vector_t.resize(sequence_length);
1931 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1932 std::is_arithmetic<_T>::value>
::type* =
nullptr>
1934 std::vector<_T>& vector_t)
1936 uint32_t sequence_length = 0;
1937 state state_before_error(*
this);
1941 if (sequence_length == 0)
1956 vector_t.resize(sequence_length);
1976 std::vector<bool>& vector_t)
1987 template<class _K, class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1988 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
1990 std::map<_K, _T>& map_t)
1994 uint32_t dheader {0};
1999 uint32_t map_length {0};
2005 while (
offset_ - offset < dheader &&
count < map_length)
2015 if (
offset_ - offset != dheader)
2022 uint32_t sequence_length = 0;
2023 state state_(*
this);
2029 for (uint32_t i = 0; i < sequence_length; ++i)
2054 template<class _K, class _T, typename std::enable_if<std::is_enum<_T>::value ||
2055 std::is_arithmetic<_T>::value>
::type* =
nullptr>
2057 std::map<_K, _T>& map_t)
2059 uint32_t sequence_length = 0;
2060 state state_(*
this);
2066 for (uint32_t i = 0; i < sequence_length; ++i)
2091 template<
size_t N,
typename std::enable_if < (N < 9) > ::type* =
nullptr>
2093 std::bitset<N>& value)
2095 u
int8_t decode_value {0};
2096 deserialize(decode_value);
2097 value = decode_value;
2101 template<
size_t N,
typename std::enable_if < (8 < N && N < 17) > ::type* =
nullptr>
2103 std::bitset<N>& value)
2105 u
int16_t decode_value {0};
2106 deserialize(decode_value);
2107 value = decode_value;
2111 template<
size_t N,
typename std::enable_if < (16 < N && N < 33) > ::type* =
nullptr>
2113 std::bitset<N>& value)
2115 u
int32_t decode_value {0};
2116 deserialize(decode_value);
2117 value = decode_value;
2121 template<
size_t N,
typename std::enable_if < (32 < N && N < 65) > ::type* =
nullptr>
2123 std::bitset<N>& value)
2125 u
int64_t decode_value {0};
2126 deserialize(decode_value);
2127 value = decode_value;
2145 size_t num_elements)
2165 size_t num_elements,
2196 size_t num_elements)
2210 size_t num_elements);
2222 size_t num_elements)
2237 size_t num_elements)
2251 size_t num_elements);
2263 size_t num_elements)
2277 size_t num_elements);
2288 size_t num_elements);
2299 uint64_t* ulonglong_t,
2300 size_t num_elements)
2302 return deserialize_array(
reinterpret_cast<int64_t*
>(ulonglong_t), num_elements);
2313 int64_t* longlong_t,
2314 size_t num_elements);
2325 size_t num_elements);
2336 size_t num_elements);
2347 long double* ldouble_t,
2348 size_t num_elements);
2359 size_t num_elements);
2371 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
2372 std::is_arithmetic<_T>::value>
::type* =
nullptr>
2374 std::vector<_T>& value)
2391 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
2392 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
2394 std::vector<_T>& value)
2398 uint32_t dheader {0};
2403 while (
offset_ - offset < dheader &&
count < value.size())
2409 if (
offset_ - offset != dheader)
2435 std::vector<_T>& value,
2468 std::vector<bool>& value)
2484 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
2485 !std::is_arithmetic<_T>::value>
::type* =
nullptr>
2488 size_t& num_elements)
2490 uint32_t sequence_length {0};
2494 uint32_t dheader {0};
2503 sequence_t =
reinterpret_cast<_T*
>(calloc(sequence_length,
sizeof(_T)));
2506 while (
offset_ - offset < dheader &&
count < sequence_length)
2512 if (
offset_ - offset != dheader)
2526 state state_before_error(*
this);
2539 sequence_t =
reinterpret_cast<_T*
>(calloc(sequence_length,
sizeof(_T)));
2551 num_elements = sequence_length;
2564 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
2565 std::is_arithmetic<_T>::value>
::type* =
nullptr>
2568 size_t& num_elements)
2570 uint32_t sequence_length = 0;
2571 state state_before_error(*
this);
2577 sequence_t =
reinterpret_cast<_T*
>(calloc(sequence_length,
sizeof(_T)));
2588 num_elements = sequence_length;
2605 size_t& num_elements,
2637 std::string*& sequence_t,
2638 size_t& num_elements)
2654 std::wstring*& sequence_t,
2655 size_t& num_elements)
2677 const _T& member_value,
2678 XCdrHeaderSelection header_selection = XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
2700 XCdrHeaderSelection header_selection = XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
2746 "Member size provided by member header is not equal to the real decoded member size");
2794 std::function<
bool (
Cdr&,
const MemberId&)> functor)
2815 if (value.has_value())
2873 bool is_present =
true;
2878 value.reset(is_present);
2898 if (value.is_locked())
2924 if (value.has_value() && value.value().is_locked())
2929 bool is_present =
true;
2934 value.reset(is_present);
2961 const Cdr&) =
delete;
2964 const Cdr&) =
delete;
2967 const std::vector<bool>& vector_t);
2970 const std::vector<bool>& vector_t);
2973 std::vector<bool>& vector_t);
2976 std::vector<bool>& vector_t);
2979 std::string*& sequence_t,
2980 size_t& num_elements);
2983 std::wstring*& sequence_t,
2984 size_t& num_elements);
2993 template<
class _T,
size_t _Size>
2995 const std::array<_T, _Size>* array_t,
2996 size_t num_elements)
2998 return serialize_array(array_t->data(), num_elements * array_t->size());
3008 template<
class _T,
size_t _Size>
3010 std::array<_T, _Size>* array_t,
3011 size_t num_elements)
3024 template<
class _T,
size_t _Size>
3026 std::array<_T, _Size>* array_t,
3027 size_t num_elements,
3040 size_t data_size)
const
3062 size_t min_size_inc);
3093 size_t member_serialized_size);
3113 size_t member_serialized_size);
3126 size_t member_serialized_size);
3137 size_t member_serialized_size);
3172 size_t member_serialized_size);
3194 size_t member_serialized_size);
3207 size_t member_serialized_size);
3219 size_t member_serialized_size);
3416 std::function<
bool (
Cdr&,
const MemberId&)> functor);
3433 std::function<
bool (
Cdr&,
const MemberId&)> functor);
3453 std::function<
bool (
Cdr&,
const MemberId&)> functor);
3554 size_t member_serialized_size);
3556 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
3557 std::is_arithmetic<_T>::value>
::type* =
nullptr>
3570 #endif // _CDR_CDR_H_
EncodingAlgorithmFlag previous_encoding_
Not related with the state. Used by encoding algorithms to store the previous encoding algorithm.
Cdr_DllAPI Cdr & serialize(const wchar_t wchar)
This function serializes a wide-char.
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.
Cdr &(Cdr::*)(Cdr::state &, EncodingAlgorithmFlag) begin_serialize_type_functor
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.
Cdr & serialize(const external< _T > &value)
Encodes an external in the buffer.
bool has_value() const
Checks whether the optional contains a value.
Cdr & serialize_array(const std::array< _T, _Size > *array_t, size_t num_elements)
This function template detects the content type of the STD container array and serializes the array.
Cdr_DllAPI Cdr & deserialize_string_sequence(std::string *&sequence_t, size_t &num_elements)
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,...
TEMPLATE_SPEC Cdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
Cdr_DllAPI Cdr & serialize(const uint32_t ulong_t)
This function serializes an unsigned long.
constexpr SerializedMemberSizeForNextInt get_serialized_member_size() const
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)
@ SERIALIZED_MEMBER_SIZE_4
Serialized member size in a DHEADER.
Cdr &(Cdr::*)(const MemberId &, bool, Cdr::state &, XCdrHeaderSelection) begin_serialize_member_functor
@ SHORT_HEADER
Initially a short member header is allocated and cannot be changed. This option may cause an exceptio...
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 &(Cdr::*)(const MemberId &, bool, Cdr::state &, XCdrHeaderSelection) begin_serialize_opt_member_functor
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 bool operator==(const state &other_state) const
Compares two states.
Cdr & serialize(const std::array< _T, _Size > &array_t)
This function template serializes an array.
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.
state & operator=(const state &state)=delete
TEMPLATE_SPEC Cdr & deserialize(uint16_t &ushort_t)
This function deserializes an unsigned short.
TEMPLATE_SPEC Cdr & serialize(const std::vector< bool > &vector_t)
This function template serializes a sequence of booleans.
TEMPLATE_SPEC Cdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
Cdr & xcdr1_end_serialize_opt_member(const Cdr::state ¤t_state)
Tells to the encoder to finish the encoding of the member.
Cdr_DllAPI Cdr & serialize(const uint8_t &octet_t)
This function serializes an octet.
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.
Cdr & serialize(const _T &value, Endianness endianness)
Encodes the value of a type with a different endianness.
TEMPLATE_SPEC Cdr & serialize_array(const std::wstring *string_t, size_t num_elements)
This function serializes an array of wide-strings.
TEMPLATE_SPEC Cdr & deserialize_array(uint32_t *ulong_t, size_t num_elements)
This function deserializes an array of unsigned longs.
XCdrHeaderSelection header_selection_
Not related with the state. Used by encoding algorithms to store the selected member header version.
TEMPLATE_SPEC Cdr & serialize_array(const int8_t *int8, size_t num_elements)
This function serializes an array of int8_t.
Cdr & serialize(const std::map< _K, _T > &map_t)
This function template serializes a map of non-primitive.
@ 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.
Cdr & deserialize(std::map< _K, _T > &map_t)
This function template deserializes a map of non-primitive.
void reset_alignment()
This function resets the alignment to the current position in the buffer.
Cdr & deserialize(std::array< _T, _Size > &array_t)
This function template deserializes an array.
void deserialize(Cdr &, _T &)
@ BIG_ENDIANNESS
Big endianness.
TEMPLATE_SPEC Cdr & serialize(const std::string &string_t)
This function serializes a std::string.
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 & operator<<(const _T &value)
Encodes the value into the buffer.
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.
Cdr & operator=(const Cdr &)=delete
TEMPLATE_SPEC Cdr & deserialize_array(uint8_t *octet_t, size_t num_elements)
This function deserializes an array of octets.
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.
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)
Cdr & deserialize_array(_T *type_t, size_t num_elements, Endianness endianness)
This function template deserializes an array of non-basic objects with a different endianness.
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
Cdr & deserialize(optional< _T > &value)
Decodes an optional from the buffer.
TEMPLATE_SPEC Cdr & deserialize_array(uint16_t *ushort_t, size_t num_elements)
This function deserializes an array of unsigned shorts.
Cdr & deserialize(optional< external< _T >> &value)
Decodes an optional of an external from the buffer.
EncodingAlgorithmFlag encoding_flag_
Stores the main encoding algorithm.
Cdr_DllAPI bool move_alignment_forward(size_t num_bytes)
This function moves the alignment forward.
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.
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...
@ 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.
TEMPLATE_SPEC Cdr & serialize_array(const uint32_t *ulong_t, size_t num_elements)
This function serializes an array of unsigned longs.
constexpr auto count() -> size_t
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)
Cdr & serialize_array(const std::vector< _T > &value)
Encodes an std::vector of primitives as an array.
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 & deserialize(std::vector< _T > &vector_t)
This function template deserializes a sequence of non-primitive.
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 & serialize_sequence(const _T *sequence_t, size_t num_elements)
This function template serializes a raw sequence of non-primitives.
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.
TEMPLATE_SPEC Cdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
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)
Cdr & deserialize(_T &value, Endianness endianness)
Decodes the value of a type with a different endianness.
This class template manages an external member, a member declared to be external to the storage of a ...
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,...
const T & move(const T &v)
Cdr_DllAPI Cdr & deserialize_bool_array(std::vector< bool > &vector_t)
@ SERIALIZED_MEMBER_SIZE_8
Serialized member size (which is a multiple of 4) in a DHEADER.
Cdr & serialize_sequence(const _T *sequence_t, size_t num_elements, Endianness endianness)
This function template serializes a raw sequence with a different endianness.
Cdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence of non-primitive.
TEMPLATE_SPEC Cdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
Cdr_DllAPI char * get_current_position()
This function returns the current position in the CDR stream.
TEMPLATE_SPEC Cdr & serialize_array(const uint16_t *ushort_t, size_t num_elements)
This function serializes an array of unsigned shorts.
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.
@ LITTLE_ENDIANNESS
Little endianness.
This class template manages an optional contained value, i.e. a value that may or may not be present.
size_t last_data_size_
Stores the last datasize serialized/deserialized when the state was created.
constexpr bool is_multi_array_primitive(...)
Basis.
static const MemberId MEMBER_ID_INVALID
Cdr & serialize_array(const fixed_string< MAX_CHARS > *value, size_t num_elements)
Encodes an array of fixed strings.
void serialize(Cdr &, const _T &)
size_t last_data_size_
Stores the last datasize serialized/deserialized. It's used to optimize.
Cdr_DllAPI Cdr & serialize(const uint64_t ulonglong_t)
This function serializes an unsigned long long.
Cdr &(Cdr::*)(const Cdr::state &) end_serialize_type_functor
TEMPLATE_SPEC Cdr & serialize_array(const uint8_t *octet_t, size_t num_elements)
This function serializes an array of octets.
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.
Cdr & serialize_array(const std::vector< _T > &value, Endianness endianness)
Encodes an std::vector as an array with a different endianness.
enum eprosima::fastcdr::Cdr::SerializedMemberSizeForNextInt NO_SERIALIZED_MEMBER_SIZE
Specifies if a DHEADER was serialized. Used to optimize XCDRv2 member headers.
@ NO_SERIALIZED_MEMBER_SIZE
size_t alignment(size_t data_size) const
Returns the number of bytes needed to align the current position (having as reference the origin) to ...
TEMPLATE_SPEC Cdr & serialize_array(const std::vector< bool > &value)
Encodes an std::vector of booleans as an array.
Cdr & deserialize_array(std::vector< _T > &value)
Decodes an array of primitives on a std::vector.
void xcdr1_serialize_short_member_header(const MemberId &member_id)
XCDR extensions.
Cdr & deserialize_array(std::array< _T, _Size > *array_t, size_t num_elements)
This function template detects the content type of the STD container array and deserializes the array...
This abstract class is used to create exceptions.
CdrVersion cdr_version_
The type of CDR that will be use in serialization/deserialization.
Cdr & deserialize(fixed_string< MAX_CHARS > &value)
Decodes a fixed string.
Cdr & serialize_array(const _T *type_t, size_t num_elements, Endianness endianness)
This function template serializes an array of non-basic objects with a different endianness.
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.
TEMPLATE_SPEC Cdr & serialize_array(const uint64_t *ulonglong_t, size_t num_elements)
This function serializes an array of unsigned long longs.
Cdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements, Endianness endianness)
This function template deserializes a raw sequence with a different endianness. This function allocat...
Cdr_DllAPI Cdr & end_serialize_type(Cdr::state ¤t_state)
Tells to the encoder the encoding of the type finishes.
end_serialize_member_functor end_serialize_member_
TEMPLATE_SPEC Cdr & deserialize_array(int8_t *int8, size_t num_elements)
This function deserializes an array of int8_t.
TEMPLATE_SPEC Cdr & deserialize(std::vector< bool > &vector_t)
This function template deserializes a sequence.
TEMPLATE_SPEC Cdr & deserialize_sequence(std::string *&sequence_t, size_t &num_elements)
This function template deserializes a string sequence. This function allocates memory to store the se...
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,...
constexpr std::uintptr_t align(std::size_t alignment, std::uintptr_t ptr, std::size_t &space)
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.
Cdr & serialize_member(const MemberId &member_id, const optional< _T > &member_value, XCdrHeaderSelection header_selection=XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
Encodes an optional member of a type according to the encoding algorithm used.
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.
Cdr & deserialize_member(optional< _T > &member_value)
Decodes an optional member of a type according to the encoding algorithm used.
Cdr & operator>>(_T &value)
Decodes the value from the buffer.
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 ...
Cdr & deserialize(external< _T > &value)
Decodes an external from the buffer.
@ SERIALIZED_MEMBER_SIZE
Default. No serialized member size in a DHEADER.
Cdr & deserialize_array(std::array< _T, _Size > *array_t, size_t num_elements, Endianness endianness)
This function template detects the content type of STD container array and deserializes the array wit...
Cdr_DllAPI void set_state(const state &state)
Sets a previous state of the CDR serialization process;.
TEMPLATE_SPEC Cdr & serialize_array(const std::string *string_t, size_t num_elements)
This function serializes an array of strings.
std::array< uint8_t, 2 > options_
This attribute stores the option flags when the CDR type is DDS_CDR;.
Cdr & serialize_member(const MemberId &member_id, const _T &member_value, XCdrHeaderSelection header_selection=XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
XCDR extensions.
end_serialize_member_functor end_serialize_opt_member_
const Cdr_DllAPI char * read_string(uint32_t &length)
Template class for non-alloc strings.
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)
Cdr &(Cdr::*)(const Cdr::state &) end_serialize_memberopt__functor
SerializedMemberSizeForNextInt
TEMPLATE_SPEC Cdr & deserialize(std::string &string_t)
This function deserializes a std::string.
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_DllAPI Cdr & serialize(const int8_t int8)
This function serializes an int8_t.
TEMPLATE_SPEC Cdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
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.
Cdr & deserialize(_T &value)
Decodes the value of a type from the buffer.
TEMPLATE_SPEC Cdr & deserialize_array(std::vector< bool > &value)
Decodes an array of booleans on a std::vector.
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)
TEMPLATE_SPEC Cdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
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.
Cdr &(Cdr::*)(EncodingAlgorithmFlag, std::function< bool(Cdr &, const MemberId &)>) deserialize_type_functor
Cdr_DllAPI Cdr & serialize(char *string_t)
This function serializes a string.
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 & serialize(const fixed_string< MAX_CHARS > &value)
Encodes a eprosima::fastcdr::fixed_string in the buffer.
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 ...
Cdr & deserialize_member(_T &member_value)
Decodes a member of a type according to the encoding algorithm used.
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.
Cdr &(Cdr::*)(const Cdr::state &) end_serialize_member_functor
uint32_t get_short_lc(size_t member_serialized_size)
Cdr & serialize(const optional< _T > &value)
Encodes an optional in the buffer.
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.
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.
TEMPLATE_SPEC Cdr & deserialize_array(uint64_t *ulonglong_t, size_t num_elements)
This function deserializes an array of unsigned long longs.
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.
TEMPLATE_SPEC Cdr & deserialize_sequence(std::wstring *&sequence_t, size_t &num_elements)
This function template deserializes a wide-string sequence. This function allocates memory to store t...
Cdr & deserialize_array(std::vector< _T > &value, Endianness endianness)
Decodes an array of non-primitives on a std::vector with a different endianness.
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.
Cdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements)
This function template deserializes a raw sequence of non-primitives. This function allocates memory ...
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.
Cdr_DllAPI Cdr & serialize(const uint16_t ushort_t)
This function serializes an unsigned short.
TEMPLATE_SPEC Cdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43