aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/hex.h
diff options
context:
space:
mode:
authorLee Clagett <code@leeclagett.com>2019-11-07 05:45:06 +0000
committerLee Clagett <code@leeclagett.com>2020-03-05 14:20:56 +0000
commit0f78b06e8c578819f831a513490278a5f70b01af (patch)
tree2f940ff50b1676b92887a4a755b7eb1ba462c04c /contrib/epee/include/hex.h
parentMerge pull request #6057 (diff)
downloadmonero-0f78b06e8c578819f831a513490278a5f70b01af.tar.xz
Various improvements to the ZMQ JSON-RPC handling:
- Finding handling function in ZMQ JSON-RPC now uses binary search - Temporary `std::vector`s in JSON output now use `epee::span` to prevent allocations. - Binary -> hex in JSON output no longer allocates temporary buffer - C++ structs -> JSON skips intermediate DOM creation, and instead write directly to an output stream.
Diffstat (limited to 'contrib/epee/include/hex.h')
-rw-r--r--contrib/epee/include/hex.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/contrib/epee/include/hex.h b/contrib/epee/include/hex.h
index 6e720f128..4e8f90786 100644
--- a/contrib/epee/include/hex.h
+++ b/contrib/epee/include/hex.h
@@ -51,12 +51,22 @@ namespace epee
template<std::size_t N>
static std::array<char, N * 2> array(const std::array<std::uint8_t, N>& src) noexcept
{
- std::array<char, N * 2> out{{}};
+ std::array<char, N * 2> out;
static_assert(N <= 128, "keep the stack size down");
buffer_unchecked(out.data(), {src.data(), src.size()});
return out;
}
+ //! \return An array containing hex of `src`.
+ template<typename T>
+ static std::array<char, sizeof(T) * 2> array(const T& src) noexcept
+ {
+ std::array<char, sizeof(T) * 2> out;
+ static_assert(sizeof(T) <= 128, "keep the stack size down");
+ buffer_unchecked(out.data(), as_byte_span(src));
+ return out;
+ }
+
//! Append `src` as hex to `out`.
static void buffer(std::ostream& out, const span<const std::uint8_t> src);