#pragma once #include #include #include "span.h" // epee namespace tools { // Reads a hex string directly into a trivially copyable type T without performing any temporary // allocation. Returns false if the given string is not hex or does not match T in length, // otherwise copies directly into `x` and returns true. template && (std::is_trivially_copyable_v || epee::is_byte_spannable) >> bool hex_to_type(std::string_view hex, T& x) { if (!lokimq::is_hex(hex) || hex.size() != 2*sizeof(T)) return false; lokimq::to_hex(hex.begin(), hex.end(), reinterpret_cast(&x)); return true; } }