summaryrefslogtreecommitdiff
path: root/src/utils/cpp/hex_string.hpp
blob: 86ea1b9ec816e2521dd1b256e896b6a06c77e68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef INCLUDED_SRC_UTILS_CPP_HEX_STRING_HPP
#define INCLUDED_SRC_UTILS_CPP_HEX_STRING_HPP

#include <iomanip>
#include <sstream>
#include <string>

[[nodiscard]] static inline auto ToHexString(std::string const& bytes)
    -> std::string {
    std::ostringstream ss{};
    ss << std::hex << std::setfill('0');
    for (auto const& b : bytes) {
        ss << std::setw(2)
           << static_cast<int>(static_cast<unsigned char const>(b));
    }
    return ss.str();
}

#endif  // INCLUDED_SRC_UTILS_CPP_HEX_STRING_HPP