Skip to content

Commit

Permalink
Remove duplicate zid_to_str function
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund committed Mar 27, 2024
1 parent 7904cee commit 6df064a
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions rmw_zenoh_cpp/src/detail/zenoh_router_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,17 @@
#include <sstream>
#include <string>

namespace
{

// Convert a Zenoh Id to a string
// Zenoh IDs are LSB-first 128bit unsigned and non-zero integers in hexadecimal lowercase.
// @param pid Zenoh Id to convert
std::string zid_to_str(const z_id_t & pid)
{
std::stringstream ss;
int len = 0;
for (size_t i = 0; i < sizeof(pid.id); ++i) {
if (pid.id[i]) {
len = static_cast<int>(i) + 1;
}
}
if (!len) {
ss << "";
} else {
for (int i = len - 1; i >= 0; --i) {
ss << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(pid.id[i]);
}
}
return ss.str();
}

} // namespace
#include "liveliness_utils.hpp"

///=============================================================================
rmw_ret_t zenoh_router_check(z_session_t session)
{
// Initialize context for callback
int context = 0;

// Define callback
auto callback = [](const struct z_id_t * id, void * ctx) {
const std::string id_str = zid_to_str(*id);
const std::string id_str = liveliness::zid_to_str(*id);
RCUTILS_LOG_INFO_NAMED(
"rmw_zenoh_cpp",
"Successfully connected to a Zenoh router with id %s.", id_str.c_str());
Expand Down

0 comments on commit 6df064a

Please sign in to comment.