From 152ab94b96fd72d9bf563895adabe96f7f6f3cb6 Mon Sep 17 00:00:00 2001 From: Shivang Vijay Date: Fri, 10 May 2024 09:16:25 +0530 Subject: [PATCH] Solve of issue #111 (#128) * Attempt to solve issue #111 * Remove code duplication, update ros_topic_name_to_zenoh_key function * Update rmw_zenoh_cpp/src/rmw_zenoh.cpp Co-authored-by: Yadu Signed-off-by: Shivang Vijay * Added const in front of topic name and declare topic_nm * Adding proper variable name Co-authored-by: Yadu Signed-off-by: Shivang Vijay * Added appropriate variable name * / separater * Style Signed-off-by: Yadunund --------- Signed-off-by: Shivang Vijay Signed-off-by: Yadunund Co-authored-by: Shivang Vijay Co-authored-by: Yadu Co-authored-by: Yadunund --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index d61e5c58..baf31baa 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -81,26 +81,9 @@ namespace // 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) { - std::string d = std::to_string(domain_id); - - size_t start_offset = 0; - size_t topic_name_len = strlen(topic_name); - size_t end_offset = topic_name_len; - - if (topic_name_len > 0) { - if (topic_name[0] == '/') { - // Strip the leading '/' - start_offset = 1; - } - if (topic_name[end_offset - 1] == '/') { - // Strip the trailing '/' - end_offset -= 1; - } - } - - return z_keyexpr_join( - z_keyexpr(d.c_str()), - zc_keyexpr_from_slice(&topic_name[start_offset], end_offset - start_offset)); + const std::string keyexpr_str = std::to_string(domain_id) + "/" + liveliness::mangle_name( + topic_name); + return z_keyexpr_new(keyexpr_str.c_str()); } //==============================================================================