Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve of issue #111 #128

Merged
merged 9 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,24 @@ std::string mangle_name(const std::string & input)
return output;
}

///=============================================================================
char * mangle_name(const char * input)
shivangvijay marked this conversation as resolved.
Show resolved Hide resolved
{
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: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
shivangvijay marked this conversation as resolved.
Show resolved Hide resolved

/// Replace "%" instances with "/".
std::string demangle_name(const std::string & input);

Expand Down
8 changes: 5 additions & 3 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,22 @@ 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)
shivangvijay marked this conversation as resolved.
Show resolved Hide resolved
{
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;

topic_name = liveliness::mangle_name(topic_name);

if (topic_name_len > 0) {
if (topic_name[0] == '/') {
if (topic_name[0] == '%') {
shivangvijay marked this conversation as resolved.
Show resolved Hide resolved
// Strip the leading '/'
start_offset = 1;
}
if (topic_name[end_offset - 1] == '/') {
if (topic_name[end_offset - 1] == '%') {
// Strip the trailing '/'
end_offset -= 1;
}
Expand Down