Skip to content

Commit

Permalink
Support of Fast-CDR v1 (#3970)
Browse files Browse the repository at this point in the history
* Refs #19760. Coexist fastcdr v1 and v2

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Coexist fastcdr v1 and v2 [new approach]

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Compile on VS2017

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Fix asan

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Apply suggestion

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Apply suggestion

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Only show serialization methods deprecation in Fast CDR major > 1

Signed-off-by: EduPonz <[email protected]>

* Refs #19760. Fix compilation warnings and errors

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #19760. Fix warnings

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #18687. Trying compile VS2017

Signed-off-by: Ricardo González Moreno <[email protected]>

---------

Signed-off-by: Ricardo González Moreno <[email protected]>
Signed-off-by: EduPonz <[email protected]>
Co-authored-by: EduPonz <[email protected]>
  • Loading branch information
richiware and EduPonz authored Nov 17, 2023
1 parent b18a507 commit 73ff2c1
Show file tree
Hide file tree
Showing 462 changed files with 120,708 additions and 9,644 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ if(NOT BUILD_SHARED_LIBS)
set(FASTDDS_STATIC ON)
endif()

eprosima_find_package(fastcdr 2.0 REQUIRED)
eprosima_find_package(fastcdr REQUIRED)
eprosima_find_thirdparty(Asio asio VERSION 1.10.8)
eprosima_find_thirdparty(TinyXML2 tinyxml2)

Expand Down
2 changes: 1 addition & 1 deletion cmake/packaging/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif()
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")

find_package(fastcdr 2 REQUIRED)
find_package(fastcdr REQUIRED)
find_package(foonathan_memory REQUIRED)
find_package(TinyXML2 QUIET)
@FASTRTPS_INSTALLER_DEPS_ANCILLARY@
Expand Down
10 changes: 7 additions & 3 deletions examples/cpp/dds/AdvancedConfigurationExample/HelloWorld.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ char dummy;
#endif // _WIN32

#include "HelloWorld.h"

#if FASTCDR_VERSION_MAJOR > 1

#include <fastcdr/Cdr.h>


Expand All @@ -36,9 +39,10 @@ using namespace eprosima::fastcdr::exception;
#include <utility>




HelloWorld::HelloWorld()
{

}

HelloWorld::~HelloWorld()
Expand All @@ -65,7 +69,6 @@ HelloWorld& HelloWorld::operator =(

m_index = x.m_index;
m_message = x.m_message;

return *this;
}

Expand All @@ -75,7 +78,6 @@ HelloWorld& HelloWorld::operator =(

m_index = x.m_index;
m_message = std::move(x.m_message);

return *this;
}

Expand Down Expand Up @@ -162,3 +164,5 @@ std::array<char, 20>& HelloWorld::message()

// Include auxiliary functions like for serializing/deserializing.
#include "HelloWorldCdrAux.ipp"

#endif // FASTCDR_VERSION_MAJOR > 1
11 changes: 11 additions & 0 deletions examples/cpp/dds/AdvancedConfigurationExample/HelloWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
* This file was generated by the tool fastddsgen.
*/

#include <fastcdr/config.h>
#include "HelloWorldv1.h"

#if FASTCDR_VERSION_MAJOR > 1

#ifndef _FAST_DDS_GENERATED_HELLOWORLD_H_
#define _FAST_DDS_GENERATED_HELLOWORLD_H_

Expand All @@ -30,6 +35,7 @@
#include <vector>

#include <fastcdr/cdr/fixed_size_string.hpp>
#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>


Expand Down Expand Up @@ -67,6 +73,8 @@ class CdrSizeCalculator;





/*!
* @brief This class represents the structure HelloWorld defined by the user in the IDL file.
* @ingroup HelloWorld
Expand Down Expand Up @@ -182,3 +190,6 @@ class HelloWorld

#endif // _FAST_DDS_GENERATED_HELLOWORLD_H_



#endif // FASTCDR_VERSION_MAJOR > 1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace fastcdr {
class Cdr;
class CdrSizeCalculator;



eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const HelloWorld& data);
Expand All @@ -42,4 +44,5 @@ eProsima_user_DllExport void serialize_key(
} // namespace fastcdr
} // namespace eprosima

#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_
#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -123,4 +124,5 @@ void serialize_key(
} // namespace fastcdr
} // namespace eprosima

#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_
#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
*/


#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include <fastcdr/CdrSizeCalculator.hpp>
#include <fastdds/rtps/common/CdrSerialization.hpp>

#include "HelloWorldPubSubTypes.h"
#include "HelloWorldCdrAux.hpp"
Expand All @@ -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<uint32_t>(HelloWorld::getMaxCdrSerializedSize());
#else
HelloWorld_max_cdr_typesize;
#endif
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
m_typeSize = type_size + 4; /*encapsulation*/
m_isGetKeyDefined = false;
Expand Down Expand Up @@ -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
{
Expand All @@ -83,7 +90,11 @@ bool HelloWorldPubSubType::serialize(
}

// Get the serialized length
#if FASTCDR_VERSION_MAJOR == 1
payload->length = static_cast<uint32_t>(ser.getSerializedDataLength());
#else
payload->length = static_cast<uint32_t>(ser.get_serialized_data_length());
#endif // FASTCDR_VERSION_MAJOR == 1
return true;
}

Expand All @@ -100,7 +111,11 @@ bool HelloWorldPubSubType::deserialize(
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(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();
Expand All @@ -123,13 +138,26 @@ std::function<uint32_t()> 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<uint32_t>(calculator.calculate_serialized_size(
*static_cast<HelloWorld*>(data), current_alignment)) +
4u /*encapsulation*/;
#if FASTCDR_VERSION_MAJOR == 1
static_cast<void>(data_representation);
return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<HelloWorld*>(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<uint32_t>(calculator.calculate_serialized_size(
*static_cast<HelloWorld*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
#endif // FASTCDR_VERSION_MAJOR == 1
};
}

Expand Down Expand Up @@ -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<unsigned int>(ser.getSerializedDataLength()));
#else
m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.get_serialized_data_length()));
#endif // FASTCDR_VERSION_MAJOR == 1
m_md5.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 73ff2c1

Please sign in to comment.