← Back to Pull requests

Support topic instances #178

Merged
fgallegosalido merged 8 files (893 lines) on Apr 07, 2025 19:48 UTC
View on GitHub
fgallegosalido fgallegosalido commented on Mar 18, 2025 11:42 UTC
Author

This PR adds the necessary code to support topic instances in rmw_connextdds (not supported in rmw_connextddsmicro).

  • Part of https://github.com/ros2/ros2/issues/1538:

  • - Depends on https://github.com/ros2/rosidl/pull/796
    - Depends on https://github.com/ros2/rosidl_typesupport_fastrtps/pull/116

    Diff: 893 lines (+749 / -144) across 8 files Reviewer: fercsrti77 Review duration: 29286m
    All Vouch review confidence checks passed
    Residual risk 0.13 = Change Risk (0.53) × (1 − Review Confidence (0.76)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 893 lines diff across 8 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.53 · 5 substantive comment(s)
    0.53
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    76%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Real PR Conversation Timeline
    38 items
    fercsrti77 fercsrti77 approved these changes on Mar 19, 2025 14:06 UTC
    Approved Reviewer

    I already reviewed these code changes offline with @fgallegosalido and @lobolanja

    fgallegosalido fgallegosalido commented on Mar 27, 2025 20:25 UTC
    Author

    @fujitatomoya the pull request is ready to be reviewed.

    lobolanja lobolanja commented on Mar 31, 2025 14:53 UTC
    Contributor

    @fgallegosalido we will need to create a repos file to run CI, right?

    lobolanja lobolanja requested changes on Mar 31, 2025 14:56 UTC
    Changes Requested Reviewer

    @fgallegosalido Can you rebase the required branches from the original task to be able to run the tests and so, if you can't directly rebase those branches create a fork and rebase it in your personal repository, so we are able to run the CI.

    fgallegosalido fgallegosalido commented on Apr 01, 2025 09:27 UTC
    Author

    I've opened two prs that let us run the CI with the new tests:

  • https://github.com/ros2/rcl_interfaces/pull/173

  • https://github.com/ros2/system_tests/pull/568
  • fgallegosalido fgallegosalido commented on Apr 01, 2025 14:54 UTC
    Author
    MiguelCompany MiguelCompany commented on Apr 03, 2025 09:05 UTC
    Contributor

    @fgallegosalido This fails to build on windows. Could you take a look?

    fgallegosalido fgallegosalido commented on Apr 03, 2025 09:43 UTC
    Author

    @MiguelCompany solved

    fgallegosalido fgallegosalido commented on Apr 04, 2025 09:04 UTC
    Author

    @MiguelCompany CI is green. Unless someone else has any objection, this should be ready to be merged. Waiting for @fujitatomoya 's feedback before closing. We should close this one along with https://github.com/ros2/rmw_fastrtps/pull/753, https://github.com/ros2/rcl_interfaces/pull/173 and https://github.com/ros2/system_tests/pull/568

    MiguelCompany MiguelCompany commented on Apr 04, 2025 09:58 UTC
    Contributor

    @fgallegosalido I agree. I guess we will have to wait till the team in America wakes up.

    fujitatomoya fujitatomoya commented on Apr 04, 2025 16:43 UTC
    Contributor

    @fgallegosalido @MiguelCompany 1st thank you very much for putting this together. i think you guys are waiting for the reviews, i can try weekend for rmws, but cannot promise i can complete.....

    CC: @mjcarroll @wjwwood @ahcorde @sloretz @cottsay

    fujitatomoya fujitatomoya commented on Apr 07, 2025 05:00 UTC
    Contributor

    @fgallegosalido i am not sure how much i can help this, but i will review this 1st thing in the morning tomorrow.

    @lobolanja can you approve this?

    fgallegosalido fgallegosalido commented on Apr 07, 2025 07:35 UTC
    Author

    @fujitatomoya this has been already reviewed internally, but we just wanted someone from outside the company to give their OK

    lobolanja lobolanja approved these changes on Apr 07, 2025 07:52 UTC
    Approved Reviewer

    Everything has been reviewed on RTI’s side, so we’re ready to proceed with the merge.

    fgallegosalido fgallegosalido commented on Apr 07, 2025 10:34 UTC
    Author

    @MiguelCompany if everything looks good to you (changes in this repo, but most importantly the testing stuff), approve this pr

    ahcorde ahcorde commented on code on Apr 07, 2025 15:36 UTC
    Code Review
    rmw_connextdds_common/include/rmw_connextdds/type_support.hpp:1
    @@ -56,10 +56,16 @@ struct RMW_Connext_RequestReplyMessage
     
     class RMW_Connext_MessageTypeSupport
     {
    +  const rosidl_message_type_support_t * _message_type_support;
       const rosidl_message_type_support_t * _type_support_fastrtps;
    +  message_type_support_key_callbacks_t _key_callbacks;
       bool _unbounded;
       bool _empty;
    +  bool _keyed;
    +  bool _unbounded_key;
    +  bool _is_cpp;
       uint32_t _serialized_size_max;
    +  uint32_t _key_serialized_size_max;

    include <cstdint>

    ahcorde ahcorde commented on code on Apr 07, 2025 15:37 UTC
    Code Review
    rmw_connextdds_common/src/common/rmw_type_support.cpp:1
    @@ -475,17 +502,105 @@ RMW_Connext_MessageTypeSupport::deserialize(
         return RMW_RET_ERROR;
       }
     
    -  size_out = cdr_stream.get_serialized_data_length();
    +  return RMW_RET_OK;
    +}
    +
    +rmw_ret_t
    +RMW_Connext_MessageTypeSupport::serialize_key(
    +  const void * const ros_msg,
    +  rcutils_uint8_array_t * const to_buffer,
    +  RTIEncapsulationId encapsulation_id,
    +  const bool include_encapsulation)
    +{
    +  if (!this->keyed()) {
    +    return RMW_RET_ERROR;
    +  }
    +
    +  eprosima::fastcdr::FastBuffer cdr_buffer(
    +    reinterpret_cast<char *>(to_buffer->buffer),
    +    to_buffer->buffer_capacity);
    +  eprosima::fastcdr::Cdr cdr_stream(
    +    cdr_buffer,
    +    (RTICdrEncapsulation_isBigEndianCdrEncapsulationId(encapsulation_id)) ?
    +    eprosima::fastcdr::Cdr::BIG_ENDIANNESS :
    +    eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
    +    eprosima::fastcdr::CdrVersion::XCDRv1);
    +  cdr_stream.set_encoding_flag(
    +    eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
    +
    +  try {
    +    if (include_encapsulation) {
    +      cdr_stream.serialize_encapsulation();
    +    }
    +    if (!this->_key_callbacks.cdr_serialize_key(ros_msg, cdr_stream)) {
    +      return RMW_RET_ERROR;
    +    }
    +  } catch(const eprosima::fastcdr::exception::NotEnoughMemoryException & exc) {
    +    // In Release mode, the logging is disabled at compile time, so we mark this
    +    // variable as unused to avoid a warning.
    +    UNUSED_ARG(exc);
    +    // RMW_Connext_TypePlugin_serialize_key is called twice in
    +    // RMW_Connext_TypePlugin_instance_to_key_hash. It can fail the first time
    +    // it is called due to not enough memory, and then allocate the necessary
    +    // memory, so we should not print an error message here.
    +    RMW_CONNEXT_LOG_DEBUG_A(
    +      "Failed to serialize key for %s sample: %s", this->type_name(), exc.what());
    +    return RMW_RET_ERROR;
    +  } catch (const std::exception & exc) {

    include <exception>

    ahcorde ahcorde commented on code on Apr 07, 2025 15:37 UTC
    Code Review
    rmw_connextdds_common/src/common/rmw_type_support.cpp:1
    @@ -475,17 +502,105 @@ RMW_Connext_MessageTypeSupport::deserialize(
         return RMW_RET_ERROR;
       }
     
    -  size_out = cdr_stream.get_serialized_data_length();
    +  return RMW_RET_OK;
    +}
    +
    +rmw_ret_t
    +RMW_Connext_MessageTypeSupport::serialize_key(
    +  const void * const ros_msg,
    +  rcutils_uint8_array_t * const to_buffer,
    +  RTIEncapsulationId encapsulation_id,
    +  const bool include_encapsulation)
    +{
    +  if (!this->keyed()) {
    +    return RMW_RET_ERROR;
    +  }
    +
    +  eprosima::fastcdr::FastBuffer cdr_buffer(
    +    reinterpret_cast<char *>(to_buffer->buffer),
    +    to_buffer->buffer_capacity);
    +  eprosima::fastcdr::Cdr cdr_stream(
    +    cdr_buffer,
    +    (RTICdrEncapsulation_isBigEndianCdrEncapsulationId(encapsulation_id)) ?
    +    eprosima::fastcdr::Cdr::BIG_ENDIANNESS :
    +    eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
    +    eprosima::fastcdr::CdrVersion::XCDRv1);
    +  cdr_stream.set_encoding_flag(
    +    eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
    +
    +  try {
    +    if (include_encapsulation) {
    +      cdr_stream.serialize_encapsulation();
    +    }
    +    if (!this->_key_callbacks.cdr_serialize_key(ros_msg, cdr_stream)) {
    +      return RMW_RET_ERROR;
    +    }
    +  } catch(const eprosima::fastcdr::exception::NotEnoughMemoryException & exc) {
    +    // In Release mode, the logging is disabled at compile time, so we mark this
    +    // variable as unused to avoid a warning.
    +    UNUSED_ARG(exc);
    +    // RMW_Connext_TypePlugin_serialize_key is called twice in
    +    // RMW_Connext_TypePlugin_instance_to_key_hash. It can fail the first time
    +    // it is called due to not enough memory, and then allocate the necessary
    +    // memory, so we should not print an error message here.
    +    RMW_CONNEXT_LOG_DEBUG_A(
    +      "Failed to serialize key for %s sample: %s", this->type_name(), exc.what());
    +    return RMW_RET_ERROR;
    +  } catch (const std::exception & exc) {
    +    RMW_CONNEXT_LOG_ERROR_A_SET(
    +      "Failed to serialize key for %s sample: %s", this->type_name(), exc.what())
    +    return RMW_RET_ERROR;
    +  } catch (...) {
    +    RMW_CONNEXT_LOG_ERROR_A_SET("Failed to serialize key for %s sample", this->type_name())
    +    return RMW_RET_ERROR;
    +  }
    +
    +  to_buffer->buffer_length = cdr_stream.get_serialized_data_length();
     
       RMW_CONNEXT_LOG_DEBUG_A(
    -    "[type support] %s deserialized: "
    -    "consumed=%lu",
    +    "[type support] %s serialized key: "
    +    "buffer.length=%lu",
         this->_type_name.c_str(),
    -    size_out)
    +    to_buffer->buffer_length);
     
       return RMW_RET_OK;
     }
     
    +// rmw_ret_t

    TODO or remove?

    ahcorde ahcorde commented on code on Apr 07, 2025 15:38 UTC
    Code Review
    rmw_connextdds_common/src/ndds/dds_api_ndds.cpp:1
    @@ -882,7 +881,9 @@ rmw_connextdds_count_unread_samples(
       unread_count = 0;
       DDS_ReturnCode_t rc = DDS_RETCODE_ERROR;
       do {
    -    rc = DDS_DataReader_read_or_take_instance_untypedI(
    +    // TODO(fgallegosalido): Use DDS_DataReader_read_or_take_instance_untypedI
    +    // when ROS2 support for instances is added.

        // when ROS 2 support for instances is added.
    

    ahcorde ahcorde commented on code on Apr 07, 2025 15:39 UTC
    Code Review
    rmw_connextdds_common/src/ndds/rmw_type_support_ndds.cpp:1
    @@ -638,11 +720,349 @@ Key Management functions:
     * -------------------------------------------------------------------------------------- */
     static
     PRESTypePluginKeyKind
    -RMW_Connext_TypePlugin_get_key_kind(void)
    +RMW_Connext_TypePlugin_get_key_kind_unkeyed(void)
     {
       return PRES_TYPEPLUGIN_NO_KEY;
     }
     
    +static
    +PRESTypePluginKeyKind
    +RMW_Connext_TypePlugin_get_key_kind_keyed(void)
    +{
    +  return PRES_TYPEPLUGIN_USER_KEY;
    +}
    +
    +static
    +RTIBool
    +RMW_Connext_TypePlugin_serialize_key(
    +  PRESTypePluginEndpointData endpoint_data,
    +  const void *key,
    +  struct RTICdrStream *stream,
    +  RTIBool serialize_encapsulation,
    +  RTIEncapsulationId encapsulation_id,
    +  RTIBool serialize_key,
    +  void *endpoint_plugin_qos)
    +{
    +  UNUSED_ARG(endpoint_data);
    +  UNUSED_ARG(endpoint_plugin_qos);
    +
    +  if (!serialize_key) {
    +    // Not currently supported. As a result, users cannot enable batching by
    +    // setting writer_qos.batch.enabled to TRUE.
    +    return RTI_FALSE;
    +  }
    +
    +  // key contains the serialized data of the sample, so we need to deserialize
    +  // it because the TypePlugin deserialization just copies the serialized
    +  // data to the sample buffer. The actual deserialization in a ROS2 message
    +  // is done in upper layers.
    +  const RMW_Connext_Message * const msg =
    +    reinterpret_cast<const RMW_Connext_Message *>(key);
    +
    +  if (nullptr != msg->user_data) {
    +    // Writer codepath
    +    rcutils_uint8_array_t data_buffer;
    +    data_buffer.allocator = rcutils_get_default_allocator();
    +    data_buffer.buffer =
    +      reinterpret_cast<uint8_t *>(RTICdrStream_getCurrentPosition(stream));
    +    data_buffer.buffer_length = RTICdrStream_getRemainder(stream);
    +    data_buffer.buffer_capacity = data_buffer.buffer_length;
    +
    +    if (!msg->serialized) {
    +      rmw_ret_t rc = msg->type_support->serialize_key(
    +        msg->user_data, &data_buffer, encapsulation_id, serialize_encapsulation);
    +      if (RMW_RET_OK != rc) {
    +        return RTI_FALSE;
    +      }
    +      RMW_CONNEXT_LOG_DEBUG_A(
    +        "serialized key: msg=%p, size=%lu",
    +        msg->user_data, data_buffer.buffer_length)
    +    } else {
    +      const rcutils_uint8_array_t * const user_buffer =
    +        reinterpret_cast<const rcutils_uint8_array_t *>(msg->user_data);
    +      // prevent rcutils_uint8_array_copy from trying to reallocate the target buffer.
    +      if (RCUTILS_RET_OK !=
    +        rcutils_uint8_array_copy(&data_buffer, user_buffer, false /* realloc_if_needed */))
    +      {
    +        return RTI_FALSE;
    +      }
    +    }
    +
    +    RTICdrStream_setCurrentPosition(
    +      stream,
    +      reinterpret_cast<char *>(data_buffer.buffer) + data_buffer.buffer_length);
    +  } else {
    +    // Reader codepath
    +    const auto allocator = rcutils_get_default_allocator();
    +    void * deserialized_message = nullptr;
    +
    +    if (msg->type_support->is_cpp()) {
    +      const auto message_type_support =
    +        static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(
    +        msg->type_support->message_type_support()->data);
    +      deserialized_message = allocator.allocate(
    +        message_type_support->size_of_,
    +        nullptr);
    +      if (nullptr == deserialized_message) {
    +        return RTI_FALSE;
    +      }
    +      message_type_support->init_function(
    +        deserialized_message,
    +        rosidl_runtime_cpp::MessageInitialization::SKIP);
    +    } else {
    +      const auto message_type_support =
    +        static_cast<const rosidl_typesupport_introspection_c__MessageMembers *>(
    +        msg->type_support->message_type_support()->data);
    +      deserialized_message = allocator.allocate(
    +        message_type_support->size_of_,
    +        nullptr);
    +      if (nullptr == deserialized_message) {
    +        return RTI_FALSE;
    +      }
    +      message_type_support->init_function(
    +        deserialized_message,
    +        ROSIDL_RUNTIME_C_MSG_INIT_SKIP);
    +    }
    +    auto retcode = msg->type_support->deserialize(
    +      deserialized_message,
    +      &msg->data_buffer);
    +    if (RMW_RET_OK != retcode) {
    +      allocator.deallocate(deserialized_message, nullptr);
    +      return RTI_FALSE;
    +    }
    +
    +    rcutils_uint8_array_t data_buffer;
    +    data_buffer.allocator = allocator;
    +    data_buffer.buffer =
    +      reinterpret_cast<uint8_t *>(RTICdrStream_getCurrentPosition(stream));
    +    data_buffer.buffer_length = RTICdrStream_getRemainder(stream);
    +    data_buffer.buffer_capacity = data_buffer.buffer_length;
    +
    +    retcode = msg->type_support->serialize_key(
    +      deserialized_message,
    +      &data_buffer,
    +      encapsulation_id,
    +      serialize_encapsulation);
    +    allocator.deallocate(deserialized_message, nullptr);
    +    if (RMW_RET_OK != retcode) {
    +      return RTI_FALSE;
    +    }
    +
    +    RTICdrStream_setCurrentPosition(
    +      stream,
    +      reinterpret_cast<char *>(data_buffer.buffer) + data_buffer.buffer_length);
    +  }
    +
    +  return RTI_TRUE;
    +}
    +
    +static
    +RTIBool
    +RMW_Connext_TypePlugin_deserialize_key(
    +  PRESTypePluginEndpointData endpoint_data,
    +  void ** key,
    +  RTIBool * drop_key,
    +  struct RTICdrStream *stream,
    +  RTIBool deserialize_encapsulation,
    +  RTIBool deserialize_key,
    +  void *endpoint_plugin_qos)
    +{
    +  UNUSED_ARG(endpoint_data);
    +  UNUSED_ARG(drop_key);
    +  UNUSED_ARG(endpoint_plugin_qos);
    +
    +  if (!deserialize_encapsulation) {
    +    // Currently not supported
    +    return RTI_FALSE;
    +  }
    +  if (!deserialize_key) {
    +    // Currently not supported
    +    return RTI_FALSE;
    +  }
    +
    +  RMW_Connext_Message * const msg =
    +    reinterpret_cast<RMW_Connext_Message *>(*key);
    +
    +  const size_t deserialize_size = RTICdrStream_getRemainder(stream);
    +  void * const src_ptr = RTICdrStream_getCurrentPosition(stream);
    +
    +  if (msg->data_buffer.buffer_capacity < deserialize_size) {
    +    if (RCUTILS_RET_OK !=
    +      rcutils_uint8_array_resize(&msg->data_buffer, deserialize_size))
    +    {
    +      return RTI_FALSE;
    +    }
    +  }
    +
    +  memcpy(msg->data_buffer.buffer, src_ptr, deserialize_size);

    include <cstring>

    ahcorde ahcorde approved these changes on Apr 07, 2025 15:40 UTC
    Approved Reviewer

    There are some missing includes, probably there are more, I don't want to delay this merge of this PR, we can include them in a follow up PR

    fgallegosalido fgallegosalido commented on code on Apr 07, 2025 15:58 UTC
    Code Review
    rmw_connextdds_common/src/common/rmw_type_support.cpp:1
    @@ -475,17 +502,105 @@ RMW_Connext_MessageTypeSupport::deserialize(
         return RMW_RET_ERROR;
       }
     
    -  size_out = cdr_stream.get_serialized_data_length();
    +  return RMW_RET_OK;
    +}
    +
    +rmw_ret_t
    +RMW_Connext_MessageTypeSupport::serialize_key(
    +  const void * const ros_msg,
    +  rcutils_uint8_array_t * const to_buffer,
    +  RTIEncapsulationId encapsulation_id,
    +  const bool include_encapsulation)
    +{
    +  if (!this->keyed()) {
    +    return RMW_RET_ERROR;
    +  }
    +
    +  eprosima::fastcdr::FastBuffer cdr_buffer(
    +    reinterpret_cast<char *>(to_buffer->buffer),
    +    to_buffer->buffer_capacity);
    +  eprosima::fastcdr::Cdr cdr_stream(
    +    cdr_buffer,
    +    (RTICdrEncapsulation_isBigEndianCdrEncapsulationId(encapsulation_id)) ?
    +    eprosima::fastcdr::Cdr::BIG_ENDIANNESS :
    +    eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
    +    eprosima::fastcdr::CdrVersion::XCDRv1);
    +  cdr_stream.set_encoding_flag(
    +    eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
    +
    +  try {
    +    if (include_encapsulation) {
    +      cdr_stream.serialize_encapsulation();
    +    }
    +    if (!this->_key_callbacks.cdr_serialize_key(ros_msg, cdr_stream)) {
    +      return RMW_RET_ERROR;
    +    }
    +  } catch(const eprosima::fastcdr::exception::NotEnoughMemoryException & exc) {
    +    // In Release mode, the logging is disabled at compile time, so we mark this
    +    // variable as unused to avoid a warning.
    +    UNUSED_ARG(exc);
    +    // RMW_Connext_TypePlugin_serialize_key is called twice in
    +    // RMW_Connext_TypePlugin_instance_to_key_hash. It can fail the first time
    +    // it is called due to not enough memory, and then allocate the necessary
    +    // memory, so we should not print an error message here.
    +    RMW_CONNEXT_LOG_DEBUG_A(
    +      "Failed to serialize key for %s sample: %s", this->type_name(), exc.what());
    +    return RMW_RET_ERROR;
    +  } catch (const std::exception & exc) {
    +    RMW_CONNEXT_LOG_ERROR_A_SET(
    +      "Failed to serialize key for %s sample: %s", this->type_name(), exc.what())
    +    return RMW_RET_ERROR;
    +  } catch (...) {
    +    RMW_CONNEXT_LOG_ERROR_A_SET("Failed to serialize key for %s sample", this->type_name())
    +    return RMW_RET_ERROR;
    +  }
    +
    +  to_buffer->buffer_length = cdr_stream.get_serialized_data_length();
     
       RMW_CONNEXT_LOG_DEBUG_A(
    -    "[type support] %s deserialized: "
    -    "consumed=%lu",
    +    "[type support] %s serialized key: "
    +    "buffer.length=%lu",
         this->_type_name.c_str(),
    -    size_out)
    +    to_buffer->buffer_length);
     
       return RMW_RET_OK;
     }
     
    +// rmw_ret_t

    I will leave it as a TODO for now.

    fujitatomoya fujitatomoya commented on code on Apr 07, 2025 16:02 UTC
    Code Review
    rmw_connextdds_common/src/ndds/dds_api_ndds.cpp:1
    @@ -796,35 +796,34 @@ rmw_connextdds_take_samples(
       DDS_Long data_len = 0;
       void ** data_buffer = nullptr;
     
    +  // TODO(fgallegosalido): Use DDS_DataReader_read_or_take_instance_untypedI
    +  // when ROS2 support for instances is added.

    precisely ROS2 should be ROS 2, there are other comments already exist with `ROS2, i guess no need to fix :speech_balloon:

    fgallegosalido fgallegosalido commented on Apr 07, 2025 16:15 UTC
    Author

    @ahcorde feedback applied. No functional change has really been added. If there is a need to run again the CI, go ahead, although the schedule is a bit tight to merge today if we need to rerun the CI. @fujitatomoya what do you think?

    I can also undo the last commit and cherry-pick it later to avoid running the CI again.

    fujitatomoya fujitatomoya commented on code on Apr 07, 2025 16:22 UTC
    Code Review
    rmw_connextdds_common/src/ndds/rmw_type_support_ndds.cpp:1
    @@ -268,6 +277,44 @@ RMW_Connext_TypePlugin_destroy_data(void ** sample, void * user_data)
       delete msg;
     }
     
    +static
    +RTIBool
    +RMW_Connext_TypePlugin_create_key(void ** key, void * user_data)
    +{
    +  RMW_Connext_MessageTypeSupport * const type_support =
    +    reinterpret_cast<RMW_Connext_MessageTypeSupport *>(user_data);
    +
    +  const auto buffer_size = (type_support->unbounded_key()) ?
    +    0 : type_support->type_key_serialized_size_max();
    +
    +  RMW_Connext_Message * msg = new (std::nothrow) RMW_Connext_Message();
    +  if (nullptr == msg) {
    +    return RTI_FALSE;
    +  }
    +  if (RMW_RET_OK != RMW_Connext_Message_initialize(msg, type_support, buffer_size)) {
    +    delete msg;
    +    return RTI_FALSE;
    +  }
    +  *key = msg;
    +
    +  return RTI_TRUE;
    +}
    +
    +static
    +void
    +RMW_Connext_TypePlugin_destroy_key(void ** key, void * user_data)

    (not blocking PR, just a suggestion) i would do the following to keep the code cleaner, if that is unused for now.

    RMW_Connext_TypePlugin_destroy_key(void ** key, [[maybe_unused]] void * user_data)
    

    fujitatomoya fujitatomoya commented on code on Apr 07, 2025 16:42 UTC
    Code Review
    rmw_connextdds_common/include/rmw_connextdds/type_support.hpp:1
    @@ -139,14 +174,32 @@ class RMW_Connext_MessageTypeSupport
     
       rmw_ret_t serialize(
         const void * const ros_msg,
    -    rcutils_uint8_array_t * const to_buffer);
    +    rcutils_uint8_array_t * const to_buffer,
    +    const bool include_encapsulation = true);
     
       rmw_ret_t deserialize(
         void * const ros_msg,
         const rcutils_uint8_array_t * const from_buffer,
    -    size_t & size_out,
         const bool header_only = false);
     
    +  rmw_ret_t serialize_key(
    +    const void * const ros_msg,
    +    rcutils_uint8_array_t * const to_buffer,
    +    RTIEncapsulationId encapsulation_id,
    +    const bool include_encapsulation = true);
    +
    +  // Not available in message_type_support_key_callbacks_t yet
    +  //
    +  // Because deserialize_key is not supported yet there will be errors receiving dispose samples
    +  // that have the serialized key as payload and the sample will be reported as lost.
    +  //
    +  // By default, dispose samples do not contain the serialized key, so this should only be a
    +  // problem if the DataWriterQos.protocol.serialize_key_with_dispose is set to true.

    what if the user configure DataWriterQos.protocol.serialize_key_with_dispose as DDS, and comes to this situation? there will be errors when receiving dispose samples, correct? as source code, we can see that is the case it does not support yet, but any user notification can be added? or is this really a corner case, that user barely can configure in that way? just curious that user might or might not be affected with this constraint.

    fujitatomoya fujitatomoya commented on code on Apr 07, 2025 16:51 UTC
    Code Review
    rmw_connextdds_common/src/ndds/rmw_type_support_ndds.cpp:1
    @@ -638,11 +721,349 @@ Key Management functions:
     * -------------------------------------------------------------------------------------- */
     static
     PRESTypePluginKeyKind
    -RMW_Connext_TypePlugin_get_key_kind(void)
    +RMW_Connext_TypePlugin_get_key_kind_unkeyed(void)
     {
       return PRES_TYPEPLUGIN_NO_KEY;
     }
     
    +static
    +PRESTypePluginKeyKind
    +RMW_Connext_TypePlugin_get_key_kind_keyed(void)
    +{
    +  return PRES_TYPEPLUGIN_USER_KEY;
    +}
    +
    +static
    +RTIBool
    +RMW_Connext_TypePlugin_serialize_key(
    +  PRESTypePluginEndpointData endpoint_data,
    +  const void *key,
    +  struct RTICdrStream *stream,
    +  RTIBool serialize_encapsulation,
    +  RTIEncapsulationId encapsulation_id,
    +  RTIBool serialize_key,
    +  void *endpoint_plugin_qos)
    +{
    +  UNUSED_ARG(endpoint_data);
    +  UNUSED_ARG(endpoint_plugin_qos);
    +
    +  if (!serialize_key) {
    +    // Not currently supported. As a result, users cannot enable batching by
    +    // setting writer_qos.batch.enabled to TRUE.
    +    return RTI_FALSE;
    +  }

    user still can configure RTI DDS to enable writer_qos.batch.enabled and ends up having this failure? if this happens, user can know why it is failing with clear error message from RTI connextdds? if not, it would be nice to add the error message that tells user about this limitation explicitly?

    fujitatomoya fujitatomoya commented on Apr 07, 2025 16:56 UTC
    Contributor

    @fgallegosalido i just did the review, minor concerns for user perspective. can you take a look? i am okay to merge this without changes.

    fujitatomoya fujitatomoya commented on Apr 07, 2025 19:21 UTC
    Contributor

    @fgallegosalido @lobolanja is this good to go?

    lobolanja lobolanja commented on Apr 07, 2025 19:32 UTC
    Contributor

    @fgallegosalido @lobolanja is this good to go?

    Yes, good to go! @fujitatomoya

    I’ll take note of your questions and recommendations and discuss them with @fgallegosalido. We’ll address them in future PRs if needed. For now, we’re confident that the changes already in place are quite stable.

    fgallegosalido fgallegosalido commented on code on Apr 07, 2025 19:33 UTC
    Code Review
    rmw_connextdds_common/src/ndds/dds_api_ndds.cpp:1
    @@ -796,35 +796,34 @@ rmw_connextdds_take_samples(
       DDS_Long data_len = 0;
       void ** data_buffer = nullptr;
     
    +  // TODO(fgallegosalido): Use DDS_DataReader_read_or_take_instance_untypedI
    +  // when ROS2 support for instances is added.

    Will address that during the next release cycle

    fgallegosalido fgallegosalido commented on code on Apr 07, 2025 19:33 UTC
    Code Review
    rmw_connextdds_common/src/ndds/rmw_type_support_ndds.cpp:1
    @@ -268,6 +277,44 @@ RMW_Connext_TypePlugin_destroy_data(void ** sample, void * user_data)
       delete msg;
     }
     
    +static
    +RTIBool
    +RMW_Connext_TypePlugin_create_key(void ** key, void * user_data)
    +{
    +  RMW_Connext_MessageTypeSupport * const type_support =
    +    reinterpret_cast<RMW_Connext_MessageTypeSupport *>(user_data);
    +
    +  const auto buffer_size = (type_support->unbounded_key()) ?
    +    0 : type_support->type_key_serialized_size_max();
    +
    +  RMW_Connext_Message * msg = new (std::nothrow) RMW_Connext_Message();
    +  if (nullptr == msg) {
    +    return RTI_FALSE;
    +  }
    +  if (RMW_RET_OK != RMW_Connext_Message_initialize(msg, type_support, buffer_size)) {
    +    delete msg;
    +    return RTI_FALSE;
    +  }
    +  *key = msg;
    +
    +  return RTI_TRUE;
    +}
    +
    +static
    +void
    +RMW_Connext_TypePlugin_destroy_key(void ** key, void * user_data)

    That's a really nice addition! I'll make sure to slowly clean up the code after this is merged

    fgallegosalido fgallegosalido commented on code on Apr 07, 2025 19:35 UTC
    Code Review
    rmw_connextdds_common/include/rmw_connextdds/type_support.hpp:1
    @@ -139,14 +174,32 @@ class RMW_Connext_MessageTypeSupport
     
       rmw_ret_t serialize(
         const void * const ros_msg,
    -    rcutils_uint8_array_t * const to_buffer);
    +    rcutils_uint8_array_t * const to_buffer,
    +    const bool include_encapsulation = true);
     
       rmw_ret_t deserialize(
         void * const ros_msg,
         const rcutils_uint8_array_t * const from_buffer,
    -    size_t & size_out,
         const bool header_only = false);
     
    +  rmw_ret_t serialize_key(
    +    const void * const ros_msg,
    +    rcutils_uint8_array_t * const to_buffer,
    +    RTIEncapsulationId encapsulation_id,
    +    const bool include_encapsulation = true);
    +
    +  // Not available in message_type_support_key_callbacks_t yet
    +  //
    +  // Because deserialize_key is not supported yet there will be errors receiving dispose samples
    +  // that have the serialized key as payload and the sample will be reported as lost.
    +  //
    +  // By default, dispose samples do not contain the serialized key, so this should only be a
    +  // problem if the DataWriterQos.protocol.serialize_key_with_dispose is set to true.

    I don't think many ROS 2 users will use this or find themselves in this codepath. However, we are planning to polish the Keyed Topics implementation later on to cover all these corner cases

    fgallegosalido fgallegosalido commented on code on Apr 07, 2025 19:35 UTC
    Code Review
    rmw_connextdds_common/src/ndds/rmw_type_support_ndds.cpp:1
    @@ -638,11 +721,349 @@ Key Management functions:
     * -------------------------------------------------------------------------------------- */
     static
     PRESTypePluginKeyKind
    -RMW_Connext_TypePlugin_get_key_kind(void)
    +RMW_Connext_TypePlugin_get_key_kind_unkeyed(void)
     {
       return PRES_TYPEPLUGIN_NO_KEY;
     }
     
    +static
    +PRESTypePluginKeyKind
    +RMW_Connext_TypePlugin_get_key_kind_keyed(void)
    +{
    +  return PRES_TYPEPLUGIN_USER_KEY;
    +}
    +
    +static
    +RTIBool
    +RMW_Connext_TypePlugin_serialize_key(
    +  PRESTypePluginEndpointData endpoint_data,
    +  const void *key,
    +  struct RTICdrStream *stream,
    +  RTIBool serialize_encapsulation,
    +  RTIEncapsulationId encapsulation_id,
    +  RTIBool serialize_key,
    +  void *endpoint_plugin_qos)
    +{
    +  UNUSED_ARG(endpoint_data);
    +  UNUSED_ARG(endpoint_plugin_qos);
    +
    +  if (!serialize_key) {
    +    // Not currently supported. As a result, users cannot enable batching by
    +    // setting writer_qos.batch.enabled to TRUE.
    +    return RTI_FALSE;
    +  }

    See my other comment

    Reviewers
    Assignees
    fgallegosalido fgallegosalido
    Labels
    risk: low confidence: 76.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 53.2% (MEDIUM) · Higher = larger blast radius
    53.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 76.2% · Lower = rushed or shallow review
    76.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.7% · Safe to merge
    12.7%