diff --git a/dynmsg/src/message_reading_c.cpp b/dynmsg/src/message_reading_c.cpp index a6bd289..1a3ae54 100644 --- a/dynmsg/src/message_reading_c.cpp +++ b/dynmsg/src/message_reading_c.cpp @@ -491,20 +491,12 @@ dynamic_array_to_yaml( array_node); break; case rosidl_typesupport_introspection_c__ROS_TYPE_MESSAGE: - // We do not know the specific type of the sequence because the type is not available at - // compile-time, but they all follow the same structure pattern, where a pointer to the data - // is first, followed by the element count, followed by the capacity RosMessage nested_member; nested_member.type_info = reinterpret_cast(member_info.members_->data); - uint8_t * element_data; - memcpy(&element_data, member_data, sizeof(void *)); - size_t element_size; - element_size = nested_member.type_info->size_of_; - size_t element_count; - element_count = static_cast(member_data[sizeof(void *)]); - for (size_t ii = 0; ii < element_count; ++ii) { - nested_member.data = element_data + ii * element_size; + for (size_t i = 0; i < member_info.size_function(member_data); i++) { // Recursively read the nested type into the array element in the YAML representation + nested_member.data = reinterpret_cast( + member_info.get_function(const_cast(member_data), i)); array_node.push_back(dynmsg::c::message_to_yaml(nested_member)); } break; diff --git a/dynmsg/src/message_reading_cpp.cpp b/dynmsg/src/message_reading_cpp.cpp index d824de7..ada9b3a 100644 --- a/dynmsg/src/message_reading_cpp.cpp +++ b/dynmsg/src/message_reading_cpp.cpp @@ -517,11 +517,10 @@ dynamic_array_to_yaml( case rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: RosMessage_Cpp nested_member; nested_member.type_info = reinterpret_cast(member_info.members_->data); - void * data; - data = reinterpret_cast(const_cast(member_data)); - for (size_t i = 0; i < member_info.size_function(data); i++) { + for (size_t i = 0; i < member_info.size_function(member_data); i++) { // Recursively read the nested type into the array element in the YAML representation - nested_member.data = reinterpret_cast(member_info.get_function(data, i)); + nested_member.data = reinterpret_cast( + member_info.get_function(const_cast(member_data), i)); array_node.push_back(message_to_yaml(nested_member)); } break;