Dynamic Message Deserialization
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 805
- Forks
- 564
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 27
Description
Hi,
I'm relatively new to the rclcpp client after several years of using rclpy and both ROS1 clients. I'm trying to deserialize a message dynamically at runtime. I have the following callback for a generic subscriber:
[this, topic_name, topic_type](const std::shared_ptr<rclcpp::SerializedMessage> &message) {
std::shared_ptr<rcpputils::SharedLibrary> library = rclcpp::get_typesupport_library(topic_type, "rosidl_typesupport_cpp");
const rosidl_message_type_support_t * message_type_support = rclcpp::get_typesupport_handle(topic_type, "rosidl_typesupport_cpp", *library);
auto members = static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(message_type_support->data);
rcutils_allocator_t allocator = rcutils_get_default_allocator();
auto data = allocator.allocate(members->size_of_, allocator.state);
if (nullptr == data) {
RCLCPP_ERROR(this->get_logger(), "Could not allocate message memory %zu", members->size_of_);
return;
}
rclcpp::SerializationBase ser(message_type_support);
ser.deserialize_message(message.get(), data);
...
When I run this, I get a members->size_of_ of 140737332973024, so I assume the casting to message members is incorrect.
I also tried the init_function() in members.
I may be misunderstanding the mechanism for introspection or the serialization API. Any help would be great. Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start by tracing the generic subscriber callback and reading the rclcpp::SerializationBase, rosidl_typesupport_introspection_cpp::MessageMembers, and typesupport lookup APIs used in the report. Done means establishing the supported runtime deserialization path and confirming that message allocation and deserialization work without the invalid size value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, robotics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100