Adding msgpack support to ::wire:: library (#63)

This commit is contained in:
Lee *!* Clagett
2023-04-05 10:16:50 -04:00
committed by Lee *!* Clagett
parent 64f5d4a9ab
commit 3ad71ba01e
19 changed files with 1876 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020, The Monero Project
// Copyright (c) 2020-2023, The Monero Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
@@ -142,13 +142,18 @@ namespace wire_write
declared after these functions. */
template<typename W, typename T>
inline epee::byte_slice to_bytes(const T& value)
inline epee::byte_slice to_bytes(W&& dest, const T& value)
{
W dest{};
write_bytes(dest, value);
return dest.take_bytes();
}
template<typename W, typename T>
inline epee::byte_slice to_bytes(const T& value)
{
return wire_write::to_bytes(W{}, value);
}
template<typename W, typename T, typename F = wire::identity_>
inline void array(W& dest, const T& source, const std::size_t count, F filter = F{})
{
@@ -162,20 +167,20 @@ namespace wire_write
dest.end_array();
}
template<typename W, typename T>
inline bool field(W& dest, const wire::field_<T, true> elem)
template<typename W, typename T, unsigned I>
inline bool field(W& dest, const wire::field_<T, true, I> elem)
{
dest.key(0, elem.name);
dest.key(I, elem.name);
write_bytes(dest, elem.get_value());
return true;
}
template<typename W, typename T>
inline bool field(W& dest, const wire::field_<T, false> elem)
template<typename W, typename T, unsigned I>
inline bool field(W& dest, const wire::field_<T, false, I> elem)
{
if (bool(elem.get_value()))
{
dest.key(0, elem.name);
dest.key(I, elem.name);
write_bytes(dest, *elem.get_value());
}
return true;