Skip to content

Commit

Permalink
Regenerate Fast DDS docs example types due to Gen release v3.2.1 (#636)
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Jan 11, 2024
1 parent 1a1662e commit 2898e58
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 20 deletions.
7 changes: 4 additions & 3 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorld.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ char dummy;
#endif // _WIN32

#include "HelloWorld.h"

#include <fastcdr/Cdr.h>


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




HelloWorld::HelloWorld()
{

}

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

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

return *this;
}

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

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

return *this;
}

Expand Down Expand Up @@ -162,3 +162,4 @@ std::string& HelloWorld::message()

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

5 changes: 5 additions & 0 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 +68,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 +185,5 @@ class HelloWorld

#endif // _FAST_DDS_GENERATED_HELLOWORLD_H_



7 changes: 5 additions & 2 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@

constexpr uint32_t HelloWorld_max_cdr_typesize {268UL};
constexpr uint32_t HelloWorld_max_key_cdr_typesize {0UL};


namespace eprosima {
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_

6 changes: 4 additions & 2 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorldCdrAux.ipp
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_

62 changes: 49 additions & 13 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx
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
9 changes: 9 additions & 0 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h
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 Expand Up @@ -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<void>(data_representation);
return false;
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN

#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
Expand Down

0 comments on commit 2898e58

Please sign in to comment.