diff options
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r-- | src/protocol.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp index 56071f4748..93e76f1f13 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -195,7 +195,12 @@ const std::vector<std::string> &getAllNetMessageTypes() return allNetMessageTypesVec; } -std::string serviceFlagToStr(size_t bit) +/** + * Convert a service flag (NODE_*) to a human readable string. + * It supports unknown service flags which will be returned as "UNKNOWN[...]". + * @param[in] bit the service flag is calculated as (1 << bit) + */ +static std::string serviceFlagToStr(size_t bit) { const uint64_t service_flag = 1ULL << bit; switch ((ServiceFlags)service_flag) { @@ -219,3 +224,16 @@ std::string serviceFlagToStr(size_t bit) stream << "]"; return stream.str(); } + +std::vector<std::string> serviceFlagsToStr(uint64_t flags) +{ + std::vector<std::string> str_flags; + + for (size_t i = 0; i < sizeof(flags) * 8; ++i) { + if (flags & (1ULL << i)) { + str_flags.emplace_back(serviceFlagToStr(i)); + } + } + + return str_flags; +} |