Skip to content

Commit

Permalink
Refs #21349. Regenerate code
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware committed Jul 15, 2024
1 parent 572ee27 commit e27a494
Show file tree
Hide file tree
Showing 28 changed files with 1,669 additions and 2,294 deletions.
2 changes: 1 addition & 1 deletion test/profiling/MemoryTestTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(AliasStruct::getMaxCdrSerializedSize());
#else
AliasStruct_max_cdr_typesize;
#endif
set_name("AliasStruct");
uint32_t type_size = AliasStruct_max_cdr_typesize;
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;
uint32_t keyLength = AliasStruct_max_key_cdr_typesize > 16 ? AliasStruct_max_key_cdr_typesize : 16;
m_keyBuffer = reinterpret_cast<unsigned char*>(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<unsigned char*>(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_);
}
}

Expand All @@ -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
{
Expand All @@ -90,11 +83,7 @@ bool AliasStructPubSubType::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 @@ -111,11 +100,7 @@ bool AliasStructPubSubType::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
#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();
Expand All @@ -132,88 +117,90 @@ bool AliasStructPubSubType::deserialize(
return true;
}

std::function<uint32_t()> 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<void>(data_representation);
return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<AliasStruct*>(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<const AliasStruct*>(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<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const AliasStruct*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}

void* AliasStructPubSubType::createData()
void* AliasStructPubSubType::create_data()
{
return reinterpret_cast<void*>(new AliasStruct());
}

void AliasStructPubSubType::deleteData(
void AliasStructPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<AliasStruct*>(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<void*>(&data)))
{
return compute_key(static_cast<void*>(&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;
}

const AliasStruct* p_type = static_cast<const AliasStruct*>(data);

// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(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<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();
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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<uint32_t()> getSerializedSizeProvider(
const void* const data) override
{
return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION);
}

eProsima_user_DllExport std::function<uint32_t()> 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
Expand All @@ -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
Expand All @@ -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_;

};

Expand Down
Loading

0 comments on commit e27a494

Please sign in to comment.