Skip to content

Commit

Permalink
Remove code duplication, update ros_topic_name_to_zenoh_key function
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivang Vijay committed Mar 10, 2024
1 parent 300b814 commit a136fe2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
18 changes: 0 additions & 18 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,24 +446,6 @@ 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)
{
Expand Down
3 changes: 0 additions & 3 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ 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);

Expand Down
16 changes: 3 additions & 13 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,12 @@ z_owned_keyexpr_t ros_topic_name_to_zenoh_key(const char * topic_name, size_t do
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] == '%') {
// Strip the leading '/'
start_offset = 1;
}
if (topic_name[end_offset - 1] == '%') {
// Strip the trailing '/'
end_offset -= 1;
}
}
std::string topic_nm(topic_name);
topic_nm = liveliness::mangle_name(topic_nm);

return z_keyexpr_join(
z_keyexpr(d.c_str()),
zc_keyexpr_from_slice(&topic_name[start_offset], end_offset - start_offset));
z_keyexpr(topic_nm.c_str()));
}

//==============================================================================
Expand Down

0 comments on commit a136fe2

Please sign in to comment.