* Copyright (c) 2026 Huawei Technologies Co., Ltd.
* openUBMC is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef INTERNAL_HEX_UTIL_H
#define INTERNAL_HEX_UTIL_H
#include <cstdint>
#include <iomanip>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
namespace dev {
inline std::string to_hex(std::string_view bytes)
{
if (bytes.empty()) {
return {};
}
std::ostringstream oss;
oss << std::hex << std::uppercase << std::setfill('0');
for (size_t i = 0; i < bytes.size(); ++i) {
oss << std::setw(2) << static_cast<unsigned>(static_cast<unsigned char>(bytes[i]));
}
return oss.str();
}
inline std::string to_hex(const std::vector<uint8_t>& bytes)
{
if (bytes.empty()) {
return {};
}
return to_hex(std::string_view(reinterpret_cast<const char*>(bytes.data()), bytes.size()));
}
}
#endif