6 #ifndef KAGOME_HEXUTIL_HPP 7 #define KAGOME_HEXUTIL_HPP 31 std::string
int_to_hex(uint64_t n,
size_t fixed_width = 2) noexcept;
39 std::string
hex_upper(gsl::span<const uint8_t> bytes) noexcept;
47 std::string
hex_lower(gsl::span<const uint8_t> bytes) noexcept;
54 std::string
hex_lower_0x(gsl::span<const uint8_t> bytes) noexcept;
59 inline std::string
hex_lower_0x(
const uint8_t *data,
size_t size) noexcept {
60 return hex_lower_0x(gsl::span<const uint8_t>(data, size));
75 outcome::result<std::vector<uint8_t>>
unhex(std::string_view hex);
82 outcome::result<std::vector<uint8_t>>
unhexWith0x(std::string_view hex);
90 template <
class T,
typename = std::enable_if<std::is_
unsigned_v<T>>>
92 std::vector<uint8_t> bytes;
94 bytes = std::move(bts);
96 if (bytes.size() >
sizeof(T)) {
101 for (
auto b : bytes) {
103 if constexpr (
sizeof(T) > 1) {
118 #endif // KAGOME_HEXUTIL_HPP
std::string hex_lower(const gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation.
outcome::result< std::vector< uint8_t > > unhexWith0x(std::string_view hex_with_prefix)
Unhex hex-string with 0x in the begining.
std::string hex_upper(const gsl::span< const uint8_t > bytes) noexcept
Converts bytes to uppercase hex representation.
OUTCOME_HPP_DECLARE_ERROR(kagome::common, UnhexError)
std::string int_to_hex(uint64_t n, size_t fixed_width) noexcept
Converts an integer to an uppercase hex representation.
outcome::result< T > unhexNumber(std::string_view value)
unhex hex-string with 0x or without it in the beginning
std::string hex_lower_0x(gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation with prefix 0x.
UnhexError
error codes for exceptions that may occur during unhexing
outcome::result< std::vector< uint8_t > > unhex(std::string_view hex)
Converts hex representation to bytes.