diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorld.cxx b/code/Examples/C++/DDSHelloWorld/src/HelloWorld.cxx index bcda56fb4..ef9331d5d 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorld.cxx +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorld.cxx @@ -27,6 +27,7 @@ char dummy; #endif // _WIN32 #include "HelloWorld.h" + #include @@ -36,9 +37,10 @@ using namespace eprosima::fastcdr::exception; #include + + HelloWorld::HelloWorld() { - } HelloWorld::~HelloWorld() @@ -65,7 +67,6 @@ HelloWorld& HelloWorld::operator =( m_index = x.m_index; m_message = x.m_message; - return *this; } @@ -75,7 +76,6 @@ HelloWorld& HelloWorld::operator =( m_index = x.m_index; m_message = std::move(x.m_message); - return *this; } @@ -162,3 +162,4 @@ std::string& HelloWorld::message() // Include auxiliary functions like for serializing/deserializing. #include "HelloWorldCdrAux.ipp" + diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorld.h b/code/Examples/C++/DDSHelloWorld/src/HelloWorld.h index 0c6d09801..b95bcb5b1 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorld.h +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorld.h @@ -30,6 +30,7 @@ #include #include +#include #include @@ -67,6 +68,8 @@ class CdrSizeCalculator; + + /*! * @brief This class represents the structure HelloWorld defined by the user in the IDL file. * @ingroup HelloWorld @@ -182,3 +185,5 @@ class HelloWorld #endif // _FAST_DDS_GENERATED_HELLOWORLD_H_ + + diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.hpp b/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.hpp index 37b13815b..9f346d306 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.hpp +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.hpp @@ -26,7 +26,7 @@ constexpr uint32_t HelloWorld_max_cdr_typesize {268UL}; constexpr uint32_t HelloWorld_max_key_cdr_typesize {0UL}; - + namespace eprosima { namespace fastcdr { @@ -34,6 +34,8 @@ namespace fastcdr { class Cdr; class CdrSizeCalculator; + + eProsima_user_DllExport void serialize_key( eprosima::fastcdr::Cdr& scdr, const HelloWorld& data); @@ -42,4 +44,5 @@ eProsima_user_DllExport void serialize_key( } // namespace fastcdr } // namespace eprosima -#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ \ No newline at end of file +#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ + diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.ipp b/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.ipp index b9461ff5b..42e91f3cc 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.ipp +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.ipp @@ -34,6 +34,8 @@ using namespace eprosima::fastcdr::exception; namespace eprosima { namespace fastcdr { + + template<> eProsima_user_DllExport size_t calculate_serialized_size( eprosima::fastcdr::CdrSizeCalculator& calculator, @@ -77,7 +79,6 @@ eProsima_user_DllExport void serialize( << eprosima::fastcdr::MemberId(0) << data.index() << eprosima::fastcdr::MemberId(1) << data.message() ; - scdr.end_serialize_type(current_state); } @@ -123,4 +124,5 @@ void serialize_key( } // namespace fastcdr } // namespace eprosima -#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ \ No newline at end of file +#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ + diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx index f4a5ef511..85cb47789 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx @@ -20,9 +20,7 @@ */ -#include -#include -#include +#include #include "HelloWorldPubSubTypes.h" #include "HelloWorldCdrAux.hpp" @@ -31,10 +29,17 @@ using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + + HelloWorldPubSubType::HelloWorldPubSubType() { setName("HelloWorld"); - uint32_t type_size = HelloWorld_max_cdr_typesize; + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(HelloWorld::getMaxCdrSerializedSize()); +#else + HelloWorld_max_cdr_typesize; +#endif type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ m_typeSize = type_size + 4; /*encapsulation*/ m_isGetKeyDefined = false; @@ -65,10 +70,12 @@ bool HelloWorldPubSubType::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 { @@ -83,7 +90,11 @@ bool HelloWorldPubSubType::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; } @@ -100,7 +111,11 @@ bool HelloWorldPubSubType::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); + 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 + ); // Deserialize encapsulation. deser.read_encapsulation(); @@ -123,13 +138,26 @@ std::function HelloWorldPubSubType::getSerializedSizeProvider( { return [data, data_representation]() -> uint32_t { - 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*/; +#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 }; } @@ -161,12 +189,20 @@ bool HelloWorldPubSubType::getKey( HelloWorld_max_key_cdr_typesize); // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); + 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 || HelloWorld_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(); for (uint8_t i = 0; i < 16; ++i) { diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h index 5b325dd1c..cb61cd6ba 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h @@ -38,6 +38,8 @@ #endif // GEN_API_VER + + /*! * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. * @ingroup HelloWorld @@ -102,6 +104,13 @@ class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType return false; } + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + #endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN #ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE