5 #ifndef IROHA_HEXUTILS_HPP 6 #define IROHA_HEXUTILS_HPP 11 #include <boost/algorithm/hex.hpp> 12 #include <boost/optional.hpp> 18 template <
typename Container>
20 -> decltype(c.size()) {
21 return (c.size() + 1) / 2;
24 template <
typename Container>
26 -> decltype(c.size()) {
35 template <
typename OutputContainer>
38 OutputContainer &destination) {
39 static_assert(
sizeof(*input.data()) ==
sizeof(uint8_t),
"type mismatch");
40 const auto beg =
reinterpret_cast<const uint8_t *
>(input.data());
41 const auto end = beg + input.size();
43 boost::algorithm::hex_lower(beg, end, std::back_inserter(destination));
70 if (str.size() % 2 != 0) {
71 return makeError(
"Hex string contains uneven number of characters.");
76 boost::algorithm::unhex(
77 str.begin(), str.end(), std::back_inserter(result));
78 }
catch (
const boost::algorithm::hex_decode_error &e) {
81 return iroha::expected::makeValue(std::move(result));
85 std::string_view str) {
86 return iroha::expected::resultToOptionalValue(
96 typename = std::enable_if_t<std::is_arithmetic<T>::value>>
99 ss << std::hex << std::setfill(
'0') << std::setw(
sizeof(T) * 2) << val;
105 #endif // IROHA_HEXUTILS_HPP std::string numToHexstring(const T val)
Definition: hexutils.hpp:97
std::string bytestringToHexstring(std::string_view str)
Definition: hexutils.hpp:51
Definition: result_fwd.hpp:27
void bytestringToHexstringAppend(shared_model::interface::types::ByteRange input, OutputContainer &destination)
Definition: hexutils.hpp:36
boost::optional< std::string > hexstringToBytestring(std::string_view str)
Definition: hexutils.hpp:84
Definition: block_query.hpp:15
ByteRange makeByteRange(const Source &str)
Definition: byte_range.hpp:19
auto bytestringToHexstringSize(Container const &c) -> decltype(c.size())
Definition: hexutils.hpp:25
auto hexstringToBytestringSize(Container const &c) -> decltype(c.size())
Definition: hexutils.hpp:19
Definition: result_fwd.hpp:10
iroha::expected::Result< std::string, const char * > hexstringToBytestringResult(std::string_view str)
Definition: hexutils.hpp:65
expected::Result< T, DbError > makeError(uint32_t code, char const *format, Args &&... args)
Definition: rocksdb_common.hpp:471
std::basic_string_view< std::byte > ByteRange
Definition: byte_range.hpp:16