From 918454a0be3d914b66be3785df4300d362048189 Mon Sep 17 00:00:00 2001 From: adriancampo Date: Thu, 1 Feb 2024 21:00:06 +0100 Subject: [PATCH] Refs #20160: Fixes for TypeInformation serializer Signed-off-by: adriancampo --- .../core/policy/QosPoliciesSerializer.hpp | 20 ++----- .../TypeObjectRegistry.cpp | 58 +++++++++---------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp b/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp index d8a15a752a4..a7f7e478e72 100644 --- a/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp +++ b/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp @@ -1045,7 +1045,7 @@ template<> inline uint32_t QosPoliciesSerializer::cdr_serialized_size( const xtypes::TypeInformationParameter& qos_policy) { - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); size_t current_alignment {0}; size_t size = calculator.calculate_serialized_size(qos_policy.type_information, current_alignment) + 4; return 2 + 2 + static_cast(size); @@ -1056,7 +1056,7 @@ inline bool QosPoliciesSerializer::add_to_cdr_ const xtypes::TypeInformationParameter& qos_policy, fastrtps::rtps::CDRMessage_t* cdr_message) { - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); + eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv2); size_t current_alignment {0}; size_t size = calculator.calculate_serialized_size(qos_policy.type_information, @@ -1065,10 +1065,10 @@ inline bool QosPoliciesSerializer::add_to_cdr_ eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. + eprosima::fastcdr::CdrVersion::XCDRv2); // Object that serializes the data. payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - ser.serialize_encapsulation(); + ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR); ser << qos_policy.type_information; #if FASTCDR_VERSION_MAJOR == 1 @@ -1102,18 +1102,10 @@ inline bool QosPoliciesSerializer::read_conten fastrtps::rtps::CDRMessage::readData(cdr_message, payload.data, parameter_length); // Object that manages the raw buffer. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::CdrVersion::XCDRv2); try { - // Deserialize encapsulation. - deser.read_encapsulation(); - payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - deser >> qos_policy.type_information; qos_policy.assigned(true); } diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp index 5c9708114ca..f08a41b0dc8 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp @@ -843,35 +843,6 @@ const MinimalMapType TypeObjectRegistry::build_minimal_from_complete_map_type( return minimal_map_type; } -const TypeIdentifier TypeObjectRegistry::minimal_from_complete_type_identifier( - const TypeIdentifier& type_id) -{ - if (EK_COMPLETE == type_id._d() || - (TI_PLAIN_SEQUENCE_SMALL == type_id._d() && type_id.seq_sdefn().header().equiv_kind() == EK_COMPLETE) || - (TI_PLAIN_SEQUENCE_LARGE == type_id._d() && type_id.seq_ldefn().header().equiv_kind() == EK_COMPLETE) || - (TI_PLAIN_ARRAY_SMALL == type_id._d() && type_id.array_sdefn().header().equiv_kind() == EK_COMPLETE) || - (TI_PLAIN_ARRAY_LARGE == type_id._d() && type_id.array_ldefn().header().equiv_kind() == EK_COMPLETE) || - (TI_PLAIN_MAP_SMALL == type_id._d() && (type_id.map_sdefn().header().equiv_kind() == EK_COMPLETE || - type_id.map_sdefn().key_identifier()->_d() == EK_COMPLETE)) || - (TI_PLAIN_MAP_LARGE == type_id._d() && (type_id.map_ldefn().header().equiv_kind() == EK_COMPLETE || - type_id.map_ldefn().key_identifier()->_d() == EK_COMPLETE))) - { - std::lock_guard data_guard(type_object_registry_mutex_); - for (const auto& it : local_type_identifiers_) - { - if (it.second.type_identifier1() == type_id) - { - return it.second.type_identifier2(); - } - else if (it.second.type_identifier2() == type_id) - { - return it.second.type_identifier1(); - } - } - } - return type_id; -} - const MinimalEnumeratedType TypeObjectRegistry::build_minimal_from_complete_enumerated_type( const CompleteEnumeratedType& complete_enumerated_type) { @@ -946,6 +917,35 @@ void TypeObjectRegistry::register_primitive_type_identifiers() local_type_identifiers_.insert({char16_type_name, type_ids}); } +const TypeIdentifier TypeObjectRegistry::minimal_from_complete_type_identifier( + const TypeIdentifier& type_id) +{ + if (EK_COMPLETE == type_id._d() || + (TI_PLAIN_SEQUENCE_SMALL == type_id._d() && type_id.seq_sdefn().header().equiv_kind() == EK_COMPLETE) || + (TI_PLAIN_SEQUENCE_LARGE == type_id._d() && type_id.seq_ldefn().header().equiv_kind() == EK_COMPLETE) || + (TI_PLAIN_ARRAY_SMALL == type_id._d() && type_id.array_sdefn().header().equiv_kind() == EK_COMPLETE) || + (TI_PLAIN_ARRAY_LARGE == type_id._d() && type_id.array_ldefn().header().equiv_kind() == EK_COMPLETE) || + (TI_PLAIN_MAP_SMALL == type_id._d() && (type_id.map_sdefn().header().equiv_kind() == EK_COMPLETE || + type_id.map_sdefn().key_identifier()->_d() == EK_COMPLETE)) || + (TI_PLAIN_MAP_LARGE == type_id._d() && (type_id.map_ldefn().header().equiv_kind() == EK_COMPLETE || + type_id.map_ldefn().key_identifier()->_d() == EK_COMPLETE))) + { + std::lock_guard data_guard(type_object_registry_mutex_); + for (const auto& it : local_type_identifiers_) + { + if (it.second.type_identifier1() == type_id) + { + return it.second.type_identifier2(); + } + else if (it.second.type_identifier2() == type_id) + { + return it.second.type_identifier1(); + } + } + } + return type_id; +} + } // xtypes } // dds } // fastdds