15#ifndef _FASTCDR_CDR_H_
16#define _FASTCDR_CDR_H_
43#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
75 typedef enum : uint8_t
122 const state& other_state)
const;
276 size_t current_alignment,
279 return (data_size - (current_alignment % data_size)) & (data_size - 1);
380 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>::type* =
nullptr,
typename =
void>
430 int32_t>::value>::type* =
nullptr>
434 return serialize(
static_cast<int32_t
>(value));
448 uint32_t>::value>::type* =
nullptr>
452 return serialize(
static_cast<uint32_t
>(value));
466 int16_t>::value>::type* =
nullptr>
470 return serialize(
static_cast<int16_t
>(value));
484 uint16_t>::value>::type* =
nullptr>
488 return serialize(
static_cast<uint16_t
>(value));
502 int8_t>::value>::type* =
nullptr>
506 return serialize(
static_cast<int8_t
>(value));
520 uint8_t>::value>::type* =
nullptr>
524 return serialize(
static_cast<uint8_t
>(value));
534 const uint8_t& octet_t);
561 const uint16_t ushort_t);
570 const int16_t short_t);
579 const uint32_t ulong_t);
588 const int32_t long_t);
597 const wchar_t wchar);
606 const uint64_t ulonglong_t);
615 const int64_t longlong_t);
624 const float float_t);
633 const double double_t);
643 const long double ldouble_t);
670 const char* string_t);
679 const wchar_t* string_t);
693 const char* c_str = string_t.
c_str();
694 const auto str_len = strlen(c_str);
695 if (string_t.
size() > str_len)
723 template <
size_t MAX_CHARS>
736 template<
class _T,
size_t _Size>
762 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
792 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
797 state state_before_error(*
this);
813 serialized_member_size_ = get_serialized_member_size<_T>();
838 template<class _K, class _T, typename std::enable_if<!std::is_enum<_T>::value &&
849 for (
auto it_pair = map_t.
begin(); it_pair != map_t.
end(); ++it_pair)
872 template<class _K, class _T, typename std::enable_if<std::is_enum<_T>::value ||
883 for (
auto it_pair = map_t.
begin(); it_pair != map_t.
end(); ++it_pair)
906 template<
size_t N,
typename std::enable_if < (N < 9) > ::type* =
nullptr>
908 const std::bitset<N>& value)
910 return serialize(static_cast<u
int8_t>(value.to_u
long()));
913 template<
size_t N,
typename std::enable_if < (8 < N && N < 17) > ::type* =
nullptr>
915 const std::bitset<N>& value)
917 return serialize(static_cast<u
int16_t>(value.to_u
long()));
920 template<
size_t N,
typename std::enable_if < (16 < N && N < 33) > ::type* =
nullptr>
922 const std::bitset<N>& value)
924 return serialize(static_cast<u
int32_t>(value.to_u
long()));
927 template<
size_t N,
typename std::enable_if < (32 < N && N < 65) > ::type* =
nullptr>
929 const std::bitset<N>& value)
931 return serialize(static_cast<u
int64_t>(value.to_ul
long()));
950 for (
size_t count = 0; count < num_elements; ++count)
998 const uint8_t* octet_t,
1001 return serialize_array(
reinterpret_cast<const char*
>(octet_t), num_elements);
1013 size_t num_elements);
1025 size_t num_elements)
1027 return serialize_array(
reinterpret_cast<const char*
>(int8), num_elements);
1039 const uint16_t* ushort_t,
1040 size_t num_elements)
1042 return serialize_array(
reinterpret_cast<const int16_t*
>(ushort_t), num_elements);
1053 const int16_t* short_t,
1054 size_t num_elements);
1065 const uint32_t* ulong_t,
1066 size_t num_elements)
1068 return serialize_array(
reinterpret_cast<const int32_t*
>(ulong_t), num_elements);
1079 const int32_t* long_t,
1080 size_t num_elements);
1090 const wchar_t* wchar,
1091 size_t num_elements);
1102 const uint64_t* ulonglong_t,
1103 size_t num_elements)
1105 return serialize_array(
reinterpret_cast<const int64_t*
>(ulonglong_t), num_elements);
1116 const int64_t* longlong_t,
1117 size_t num_elements);
1127 const float* float_t,
1128 size_t num_elements);
1138 const double* double_t,
1139 size_t num_elements);
1150 const long double* ldouble_t,
1151 size_t num_elements);
1162 size_t num_elements);
1174 size_t num_elements)
1176 for (
size_t count = 0; count < num_elements; ++count)
1193 size_t num_elements)
1195 for (
size_t count = 0; count < num_elements; ++count)
1210 template<
size_t MAX_CHARS>
1213 size_t num_elements)
1215 for (
size_t count = 0; count < num_elements; ++count)
1229 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1246 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1314 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1317 const _T* sequence_t,
1318 size_t num_elements)
1322 serialize(
static_cast<int32_t
>(num_elements));
1346 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1349 const _T* sequence_t,
1350 size_t num_elements)
1352 state state_before_error(*
this);
1354 serialize(
static_cast<int32_t
>(num_elements));
1368 serialized_member_size_ = get_serialized_member_size<_T>();
1384 const _T* sequence_t,
1385 size_t num_elements,
1416 template<class _T, typename std::enable_if<!std::is_enum<_T>::value>::type* =
nullptr,
typename =
void>
1465 int32_t>::value>::type* =
nullptr>
1469 int32_t decode_value {0};
1471 value =
static_cast<_T
>(decode_value);
1485 uint32_t>::value>::type* =
nullptr>
1489 uint32_t decode_value {0};
1491 value =
static_cast<_T
>(decode_value);
1505 int16_t>::value>::type* =
nullptr>
1509 int16_t decode_value {0};
1511 value =
static_cast<_T
>(decode_value);
1525 uint16_t>::value>::type* =
nullptr>
1529 uint16_t decode_value {0};
1531 value =
static_cast<_T
>(decode_value);
1545 int8_t>::value>::type* =
nullptr>
1549 int8_t decode_value {0};
1551 value =
static_cast<_T
>(decode_value);
1565 uint8_t>::value>::type* =
nullptr>
1569 uint8_t decode_value {0};
1571 value =
static_cast<_T
>(decode_value);
1585 return deserialize(
reinterpret_cast<char&
>(octet_t));
1607 return deserialize(
reinterpret_cast<char&
>(int8));
1620 return deserialize(
reinterpret_cast<int16_t&
>(ushort_t));
1642 return deserialize(
reinterpret_cast<int32_t&
>(ulong_t));
1666 wchar =
static_cast<wchar_t>(ret);
1678 uint64_t& ulonglong_t)
1680 return deserialize(
reinterpret_cast<int64_t&
>(ulonglong_t));
1690 int64_t& longlong_t);
1718 long double& ldouble_t);
1750 wchar_t*& string_t);
1762 uint32_t length = 0;
1764 string_t.
assign(str, length);
1778 uint32_t length = 0;
1790 template <
size_t MAX_CHARS>
1794 uint32_t length = 0;
1796 value.
assign(str, length);
1806 template<
class _T,
size_t _Size>
1812 uint32_t dheader {0};
1817 while (
offset_ - offset < dheader && count < _Size)
1823 if (
offset_ - offset != dheader)
1842 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1847 uint32_t sequence_length {0};
1851 uint32_t dheader {0};
1858 if (0 == sequence_length)
1865 vector_t.
resize(sequence_length);
1869 while (
offset_ - offset < dheader && count < sequence_length)
1875 if (
offset_ - offset != dheader)
1882 state state_before_error(*
this);
1886 if (sequence_length == 0)
1901 vector_t.
resize(sequence_length);
1920 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
1925 uint32_t sequence_length = 0;
1926 state state_before_error(*
this);
1930 if (sequence_length == 0)
1945 vector_t.
resize(sequence_length);
1976 template<class _K, class _T, typename std::enable_if<!std::is_enum<_T>::value &&
1983 uint32_t dheader {0};
1988 uint32_t map_length {0};
1994 while (
offset_ - offset < dheader && count < map_length)
2004 if (
offset_ - offset != dheader)
2011 uint32_t sequence_length = 0;
2012 state state_(*
this);
2020 for (uint32_t i = 0; i < sequence_length; ++i)
2045 template<class _K, class _T, typename std::enable_if<std::is_enum<_T>::value ||
2050 uint32_t sequence_length = 0;
2051 state state_(*
this);
2057 for (uint32_t i = 0; i < sequence_length; ++i)
2082 template<
size_t N,
typename std::enable_if < (N < 9) > ::type* =
nullptr>
2084 std::bitset<N>& value)
2086 u
int8_t decode_value {0};
2087 deserialize(decode_value);
2088 value = decode_value;
2092 template<
size_t N,
typename std::enable_if < (8 < N && N < 17) > ::type* =
nullptr>
2094 std::bitset<N>& value)
2096 u
int16_t decode_value {0};
2097 deserialize(decode_value);
2098 value = decode_value;
2102 template<
size_t N,
typename std::enable_if < (16 < N && N < 33) > ::type* =
nullptr>
2104 std::bitset<N>& value)
2106 u
int32_t decode_value {0};
2107 deserialize(decode_value);
2108 value = decode_value;
2112 template<
size_t N,
typename std::enable_if < (32 < N && N < 65) > ::type* =
nullptr>
2114 std::bitset<N>& value)
2116 u
int64_t decode_value {0};
2117 deserialize(decode_value);
2118 value = decode_value;
2136 size_t num_elements)
2138 for (
size_t count = 0; count < num_elements; ++count)
2156 size_t num_elements,
2187 size_t num_elements)
2201 size_t num_elements);
2213 size_t num_elements)
2228 size_t num_elements)
2242 size_t num_elements);
2254 size_t num_elements)
2268 size_t num_elements);
2279 size_t num_elements);
2290 uint64_t* ulonglong_t,
2291 size_t num_elements)
2293 return deserialize_array(
reinterpret_cast<int64_t*
>(ulonglong_t), num_elements);
2304 int64_t* longlong_t,
2305 size_t num_elements);
2316 size_t num_elements);
2327 size_t num_elements);
2338 long double* ldouble_t,
2339 size_t num_elements);
2350 size_t num_elements);
2362 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
2382 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
2389 uint32_t dheader {0};
2394 while (
offset_ - offset < dheader && count < value.
size())
2400 if (
offset_ - offset != dheader)
2475 template<class _T, typename std::enable_if<!std::is_enum<_T>::value &&
2479 size_t& num_elements)
2481 uint32_t sequence_length {0};
2485 uint32_t dheader {0};
2494 sequence_t =
reinterpret_cast<_T*
>(calloc(sequence_length,
sizeof(_T)));
2497 while (
offset_ - offset < dheader && count < sequence_length)
2503 if (
offset_ - offset != dheader)
2517 state state_before_error(*
this);
2530 sequence_t =
reinterpret_cast<_T*
>(calloc(sequence_length,
sizeof(_T)));
2542 num_elements = sequence_length;
2555 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
2559 size_t& num_elements)
2561 uint32_t sequence_length = 0;
2562 state state_before_error(*
this);
2568 sequence_t =
reinterpret_cast<_T*
>(calloc(sequence_length,
sizeof(_T)));
2579 num_elements = sequence_length;
2596 size_t& num_elements,
2629 size_t& num_elements)
2646 size_t& num_elements)
2668 const _T& member_value,
2737 "Member size provided by member header is not equal to the real decoded member size");
2846 bool is_present =
true;
2851 value.
reset(is_present);
2897 if (value.has_value() && value.value().is_locked())
2902 bool is_present =
true;
2907 value.reset(is_present);
2929 const state& state);
2934 const Cdr&) =
delete;
2937 const Cdr&) =
delete;
2953 size_t& num_elements);
2957 size_t& num_elements);
2966 template<
class _T,
size_t _Size>
2969 size_t num_elements)
2981 template<
class _T,
size_t _Size>
2984 size_t num_elements)
2997 template<
class _T,
size_t _Size>
3000 size_t num_elements,
3013 size_t data_size)
const
3035 size_t min_size_inc);
3066 size_t member_serialized_size);
3086 size_t member_serialized_size);
3099 size_t member_serialized_size);
3110 size_t member_serialized_size);
3145 size_t member_serialized_size);
3167 size_t member_serialized_size);
3180 size_t member_serialized_size);
3192 size_t member_serialized_size);
3533 size_t member_serialized_size);
3535 template<class _T, typename std::enable_if<std::is_enum<_T>::value ||
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.
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.
state & operator=(const state &state)=delete
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...
TEMPLATE_SPEC Cdr & serialize(const std::vector< bool > &vector_t)
This function template serializes a sequence of booleans.
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 & deserialize(std::vector< _T > &vector_t)
This function template deserializes a sequence of non-primitive.
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.
TEMPLATE_SPEC Cdr & deserialize(std::string &string_t)
This function deserializes a std::string.
Cdr & serialize_sequence(const _T *sequence_t, size_t num_elements, Endianness endianness)
This function template serializes a raw sequence with a different endianness.
TEMPLATE_SPEC Cdr & serialize(const std::string &string_t)
This function serializes a std::string.
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.
TEMPLATE_SPEC Cdr & deserialize_array(std::vector< bool > &value)
Decodes an array of booleans on a std::vector.
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.
Cdr & deserialize_sequence(_T *&sequence_t, size_t &num_elements)
This function template deserializes a raw sequence of non-primitives. This function allocates memory ...
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 & serialize(const std::map< _K, _T > &map_t)
This function template serializes a map of non-primitive.
TEMPLATE_SPEC Cdr & serialize_array(const uint16_t *ushort_t, size_t num_elements)
This function serializes an array of unsigned shorts.
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 ...
Cdr_DllAPI Cdr & deserialize_bool_array(std::vector< bool > &vector_t)
Cdr_DllAPI Cdr & deserialize_bool_sequence(std::vector< bool > &vector_t)
Cdr &(Cdr::*)(const MemberId &, bool, Cdr::state &, XCdrHeaderSelection) begin_serialize_member_functor
TEMPLATE_SPEC Cdr & serialize_array(const uint64_t *ulonglong_t, size_t num_elements)
This function serializes an array of unsigned long longs.
Cdr_DllAPI const char * read_string(uint32_t &length)
Cdr_DllAPI const std::wstring read_wstring(uint32_t &length)
Cdr &(Cdr::*)(EncodingAlgorithmFlag, std::function< bool(Cdr &, const MemberId &)>) deserialize_type_functor
Cdr &(Cdr::*)(const Cdr::state &) end_serialize_type_functor
Cdr & deserialize(optional< external< _T > > &value)
Decodes an optional of an external from the buffer.
Cdr & serialize(const _T &value, Endianness endianness)
Encodes the value of a type with a different endianness.
TEMPLATE_SPEC Cdr & serialize_array(const uint8_t *octet_t, size_t num_elements)
This function serializes an array of octets.
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,...
TEMPLATE_SPEC Cdr & serialize(const std::wstring &string_t)
This function serializes a std::wstring.
@ 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.
Cdr & serialize_sequence(const _T *sequence_t, size_t num_elements)
This function template serializes a raw sequence of non-primitives.
size_t align64_
Align for types equal or greater than 64bits.
TEMPLATE_SPEC Cdr & deserialize(std::wstring &string_t)
This function deserializes a std::wstring.
Cdr & serialize(const optional< _T > &value)
Encodes an optional in the buffer.
Cdr & operator=(const Cdr &)=delete
TEMPLATE_SPEC Cdr & deserialize(uint8_t &octet_t)
This function deserializes an octet.
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 char * get_buffer_pointer()
This function returns the pointer to the current used buffer.
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.
Cdr &(Cdr::*)(Cdr::state &, EncodingAlgorithmFlag) begin_serialize_type_functor
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 & serialize_array(const std::vector< _T > &value)
Encodes an std::vector of primitives as an array.
Cdr & serialize_member(const MemberId &member_id, const _T &member_value, XCdrHeaderSelection header_selection=XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT)
XCDR extensions.
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 ...
TEMPLATE_SPEC Cdr & serialize_array(const int8_t *int8, size_t num_elements)
This function serializes an array of int8_t.
SerializedMemberSizeForNextInt
@ SERIALIZED_MEMBER_SIZE_4
Serialized member size in a DHEADER.
@ SERIALIZED_MEMBER_SIZE
Default. No serialized member size in a DHEADER.
@ NO_SERIALIZED_MEMBER_SIZE
@ 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.
TEMPLATE_SPEC Cdr & deserialize_array(uint64_t *ulonglong_t, size_t num_elements)
This function deserializes an array of unsigned long longs.
TEMPLATE_SPEC Cdr & deserialize(uint16_t &ushort_t)
This function deserializes an unsigned short.
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 & 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...
constexpr SerializedMemberSizeForNextInt get_serialized_member_size() const
Cdr & serialize_array(const fixed_string< MAX_CHARS > *value, size_t num_elements)
Encodes an array of fixed strings.
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_
TEMPLATE_SPEC Cdr & deserialize(uint32_t &ulong_t)
This function deserializes an unsigned long.
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 & deserialize(std::array< _T, _Size > &array_t)
This function template deserializes an array.
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.
TEMPLATE_SPEC Cdr & deserialize(uint64_t &ulonglong_t)
This function deserializes an unsigned long long.
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.
Cdr & serialize(const std::array< _T, _Size > &array_t)
This function template serializes an array.
TEMPLATE_SPEC Cdr & deserialize(int8_t &int8)
This function deserializes an int8_t.
TEMPLATE_SPEC Cdr & deserialize(wchar_t &wchar)
This function deserializes a wide-char.
TEMPLATE_SPEC Cdr & serialize_array(const std::vector< bool > &value)
Encodes an std::vector of booleans as an array.
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...
Cdr &(Cdr::*)(const Cdr::state &) end_serialize_member_functor
Cdr & deserialize_array(std::vector< _T > &value)
Decodes an array of primitives on a std::vector.
begin_serialize_type_functor begin_serialize_type_
Cdr & deserialize(_T &value)
Decodes the value of a type from the buffer.
TEMPLATE_SPEC Cdr & deserialize_array(int8_t *int8, size_t num_elements)
This function deserializes an array of int8_t.
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 & deserialize(optional< _T > &value)
Decodes an optional from the buffer.
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.
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 & deserialize_member(optional< _T > &member_value)
Decodes an optional member of a type according to the encoding algorithm used.
Cdr_DllAPI CdrVersion get_cdr_version() const
Retrieves the CdrVersion used by the instance.
Cdr & deserialize(std::map< _K, _T > &map_t)
This function template deserializes a map of non-primitive.
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 & serialize(const external< _T > &value)
Encodes an external in the buffer.
Cdr_DllAPI void reset()
This function resets the current position in the buffer to the beginning.
TEMPLATE_SPEC Cdr & serialize_array(const uint32_t *ulong_t, size_t num_elements)
This function serializes an array of unsigned longs.
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.
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...
TEMPLATE_SPEC Cdr & deserialize_array(uint16_t *ushort_t, size_t num_elements)
This function deserializes an array of unsigned shorts.
Cdr &(Cdr::*)(const MemberId &, bool, Cdr::state &, XCdrHeaderSelection) begin_serialize_opt_member_functor
Cdr & operator>>(_T &value)
Decodes the value from the buffer.
Cdr &(Cdr::*)(const Cdr::state &) end_serialize_memberopt__functor
Cdr_DllAPI Cdr & deserialize_wstring_sequence(std::wstring *&sequence_t, size_t &num_elements)
Cdr & serialize(const std::vector< _T > &vector_t)
This function template serializes a sequence of non-primitive.
Endianness
This enumeration represents endianness types.
@ LITTLE_ENDIANNESS
Little endianness.
@ BIG_ENDIANNESS
Big endianness.
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)
TEMPLATE_SPEC Cdr & deserialize(std::vector< bool > &vector_t)
This function template deserializes a sequence.
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 & deserialize(external< _T > &value)
Decodes an external from the buffer.
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 & read_encapsulation()
This function reads the encapsulation of the CDR stream. If the CDR stream contains an encapsulation,...
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.
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_
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.
TEMPLATE_SPEC Cdr & serialize_array(const std::wstring *string_t, size_t num_elements)
This function serializes an array of wide-strings.
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 & serialize(const fixed_string< MAX_CHARS > &value)
Encodes a eprosima::fastcdr::fixed_string in the buffer.
Cdr_DllAPI size_t get_serialized_data_length() const
This function returns the length of the serialized data inside the stream.
TEMPLATE_SPEC Cdr & serialize_array(const std::string *string_t, size_t num_elements)
This function serializes an array of strings.
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 ...
TEMPLATE_SPEC Cdr & deserialize_array(uint8_t *octet_t, size_t num_elements)
This function deserializes an array of octets.
void xcdr2_serialize_short_member_header(const MemberId &member_id)
Encodes a short member header of a member according to XCDRv2.
Cdr & deserialize_array(std::vector< _T > &value, Endianness endianness)
Decodes an array of non-primitives on a std::vector with a different endianness.
Cdr_DllAPI Cdr & deserialize_string_sequence(std::string *&sequence_t, size_t &num_elements)
Cdr & serialize_array(const std::vector< _T > &value, Endianness endianness)
Encodes an std::vector as an array with a different endianness.
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)
TEMPLATE_SPEC Cdr & deserialize_array(uint32_t *ulong_t, size_t num_elements)
This function deserializes an array of unsigned longs.
Cdr & deserialize(fixed_string< MAX_CHARS > &value)
Decodes a fixed string.
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 & deserialize(_T &value, Endianness endianness)
Decodes the value of a type with a different endianness.
Cdr & deserialize_member(_T &member_value)
Decodes a member of a type according to the encoding algorithm used.
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....
This class implements the iterator used to go through a FastBuffer.
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.
This class template manages an external member, a member declared to be external to the storage of a ...
bool is_locked() const noexcept
Checks if locked.
This class template manages an optional contained value, i.e. a value that may or may not be present.
void reset(bool initial_engaged=false)
Reset the state of the optional.
bool has_value() const
Checks whether the optional contains a value.
void serialize(Cdr &, const _T &)
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.
constexpr bool is_multi_array_primitive(...)
Basis.
static const MemberId MEMBER_ID_INVALID
void deserialize(Cdr &, _T &)
CdrVersion
This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR.
@ XCDRv2
XCDRv2 encoding defined by standard DDS X-Types 1.3.
Template class for non-alloc strings.
fixed_string & assign(const char *c_array, size_t n_chars) noexcept
Assigns from a char array.
const char * c_str() const noexcept
Converts to C string.