From 01f9dc84826e9fd23f462cee8503e5339c8617dc Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 11 Jun 2022 15:46:45 +0800 Subject: [PATCH] msg/msg_type: use fmt::format to print entity_addr for better readability Signed-off-by: Kefu Chai --- src/msg/msg_types.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/msg/msg_types.cc b/src/msg/msg_types.cc index 1a78cb3268098..d4114b06e5975 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -8,6 +8,8 @@ #include #include +#include + #include "common/Formatter.h" bool entity_name_t::parse(std::string_view s) @@ -413,13 +415,9 @@ std::string entity_addr_t::ip_only_to_str() const std::string entity_addr_t::ip_n_port_to_str() const { - std::string addr; - addr += ip_only_to_str(); if (is_ipv6()) { - addr = '[' + addr + ']'; + return fmt::format("[{}]:{}", ip_only_to_str(), get_port()); + } else { + return fmt::format("{}:{}", ip_only_to_str(), get_port()); } - addr += ':'; - addr += std::to_string(get_port()); - return addr; } -