diff --git a/test/profiling/MemoryTestTypes.h b/test/profiling/MemoryTestTypes.h index 9ba8bb1aa5e..17c8555f938 100644 --- a/test/profiling/MemoryTestTypes.h +++ b/test/profiling/MemoryTestTypes.h @@ -177,7 +177,7 @@ class TestCommandDataType : public eprosima::fastdds::dds::TopicDataType void* data) override; bool compute_key( - eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::SerializedPayload_t* /*payload*/, eprosima::fastdds::rtps::InstanceHandle_t* /*ihandle*/, bool force_md5 = false) override { diff --git a/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp b/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp index 19e96c99f4d..963b3593e76 100644 --- a/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp +++ b/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp @@ -138,7 +138,7 @@ class FooBoundedTypeSupport : public TopicDataType } bool compute_key( - fastdds::rtps::SerializedPayload_t* payload, + fastdds::rtps::SerializedPayload_t* /*payload*/, fastdds::rtps::InstanceHandle_t* /*handle*/, bool /*force_md5*/) override { diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx index 5957e1d7df1..5093f253fd8 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; AliasStructPubSubType::AliasStructPubSubType() { - setName("AliasStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(AliasStruct::getMaxCdrSerializedSize()); -#else - AliasStruct_max_cdr_typesize; -#endif + set_name("AliasStruct"); + uint32_t type_size = AliasStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = AliasStruct_max_key_cdr_typesize > 16 ? AliasStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = AliasStruct_max_key_cdr_typesize > 16 ? AliasStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } AliasStructPubSubType::~AliasStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool AliasStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool AliasStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool AliasStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool AliasStructPubSubType::deserialize( return true; } -std::function AliasStructPubSubType::getSerializedSizeProvider( +uint32_t AliasStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* AliasStructPubSubType::createData() +void* AliasStructPubSubType::create_data() { return reinterpret_cast(new AliasStruct()); } -void AliasStructPubSubType::deleteData( +void AliasStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool AliasStructPubSubType::getKey( +bool AliasStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + AliasStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool AliasStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool AliasStructPubSubType::getKey( const AliasStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), AliasStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || AliasStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp index efef4820a40..f5f946356d1 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "alias_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated alias_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER typedef uint32_t MyLong; typedef int16_t MyShort; @@ -57,13 +57,6 @@ class AliasStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~AliasStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -73,24 +66,23 @@ class AliasStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -105,10 +97,6 @@ class AliasStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -129,8 +117,8 @@ class AliasStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx index 21aa3f8ab17..8f6ee392146 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; NestedArrayElementPubSubType::NestedArrayElementPubSubType() { - setName("NestedArrayElement"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(NestedArrayElement::getMaxCdrSerializedSize()); -#else - NestedArrayElement_max_cdr_typesize; -#endif + set_name("NestedArrayElement"); + uint32_t type_size = NestedArrayElement_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = NestedArrayElement_max_key_cdr_typesize > 16 ? NestedArrayElement_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = NestedArrayElement_max_key_cdr_typesize > 16 ? NestedArrayElement_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } NestedArrayElementPubSubType::~NestedArrayElementPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool NestedArrayElementPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool NestedArrayElementPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool NestedArrayElementPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool NestedArrayElementPubSubType::deserialize( return true; } -std::function NestedArrayElementPubSubType::getSerializedSizeProvider( +uint32_t NestedArrayElementPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* NestedArrayElementPubSubType::createData() +void* NestedArrayElementPubSubType::create_data() { return reinterpret_cast(new NestedArrayElement()); } -void NestedArrayElementPubSubType::deleteData( +void NestedArrayElementPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool NestedArrayElementPubSubType::getKey( +bool NestedArrayElementPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + NestedArrayElement data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool NestedArrayElementPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool NestedArrayElementPubSubType::getKey( const NestedArrayElement* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), NestedArrayElement_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || NestedArrayElement_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -226,26 +213,21 @@ void NestedArrayElementPubSubType::register_type_object_representation() ComplexArrayElementPubSubType::ComplexArrayElementPubSubType() { - setName("ComplexArrayElement"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ComplexArrayElement::getMaxCdrSerializedSize()); -#else - ComplexArrayElement_max_cdr_typesize; -#endif + set_name("ComplexArrayElement"); + uint32_t type_size = ComplexArrayElement_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ComplexArrayElement_max_key_cdr_typesize > 16 ? ComplexArrayElement_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = ComplexArrayElement_max_key_cdr_typesize > 16 ? ComplexArrayElement_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ComplexArrayElementPubSubType::~ComplexArrayElementPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -263,12 +245,10 @@ bool ComplexArrayElementPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -283,11 +263,7 @@ bool ComplexArrayElementPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -304,11 +280,7 @@ bool ComplexArrayElementPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -325,52 +297,62 @@ bool ComplexArrayElementPubSubType::deserialize( return true; } -std::function ComplexArrayElementPubSubType::getSerializedSizeProvider( +uint32_t ComplexArrayElementPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* ComplexArrayElementPubSubType::createData() +void* ComplexArrayElementPubSubType::create_data() { return reinterpret_cast(new ComplexArrayElement()); } -void ComplexArrayElementPubSubType::deleteData( +void ComplexArrayElementPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ComplexArrayElementPubSubType::getKey( +bool ComplexArrayElementPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ComplexArrayElement data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ComplexArrayElementPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -378,35 +360,27 @@ bool ComplexArrayElementPubSubType::getKey( const ComplexArrayElement* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ComplexArrayElement_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ComplexArrayElement_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -419,26 +393,21 @@ void ComplexArrayElementPubSubType::register_type_object_representation() ArrayStructPubSubType::ArrayStructPubSubType() { - setName("ArrayStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ArrayStruct::getMaxCdrSerializedSize()); -#else - ArrayStruct_max_cdr_typesize; -#endif + set_name("ArrayStruct"); + uint32_t type_size = ArrayStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ArrayStruct_max_key_cdr_typesize > 16 ? ArrayStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = ArrayStruct_max_key_cdr_typesize > 16 ? ArrayStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ArrayStructPubSubType::~ArrayStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -456,12 +425,10 @@ bool ArrayStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -476,11 +443,7 @@ bool ArrayStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -497,11 +460,7 @@ bool ArrayStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -518,52 +477,62 @@ bool ArrayStructPubSubType::deserialize( return true; } -std::function ArrayStructPubSubType::getSerializedSizeProvider( +uint32_t ArrayStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* ArrayStructPubSubType::createData() +void* ArrayStructPubSubType::create_data() { return reinterpret_cast(new ArrayStruct()); } -void ArrayStructPubSubType::deleteData( +void ArrayStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ArrayStructPubSubType::getKey( +bool ArrayStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ArrayStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ArrayStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -571,35 +540,27 @@ bool ArrayStructPubSubType::getKey( const ArrayStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ArrayStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ArrayStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp index 0d0672b8fc1..9397608fc4b 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "array_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated array_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class NestedArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTyp eProsima_user_DllExport ~NestedArrayElementPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class NestedArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTyp eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class NestedArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTyp #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class NestedArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTyp #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -143,13 +131,6 @@ class ComplexArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTy eProsima_user_DllExport ~ComplexArrayElementPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -159,24 +140,23 @@ class ComplexArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTy eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -191,10 +171,6 @@ class ComplexArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTy #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -215,8 +191,8 @@ class ComplexArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataTy #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -234,13 +210,6 @@ class ArrayStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~ArrayStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -250,24 +219,23 @@ class ArrayStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -282,10 +250,6 @@ class ArrayStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -306,8 +270,8 @@ class ArrayStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx index a42af45f42c..32167de6781 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; BitmaskStructPubSubType::BitmaskStructPubSubType() { - setName("BitmaskStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(BitmaskStruct::getMaxCdrSerializedSize()); -#else - BitmaskStruct_max_cdr_typesize; -#endif + set_name("BitmaskStruct"); + uint32_t type_size = BitmaskStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = BitmaskStruct_max_key_cdr_typesize > 16 ? BitmaskStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = BitmaskStruct_max_key_cdr_typesize > 16 ? BitmaskStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } BitmaskStructPubSubType::~BitmaskStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool BitmaskStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool BitmaskStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool BitmaskStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool BitmaskStructPubSubType::deserialize( return true; } -std::function BitmaskStructPubSubType::getSerializedSizeProvider( +uint32_t BitmaskStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* BitmaskStructPubSubType::createData() +void* BitmaskStructPubSubType::create_data() { return reinterpret_cast(new BitmaskStruct()); } -void BitmaskStructPubSubType::deleteData( +void BitmaskStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool BitmaskStructPubSubType::getKey( +bool BitmaskStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + BitmaskStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool BitmaskStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool BitmaskStructPubSubType::getKey( const BitmaskStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), BitmaskStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || BitmaskStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp index df42d2f96aa..33c1e246a47 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "bitmask_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated bitmask_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class BitmaskStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~BitmaskStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class BitmaskStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class BitmaskStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class BitmaskStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx index d327fd7adb3..6d2156195ce 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; BitsetStructPubSubType::BitsetStructPubSubType() { - setName("BitsetStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(BitsetStruct::getMaxCdrSerializedSize()); -#else - BitsetStruct_max_cdr_typesize; -#endif + set_name("BitsetStruct"); + uint32_t type_size = BitsetStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = BitsetStruct_max_key_cdr_typesize > 16 ? BitsetStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = BitsetStruct_max_key_cdr_typesize > 16 ? BitsetStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } BitsetStructPubSubType::~BitsetStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool BitsetStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool BitsetStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool BitsetStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool BitsetStructPubSubType::deserialize( return true; } -std::function BitsetStructPubSubType::getSerializedSizeProvider( +uint32_t BitsetStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* BitsetStructPubSubType::createData() +void* BitsetStructPubSubType::create_data() { return reinterpret_cast(new BitsetStruct()); } -void BitsetStructPubSubType::deleteData( +void BitsetStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool BitsetStructPubSubType::getKey( +bool BitsetStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + BitsetStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool BitsetStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool BitsetStructPubSubType::getKey( const BitsetStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), BitsetStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || BitsetStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp index 299306c4338..3aa7ddfdecc 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "bitset_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated bitset_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class BitsetStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~BitsetStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class BitsetStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class BitsetStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class BitsetStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx index e6d63cec8b4..a8ca8ab7bce 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; EnumStructPubSubType::EnumStructPubSubType() { - setName("EnumStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(EnumStruct::getMaxCdrSerializedSize()); -#else - EnumStruct_max_cdr_typesize; -#endif + set_name("EnumStruct"); + uint32_t type_size = EnumStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = EnumStruct_max_key_cdr_typesize > 16 ? EnumStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = EnumStruct_max_key_cdr_typesize > 16 ? EnumStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } EnumStructPubSubType::~EnumStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool EnumStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool EnumStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool EnumStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool EnumStructPubSubType::deserialize( return true; } -std::function EnumStructPubSubType::getSerializedSizeProvider( +uint32_t EnumStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* EnumStructPubSubType::createData() +void* EnumStructPubSubType::create_data() { return reinterpret_cast(new EnumStruct()); } -void EnumStructPubSubType::deleteData( +void EnumStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool EnumStructPubSubType::getKey( +bool EnumStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + EnumStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool EnumStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool EnumStructPubSubType::getKey( const EnumStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), EnumStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || EnumStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp index 4a0e3122b01..66bd6bea195 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "enum_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated enum_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class EnumStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~EnumStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class EnumStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class EnumStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class EnumStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx index 87070348864..250dc010571 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; FinalStructPubSubType::FinalStructPubSubType() { - setName("FinalStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(FinalStruct::getMaxCdrSerializedSize()); -#else - FinalStruct_max_cdr_typesize; -#endif + set_name("FinalStruct"); + uint32_t type_size = FinalStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = FinalStruct_max_key_cdr_typesize > 16 ? FinalStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = FinalStruct_max_key_cdr_typesize > 16 ? FinalStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } FinalStructPubSubType::~FinalStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool FinalStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool FinalStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool FinalStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool FinalStructPubSubType::deserialize( return true; } -std::function FinalStructPubSubType::getSerializedSizeProvider( +uint32_t FinalStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* FinalStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* FinalStructPubSubType::create_data() { return reinterpret_cast(new FinalStruct()); } -void FinalStructPubSubType::deleteData( +void FinalStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool FinalStructPubSubType::getKey( +bool FinalStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + FinalStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool FinalStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool FinalStructPubSubType::getKey( const FinalStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), FinalStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || FinalStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -226,26 +213,21 @@ void FinalStructPubSubType::register_type_object_representation() MutableStructPubSubType::MutableStructPubSubType() { - setName("MutableStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(MutableStruct::getMaxCdrSerializedSize()); -#else - MutableStruct_max_cdr_typesize; -#endif + set_name("MutableStruct"); + uint32_t type_size = MutableStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = MutableStruct_max_key_cdr_typesize > 16 ? MutableStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = MutableStruct_max_key_cdr_typesize > 16 ? MutableStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } MutableStructPubSubType::~MutableStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -263,12 +245,10 @@ bool MutableStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -283,11 +263,7 @@ bool MutableStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -304,11 +280,7 @@ bool MutableStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -325,52 +297,62 @@ bool MutableStructPubSubType::deserialize( return true; } -std::function MutableStructPubSubType::getSerializedSizeProvider( +uint32_t MutableStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* MutableStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* MutableStructPubSubType::create_data() { return reinterpret_cast(new MutableStruct()); } -void MutableStructPubSubType::deleteData( +void MutableStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool MutableStructPubSubType::getKey( +bool MutableStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + MutableStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool MutableStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -378,35 +360,27 @@ bool MutableStructPubSubType::getKey( const MutableStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), MutableStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || MutableStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -419,26 +393,21 @@ void MutableStructPubSubType::register_type_object_representation() AppendableStructPubSubType::AppendableStructPubSubType() { - setName("AppendableStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(AppendableStruct::getMaxCdrSerializedSize()); -#else - AppendableStruct_max_cdr_typesize; -#endif + set_name("AppendableStruct"); + uint32_t type_size = AppendableStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = AppendableStruct_max_key_cdr_typesize > 16 ? AppendableStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = AppendableStruct_max_key_cdr_typesize > 16 ? AppendableStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } AppendableStructPubSubType::~AppendableStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -456,12 +425,10 @@ bool AppendableStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -476,11 +443,7 @@ bool AppendableStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -497,11 +460,7 @@ bool AppendableStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -518,52 +477,62 @@ bool AppendableStructPubSubType::deserialize( return true; } -std::function AppendableStructPubSubType::getSerializedSizeProvider( +uint32_t AppendableStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* AppendableStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* AppendableStructPubSubType::create_data() { return reinterpret_cast(new AppendableStruct()); } -void AppendableStructPubSubType::deleteData( +void AppendableStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool AppendableStructPubSubType::getKey( +bool AppendableStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + AppendableStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool AppendableStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -571,35 +540,27 @@ bool AppendableStructPubSubType::getKey( const AppendableStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), AppendableStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || AppendableStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -612,26 +573,21 @@ void AppendableStructPubSubType::register_type_object_representation() ExtensibilityStructPubSubType::ExtensibilityStructPubSubType() { - setName("ExtensibilityStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ExtensibilityStruct::getMaxCdrSerializedSize()); -#else - ExtensibilityStruct_max_cdr_typesize; -#endif + set_name("ExtensibilityStruct"); + uint32_t type_size = ExtensibilityStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ExtensibilityStruct_max_key_cdr_typesize > 16 ? ExtensibilityStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = ExtensibilityStruct_max_key_cdr_typesize > 16 ? ExtensibilityStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ExtensibilityStructPubSubType::~ExtensibilityStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -649,12 +605,10 @@ bool ExtensibilityStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -669,11 +623,7 @@ bool ExtensibilityStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -690,11 +640,7 @@ bool ExtensibilityStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -711,52 +657,62 @@ bool ExtensibilityStructPubSubType::deserialize( return true; } -std::function ExtensibilityStructPubSubType::getSerializedSizeProvider( +uint32_t ExtensibilityStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* ExtensibilityStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* ExtensibilityStructPubSubType::create_data() { return reinterpret_cast(new ExtensibilityStruct()); } -void ExtensibilityStructPubSubType::deleteData( +void ExtensibilityStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ExtensibilityStructPubSubType::getKey( +bool ExtensibilityStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ExtensibilityStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ExtensibilityStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -764,35 +720,27 @@ bool ExtensibilityStructPubSubType::getKey( const ExtensibilityStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ExtensibilityStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ExtensibilityStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp index 28ad65cb910..0acf7fdb93c 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "extensibility_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated extensibility_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER #ifndef SWIG @@ -85,13 +85,6 @@ class FinalStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~FinalStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -101,24 +94,23 @@ class FinalStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -133,10 +125,6 @@ class FinalStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return is_plain_xcdrv1_impl(); - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -163,8 +151,8 @@ class FinalStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; private: @@ -198,13 +186,6 @@ class MutableStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~MutableStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -214,24 +195,23 @@ class MutableStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -246,10 +226,6 @@ class MutableStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -270,8 +246,8 @@ class MutableStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -289,13 +265,6 @@ class AppendableStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~AppendableStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -305,24 +274,23 @@ class AppendableStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -337,10 +305,6 @@ class AppendableStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -361,8 +325,8 @@ class AppendableStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -380,13 +344,6 @@ class ExtensibilityStructPubSubType : public eprosima::fastdds::dds::TopicDataTy eProsima_user_DllExport ~ExtensibilityStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -396,24 +353,23 @@ class ExtensibilityStructPubSubType : public eprosima::fastdds::dds::TopicDataTy eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -428,10 +384,6 @@ class ExtensibilityStructPubSubType : public eprosima::fastdds::dds::TopicDataTy #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -452,8 +404,8 @@ class ExtensibilityStructPubSubType : public eprosima::fastdds::dds::TopicDataTy #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx index 4a48941b222..6250ac91171 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; ImportantStructPubSubType::ImportantStructPubSubType() { - setName("ImportantStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ImportantStruct::getMaxCdrSerializedSize()); -#else - ImportantStruct_max_cdr_typesize; -#endif + set_name("ImportantStruct"); + uint32_t type_size = ImportantStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = ImportantStruct_max_key_cdr_typesize > 16 ? ImportantStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = true; + uint32_t key_length = ImportantStruct_max_key_cdr_typesize > 16 ? ImportantStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ImportantStructPubSubType::~ImportantStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool ImportantStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool ImportantStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool ImportantStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool ImportantStructPubSubType::deserialize( return true; } -std::function ImportantStructPubSubType::getSerializedSizeProvider( +uint32_t ImportantStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* ImportantStructPubSubType::createData() +void* ImportantStructPubSubType::create_data() { return reinterpret_cast(new ImportantStruct()); } -void ImportantStructPubSubType::deleteData( +void ImportantStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ImportantStructPubSubType::getKey( +bool ImportantStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ImportantStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ImportantStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool ImportantStructPubSubType::getKey( const ImportantStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ImportantStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ImportantStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -226,26 +213,21 @@ void ImportantStructPubSubType::register_type_object_representation() KeyStructPubSubType::KeyStructPubSubType() { - setName("KeyStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(KeyStruct::getMaxCdrSerializedSize()); -#else - KeyStruct_max_cdr_typesize; -#endif + set_name("KeyStruct"); + uint32_t type_size = KeyStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = KeyStruct_max_key_cdr_typesize > 16 ? KeyStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = true; + uint32_t key_length = KeyStruct_max_key_cdr_typesize > 16 ? KeyStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } KeyStructPubSubType::~KeyStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -263,12 +245,10 @@ bool KeyStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -283,11 +263,7 @@ bool KeyStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -304,11 +280,7 @@ bool KeyStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -325,52 +297,62 @@ bool KeyStructPubSubType::deserialize( return true; } -std::function KeyStructPubSubType::getSerializedSizeProvider( +uint32_t KeyStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* KeyStructPubSubType::createData() +void* KeyStructPubSubType::create_data() { return reinterpret_cast(new KeyStruct()); } -void KeyStructPubSubType::deleteData( +void KeyStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool KeyStructPubSubType::getKey( +bool KeyStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + KeyStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool KeyStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -378,35 +360,27 @@ bool KeyStructPubSubType::getKey( const KeyStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), KeyStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || KeyStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp index bb3d4678554..f25e64d92e3 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "key_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated key_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class ImportantStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~ImportantStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class ImportantStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class ImportantStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class ImportantStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -143,13 +131,6 @@ class KeyStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~KeyStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -159,24 +140,23 @@ class KeyStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -191,10 +171,6 @@ class KeyStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -215,8 +191,8 @@ class KeyStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx index 8c30463bdcc..6349d35495e 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; ValueStructPubSubType::ValueStructPubSubType() { - setName("ValueStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ValueStruct::getMaxCdrSerializedSize()); -#else - ValueStruct_max_cdr_typesize; -#endif + set_name("ValueStruct"); + uint32_t type_size = ValueStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ValueStruct_max_key_cdr_typesize > 16 ? ValueStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = ValueStruct_max_key_cdr_typesize > 16 ? ValueStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ValueStructPubSubType::~ValueStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool ValueStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool ValueStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool ValueStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool ValueStructPubSubType::deserialize( return true; } -std::function ValueStructPubSubType::getSerializedSizeProvider( +uint32_t ValueStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* ValueStructPubSubType::createData() +void* ValueStructPubSubType::create_data() { return reinterpret_cast(new ValueStruct()); } -void ValueStructPubSubType::deleteData( +void ValueStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ValueStructPubSubType::getKey( +bool ValueStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ValueStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ValueStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool ValueStructPubSubType::getKey( const ValueStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ValueStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ValueStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -226,26 +213,21 @@ void ValueStructPubSubType::register_type_object_representation() MapStructPubSubType::MapStructPubSubType() { - setName("MapStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(MapStruct::getMaxCdrSerializedSize()); -#else - MapStruct_max_cdr_typesize; -#endif + set_name("MapStruct"); + uint32_t type_size = MapStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = MapStruct_max_key_cdr_typesize > 16 ? MapStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = MapStruct_max_key_cdr_typesize > 16 ? MapStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } MapStructPubSubType::~MapStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -263,12 +245,10 @@ bool MapStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -283,11 +263,7 @@ bool MapStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -304,11 +280,7 @@ bool MapStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -325,52 +297,62 @@ bool MapStructPubSubType::deserialize( return true; } -std::function MapStructPubSubType::getSerializedSizeProvider( +uint32_t MapStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* MapStructPubSubType::createData() +void* MapStructPubSubType::create_data() { return reinterpret_cast(new MapStruct()); } -void MapStructPubSubType::deleteData( +void MapStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool MapStructPubSubType::getKey( +bool MapStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + MapStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool MapStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -378,35 +360,27 @@ bool MapStructPubSubType::getKey( const MapStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), MapStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || MapStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp index 6cffc72f9e0..9f83a37ec08 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "map_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated map_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class ValueStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~ValueStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class ValueStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class ValueStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class ValueStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -143,13 +131,6 @@ class MapStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~MapStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -159,24 +140,23 @@ class MapStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -191,10 +171,6 @@ class MapStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -215,8 +191,8 @@ class MapStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx index 3434ba975ca..0f5af696c22 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; PrimitivesStructPubSubType::PrimitivesStructPubSubType() { - setName("PrimitivesStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(PrimitivesStruct::getMaxCdrSerializedSize()); -#else - PrimitivesStruct_max_cdr_typesize; -#endif + set_name("PrimitivesStruct"); + uint32_t type_size = PrimitivesStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = PrimitivesStruct_max_key_cdr_typesize > 16 ? PrimitivesStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = PrimitivesStruct_max_key_cdr_typesize > 16 ? PrimitivesStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } PrimitivesStructPubSubType::~PrimitivesStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool PrimitivesStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool PrimitivesStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool PrimitivesStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool PrimitivesStructPubSubType::deserialize( return true; } -std::function PrimitivesStructPubSubType::getSerializedSizeProvider( +uint32_t PrimitivesStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* PrimitivesStructPubSubType::createData() +void* PrimitivesStructPubSubType::create_data() { return reinterpret_cast(new PrimitivesStruct()); } -void PrimitivesStructPubSubType::deleteData( +void PrimitivesStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool PrimitivesStructPubSubType::getKey( +bool PrimitivesStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + PrimitivesStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool PrimitivesStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool PrimitivesStructPubSubType::getKey( const PrimitivesStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), PrimitivesStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || PrimitivesStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp index afcc3758609..dc813132db2 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "primitives_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated primitives_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class PrimitivesStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~PrimitivesStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class PrimitivesStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class PrimitivesStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class PrimitivesStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx index 406a1041ea5..030fb441170 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; NestedSequenceElementPubSubType::NestedSequenceElementPubSubType() { - setName("NestedSequenceElement"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(NestedSequenceElement::getMaxCdrSerializedSize()); -#else - NestedSequenceElement_max_cdr_typesize; -#endif + set_name("NestedSequenceElement"); + uint32_t type_size = NestedSequenceElement_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = NestedSequenceElement_max_key_cdr_typesize > 16 ? NestedSequenceElement_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = NestedSequenceElement_max_key_cdr_typesize > 16 ? NestedSequenceElement_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } NestedSequenceElementPubSubType::~NestedSequenceElementPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool NestedSequenceElementPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool NestedSequenceElementPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool NestedSequenceElementPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool NestedSequenceElementPubSubType::deserialize( return true; } -std::function NestedSequenceElementPubSubType::getSerializedSizeProvider( +uint32_t NestedSequenceElementPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* NestedSequenceElementPubSubType::createData() +void* NestedSequenceElementPubSubType::create_data() { return reinterpret_cast(new NestedSequenceElement()); } -void NestedSequenceElementPubSubType::deleteData( +void NestedSequenceElementPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool NestedSequenceElementPubSubType::getKey( +bool NestedSequenceElementPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + NestedSequenceElement data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool NestedSequenceElementPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool NestedSequenceElementPubSubType::getKey( const NestedSequenceElement* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), NestedSequenceElement_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || NestedSequenceElement_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -226,26 +213,21 @@ void NestedSequenceElementPubSubType::register_type_object_representation() ComplexSequenceElementPubSubType::ComplexSequenceElementPubSubType() { - setName("ComplexSequenceElement"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ComplexSequenceElement::getMaxCdrSerializedSize()); -#else - ComplexSequenceElement_max_cdr_typesize; -#endif + set_name("ComplexSequenceElement"); + uint32_t type_size = ComplexSequenceElement_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ComplexSequenceElement_max_key_cdr_typesize > 16 ? ComplexSequenceElement_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = ComplexSequenceElement_max_key_cdr_typesize > 16 ? ComplexSequenceElement_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ComplexSequenceElementPubSubType::~ComplexSequenceElementPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -263,12 +245,10 @@ bool ComplexSequenceElementPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -283,11 +263,7 @@ bool ComplexSequenceElementPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -304,11 +280,7 @@ bool ComplexSequenceElementPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -325,52 +297,62 @@ bool ComplexSequenceElementPubSubType::deserialize( return true; } -std::function ComplexSequenceElementPubSubType::getSerializedSizeProvider( +uint32_t ComplexSequenceElementPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* ComplexSequenceElementPubSubType::createData() +void* ComplexSequenceElementPubSubType::create_data() { return reinterpret_cast(new ComplexSequenceElement()); } -void ComplexSequenceElementPubSubType::deleteData( +void ComplexSequenceElementPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ComplexSequenceElementPubSubType::getKey( +bool ComplexSequenceElementPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ComplexSequenceElement data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ComplexSequenceElementPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -378,35 +360,27 @@ bool ComplexSequenceElementPubSubType::getKey( const ComplexSequenceElement* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ComplexSequenceElement_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ComplexSequenceElement_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -419,26 +393,21 @@ void ComplexSequenceElementPubSubType::register_type_object_representation() SequenceStructPubSubType::SequenceStructPubSubType() { - setName("SequenceStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(SequenceStruct::getMaxCdrSerializedSize()); -#else - SequenceStruct_max_cdr_typesize; -#endif + set_name("SequenceStruct"); + uint32_t type_size = SequenceStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = SequenceStruct_max_key_cdr_typesize > 16 ? SequenceStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = SequenceStruct_max_key_cdr_typesize > 16 ? SequenceStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } SequenceStructPubSubType::~SequenceStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -456,12 +425,10 @@ bool SequenceStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -476,11 +443,7 @@ bool SequenceStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -497,11 +460,7 @@ bool SequenceStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -518,52 +477,62 @@ bool SequenceStructPubSubType::deserialize( return true; } -std::function SequenceStructPubSubType::getSerializedSizeProvider( +uint32_t SequenceStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* SequenceStructPubSubType::createData() +void* SequenceStructPubSubType::create_data() { return reinterpret_cast(new SequenceStruct()); } -void SequenceStructPubSubType::deleteData( +void SequenceStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool SequenceStructPubSubType::getKey( +bool SequenceStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + SequenceStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool SequenceStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -571,35 +540,27 @@ bool SequenceStructPubSubType::getKey( const SequenceStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), SequenceStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || SequenceStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp index d0c2498530d..305c6dedcea 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "sequence_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated sequence_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class NestedSequenceElementPubSubType : public eprosima::fastdds::dds::TopicData eProsima_user_DllExport ~NestedSequenceElementPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class NestedSequenceElementPubSubType : public eprosima::fastdds::dds::TopicData eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class NestedSequenceElementPubSubType : public eprosima::fastdds::dds::TopicData #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class NestedSequenceElementPubSubType : public eprosima::fastdds::dds::TopicData #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -143,13 +131,6 @@ class ComplexSequenceElementPubSubType : public eprosima::fastdds::dds::TopicDat eProsima_user_DllExport ~ComplexSequenceElementPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -159,24 +140,23 @@ class ComplexSequenceElementPubSubType : public eprosima::fastdds::dds::TopicDat eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -191,10 +171,6 @@ class ComplexSequenceElementPubSubType : public eprosima::fastdds::dds::TopicDat #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -215,8 +191,8 @@ class ComplexSequenceElementPubSubType : public eprosima::fastdds::dds::TopicDat #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -234,13 +210,6 @@ class SequenceStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~SequenceStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -250,24 +219,23 @@ class SequenceStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -282,10 +250,6 @@ class SequenceStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -306,8 +270,8 @@ class SequenceStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx index 68f1132a3dc..bd0f053744c 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; StringStructPubSubType::StringStructPubSubType() { - setName("StringStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(StringStruct::getMaxCdrSerializedSize()); -#else - StringStruct_max_cdr_typesize; -#endif + set_name("StringStruct"); + uint32_t type_size = StringStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = StringStruct_max_key_cdr_typesize > 16 ? StringStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = StringStruct_max_key_cdr_typesize > 16 ? StringStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } StringStructPubSubType::~StringStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool StringStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool StringStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool StringStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool StringStructPubSubType::deserialize( return true; } -std::function StringStructPubSubType::getSerializedSizeProvider( +uint32_t StringStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* StringStructPubSubType::createData() +void* StringStructPubSubType::create_data() { return reinterpret_cast(new StringStruct()); } -void StringStructPubSubType::deleteData( +void StringStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool StringStructPubSubType::getKey( +bool StringStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + StringStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool StringStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool StringStructPubSubType::getKey( const StringStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), StringStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || StringStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp index e8e375b8b10..893879e22f0 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "string_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated string_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class StringStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~StringStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class StringStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class StringStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class StringStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx index 90e507519ec..798a5158000 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; GrandparentStructPubSubType::GrandparentStructPubSubType() { - setName("GrandparentStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(GrandparentStruct::getMaxCdrSerializedSize()); -#else - GrandparentStruct_max_cdr_typesize; -#endif + set_name("GrandparentStruct"); + uint32_t type_size = GrandparentStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = GrandparentStruct_max_key_cdr_typesize > 16 ? GrandparentStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = GrandparentStruct_max_key_cdr_typesize > 16 ? GrandparentStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } GrandparentStructPubSubType::~GrandparentStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool GrandparentStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool GrandparentStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool GrandparentStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool GrandparentStructPubSubType::deserialize( return true; } -std::function GrandparentStructPubSubType::getSerializedSizeProvider( +uint32_t GrandparentStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* GrandparentStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* GrandparentStructPubSubType::create_data() { return reinterpret_cast(new GrandparentStruct()); } -void GrandparentStructPubSubType::deleteData( +void GrandparentStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool GrandparentStructPubSubType::getKey( +bool GrandparentStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + GrandparentStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool GrandparentStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool GrandparentStructPubSubType::getKey( const GrandparentStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), GrandparentStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || GrandparentStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -226,26 +213,21 @@ void GrandparentStructPubSubType::register_type_object_representation() ParentStructPubSubType::ParentStructPubSubType() { - setName("ParentStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ParentStruct::getMaxCdrSerializedSize()); -#else - ParentStruct_max_cdr_typesize; -#endif + set_name("ParentStruct"); + uint32_t type_size = ParentStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ParentStruct_max_key_cdr_typesize > 16 ? ParentStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = ParentStruct_max_key_cdr_typesize > 16 ? ParentStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } ParentStructPubSubType::~ParentStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -263,12 +245,10 @@ bool ParentStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -283,11 +263,7 @@ bool ParentStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -304,11 +280,7 @@ bool ParentStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -325,52 +297,62 @@ bool ParentStructPubSubType::deserialize( return true; } -std::function ParentStructPubSubType::getSerializedSizeProvider( +uint32_t ParentStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* ParentStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* ParentStructPubSubType::create_data() { return reinterpret_cast(new ParentStruct()); } -void ParentStructPubSubType::deleteData( +void ParentStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool ParentStructPubSubType::getKey( +bool ParentStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + ParentStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool ParentStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -378,35 +360,27 @@ bool ParentStructPubSubType::getKey( const ParentStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), ParentStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || ParentStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -419,26 +393,21 @@ void ParentStructPubSubType::register_type_object_representation() NestedStructElementPubSubType::NestedStructElementPubSubType() { - setName("NestedStructElement"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(NestedStructElement::getMaxCdrSerializedSize()); -#else - NestedStructElement_max_cdr_typesize; -#endif + set_name("NestedStructElement"); + uint32_t type_size = NestedStructElement_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = NestedStructElement_max_key_cdr_typesize > 16 ? NestedStructElement_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = NestedStructElement_max_key_cdr_typesize > 16 ? NestedStructElement_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } NestedStructElementPubSubType::~NestedStructElementPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -456,12 +425,10 @@ bool NestedStructElementPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -476,11 +443,7 @@ bool NestedStructElementPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -497,11 +460,7 @@ bool NestedStructElementPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -518,52 +477,62 @@ bool NestedStructElementPubSubType::deserialize( return true; } -std::function NestedStructElementPubSubType::getSerializedSizeProvider( +uint32_t NestedStructElementPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* NestedStructElementPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* NestedStructElementPubSubType::create_data() { return reinterpret_cast(new NestedStructElement()); } -void NestedStructElementPubSubType::deleteData( +void NestedStructElementPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool NestedStructElementPubSubType::getKey( +bool NestedStructElementPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + NestedStructElement data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool NestedStructElementPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -571,35 +540,27 @@ bool NestedStructElementPubSubType::getKey( const NestedStructElement* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), NestedStructElement_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || NestedStructElement_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; @@ -612,26 +573,21 @@ void NestedStructElementPubSubType::register_type_object_representation() StructStructPubSubType::StructStructPubSubType() { - setName("StructStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(StructStruct::getMaxCdrSerializedSize()); -#else - StructStruct_max_cdr_typesize; -#endif + set_name("StructStruct"); + uint32_t type_size = StructStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = StructStruct_max_key_cdr_typesize > 16 ? StructStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = StructStruct_max_key_cdr_typesize > 16 ? StructStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } StructStructPubSubType::~StructStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -649,12 +605,10 @@ bool StructStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -669,11 +623,7 @@ bool StructStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -690,11 +640,7 @@ bool StructStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -711,52 +657,62 @@ bool StructStructPubSubType::deserialize( return true; } -std::function StructStructPubSubType::getSerializedSizeProvider( +uint32_t StructStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* StructStructPubSubType::createData() + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* StructStructPubSubType::create_data() { return reinterpret_cast(new StructStruct()); } -void StructStructPubSubType::deleteData( +void StructStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool StructStructPubSubType::getKey( +bool StructStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + StructStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool StructStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -764,35 +720,27 @@ bool StructStructPubSubType::getKey( const StructStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), StructStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || StructStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp index 5a87fd6aa30..f36283e79e8 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "struct_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated struct_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class GrandparentStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~GrandparentStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class GrandparentStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class GrandparentStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class GrandparentStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -143,13 +131,6 @@ class ParentStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~ParentStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -159,24 +140,23 @@ class ParentStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -191,10 +171,6 @@ class ParentStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -215,8 +191,8 @@ class ParentStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -234,13 +210,6 @@ class NestedStructElementPubSubType : public eprosima::fastdds::dds::TopicDataTy eProsima_user_DllExport ~NestedStructElementPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -250,24 +219,23 @@ class NestedStructElementPubSubType : public eprosima::fastdds::dds::TopicDataTy eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -282,10 +250,6 @@ class NestedStructElementPubSubType : public eprosima::fastdds::dds::TopicDataTy #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -306,8 +270,8 @@ class NestedStructElementPubSubType : public eprosima::fastdds::dds::TopicDataTy #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; @@ -325,13 +289,6 @@ class StructStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~StructStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -341,24 +298,23 @@ class StructStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -373,10 +329,6 @@ class StructStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -397,8 +349,8 @@ class StructStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; }; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx index 22ad76ec79b..61562796504 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx @@ -33,26 +33,21 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; UnionStructPubSubType::UnionStructPubSubType() { - setName("UnionStruct"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(UnionStruct::getMaxCdrSerializedSize()); -#else - UnionStruct_max_cdr_typesize; -#endif + set_name("UnionStruct"); + uint32_t type_size = UnionStruct_max_cdr_typesize; type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = UnionStruct_max_key_cdr_typesize > 16 ? UnionStruct_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = UnionStruct_max_key_cdr_typesize > 16 ? UnionStruct_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); } UnionStructPubSubType::~UnionStructPubSubType() { - if (m_keyBuffer != nullptr) + if (key_buffer_ != nullptr) { - free(m_keyBuffer); + free(key_buffer_); } } @@ -70,12 +65,10 @@ bool UnionStructPubSubType::serialize( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 ser.set_encoding_flag( data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 try { @@ -90,11 +83,7 @@ bool UnionStructPubSubType::serialize( } // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 return true; } @@ -111,11 +100,7 @@ bool UnionStructPubSubType::deserialize( eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that deserializes the data. - 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); // Deserialize encapsulation. deser.read_encapsulation(); @@ -132,52 +117,62 @@ bool UnionStructPubSubType::deserialize( return true; } -std::function UnionStructPubSubType::getSerializedSizeProvider( +uint32_t UnionStructPubSubType::calculate_serialized_size( const void* const data, DataRepresentationId_t data_representation) { - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } } -void* UnionStructPubSubType::createData() +void* UnionStructPubSubType::create_data() { return reinterpret_cast(new UnionStruct()); } -void UnionStructPubSubType::deleteData( +void UnionStructPubSubType::delete_data( void* data) { delete(reinterpret_cast(data)); } -bool UnionStructPubSubType::getKey( +bool UnionStructPubSubType::compute_key( + SerializedPayload_t* payload, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + UnionStruct data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool UnionStructPubSubType::compute_key( const void* const data, InstanceHandle_t* handle, bool force_md5) { - if (!m_isGetKeyDefined) + if (!is_compute_key_provided) { return false; } @@ -185,35 +180,27 @@ bool UnionStructPubSubType::getKey( const UnionStruct* p_type = static_cast(data); // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), UnionStruct_max_key_cdr_typesize); // Object that serializes the data. eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 if (force_md5 || UnionStruct_max_key_cdr_typesize > 16) { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_md5.digest[i]; + handle->value[i] = md5_.digest[i]; } } else { for (uint8_t i = 0; i < 16; ++i) { - handle->value[i] = m_keyBuffer[i]; + handle->value[i] = key_buffer_[i]; } } return true; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp index bbd1b9e3986..86d15c99e42 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp @@ -32,10 +32,10 @@ #include "union_struct.hpp" -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) #error \ Generated union_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER +#endif // FASTDDS_GEN_API_VER /*! @@ -52,13 +52,6 @@ class UnionStructPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport ~UnionStructPubSubType() override; - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - eProsima_user_DllExport bool serialize( const void* const data, eprosima::fastdds::rtps::SerializedPayload_t* payload, @@ -68,24 +61,23 @@ class UnionStructPubSubType : public eprosima::fastdds::dds::TopicDataType eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( + eProsima_user_DllExport uint32_t calculate_serialized_size( const void* const data, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - eProsima_user_DllExport bool getKey( + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( const void* const data, eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - eProsima_user_DllExport void* createData() override; + eProsima_user_DllExport void* create_data() override; - eProsima_user_DllExport void deleteData( + eProsima_user_DllExport void delete_data( void* data) override; //Register TypeObject representation in Fast DDS TypeObjectRegistry @@ -100,10 +92,6 @@ class UnionStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED #ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } eProsima_user_DllExport inline bool is_plain( eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override @@ -124,8 +112,8 @@ class UnionStructPubSubType : public eprosima::fastdds::dds::TopicDataType #endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; };