diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp index 997f76b3..306c60a0 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -446,6 +446,24 @@ std::string mangle_name(const std::string & input) return output; } +///============================================================================= +char * mangle_name(const char * input) +{ + size_t input_length = strlen(input); + char * output = new char[input_length + 1]; + + for (size_t i = 0; i < input_length; ++i) { + if (input[i] == '/') { + output[i] = SLASH_REPLACEMENT; + } else { + output[i] = input[i]; + } + } + output[input_length] = '\0'; + + return output; +} + ///============================================================================= std::string demangle_name(const std::string & input) { diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp index 390ecc68..40d9c80a 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.hpp @@ -122,6 +122,9 @@ class Entity /// Replace "/" instances with "%". std::string mangle_name(const std::string & input); +/// Replace "/" instances with "%". +char * mangle_name(const char * input); + /// Replace "%" instances with "/". std::string demangle_name(const std::string & input); diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index ae62e7be..de6edd11 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -79,7 +79,7 @@ namespace // the old string into it. If this becomes a performance problem, we could consider // modifying the topic_name in place. But this means we need to be much more // careful about who owns the string. -z_owned_keyexpr_t ros_topic_name_to_zenoh_key(const char * const topic_name, size_t domain_id) +z_owned_keyexpr_t ros_topic_name_to_zenoh_key(const char * topic_name, size_t domain_id) { std::string d = std::to_string(domain_id); @@ -87,12 +87,14 @@ z_owned_keyexpr_t ros_topic_name_to_zenoh_key(const char * const topic_name, siz size_t topic_name_len = strlen(topic_name); size_t end_offset = topic_name_len; + topic_name = liveliness::mangle_name(topic_name); + if (topic_name_len > 0) { - if (topic_name[0] == '/') { + if (topic_name[0] == '%') { // Strip the leading '/' start_offset = 1; } - if (topic_name[end_offset - 1] == '/') { + if (topic_name[end_offset - 1] == '%') { // Strip the trailing '/' end_offset -= 1; }