Skip to content

Commit a2a2ffd

Browse files
avalen2022claude
andcommitted
fix(ros2_parser): strip namespace suffix instead of a fixed 5 chars
`CreateSchema()` used a hard-coded `substr(0, size - 5)` to strip "::msg" from a message's C++ namespace to recover the package name. That works for normal messages (`sensor_msgs::msg`) and happens to work for services (`::srv` is also 5 chars), but it silently mangles action-generated messages whose namespace ends in `::action` (8 chars). For a topic like `<pkg>/action/<Action>_FeedbackMessage` the namespace is `<pkg>::action`. Stripping exactly 5 chars from e.g. `docking::action` (15 chars) leaves `docking::a` — exactly the truncated package name reported in #1060. Downstream lookups then fail with "package not found". Replace the hard-coded strip with a suffix check over the three known generator namespaces (`::msg`, `::srv`, `::action`). Each is stripped by its actual length, so action feedback topics subscribe cleanly and services stay unchanged. Closes #1060. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9cb0b59 commit a2a2ffd

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/ros_parsers/ros2_parser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ std::string CreateSchema(const std::string& base_type)
102102
case ROS_TYPE_MESSAGE: {
103103
auto type_info = reinterpret_cast<const MessageMembers*>(member.members_->data);
104104
std::string package = type_info->message_namespace_;
105-
package = package.substr(0, package.size() - 5); // remove "::msg"
105+
for (const std::string& suffix : { "::msg", "::srv", "::action" })
106+
{
107+
if (package.size() >= suffix.size() &&
108+
package.compare(package.size() - suffix.size(), suffix.size(), suffix) == 0)
109+
{
110+
package.resize(package.size() - suffix.size());
111+
break;
112+
}
113+
}
106114
const std::string field_type = fmt::format("{}/{}", package, type_info->message_name_);
107115
schema += field_type;
108116
if (secondary_types_done.count(field_type) == 0)

0 commit comments

Comments
 (0)