Skip to content

Conversation

@Mario-DL
Copy link
Contributor

@Mario-DL Mario-DL commented Jul 23, 2025

Description

This PR:

  • Moves the is_plain() implementation to the CdrAux.ipp. This makes necessary to define new c_scoped free functions for each type with the implementation.
  • Introduces new (de)serialize_array template specializations in the generated types
  • Non-primitive arrays or vectors are now optimally serialized (memcpy) if the types are both:
    • Plain
    • Its max_cdr_serialized_size equals sizeof()

These changes shall be introduced in a new minor.

Related PRs:

Contributor Checklist

  • Commit messages follow the project guidelines.
  • Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally
  • N/A New feature has been documented/Current behavior is correctly described in the documentation.
  • N/A Applicable backports have been included in the description.

Reviewer Checklist

  • The PR has a milestone assigned.
  • The title and description correctly express the PR's purpose.
  • Check contributor checklist is correct.
  • Check CI results: changes do not issue any warning.
  • Check CI results: failing tests are unrelated with the changes.

Comment on lines +54 to +55
eProsima_user_DllExport bool is_$struct.cScopedname$_cdr_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation)
Copy link
Member

@MiguelCompany MiguelCompany Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, we could have the following in Cdr.h:

template<typename _T>
extern bool is_cdr_plain(
        const CdrVersion encoding);

and then generate specializations here.

This way we could use the fully scoped C++ name.

Comment on lines +182 to +187
std::memcpy(
scdr.get_current_position(),
array_ptr,
(array_size - 1) * sizeof($struct.scopedname$));

scdr.jump((array_size -1) * sizeof($struct.scopedname$));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::memcpy(
scdr.get_current_position(),
array_ptr,
(array_size - 1) * sizeof($struct.scopedname$));
scdr.jump((array_size -1) * sizeof($struct.scopedname$));
std::size_t remaining = array_size - 1;
if (0 < remaining)
{
std::size_t total_bytes = remaining * sizeof($struct.scopedname$);
// Get current position and jump (would throw an exception if not enough buffer)
auto dest = scdr.get_current_position();
scdr.jump(total_bytes);
// It is now safe to do the copy
std::memcpy(dest, array_ptr, total_bytes);
}

Comment on lines +257 to +262
std::memcpy(
reinterpret_cast<char*>(array_ptr),
scdr.get_current_position(),
(array_size - 1) * sizeof($struct.scopedname$));

scdr.jump((array_size - 1) * sizeof($struct.scopedname$));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply similar changes here

@MiguelCompany MiguelCompany modified the milestones: v4.2.0, v4.3.0 Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants