5#ifndef BITCOIN_IPC_CAPNP_COMMON_TYPES_H
6#define BITCOIN_IPC_CAPNP_COMMON_TYPES_H
16#include <mp/proxy-types.h>
39concept Deserializable = std::is_constructible_v<T, ::deserialize_type, ::DataStream&>;
49template <
typename LocalType,
typename Value,
typename Output>
50void CustomBuildField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Value&& value, Output&& output)
60 value.Serialize(wrapper);
61 auto result = output.init(stream.
size());
62 memcpy(result.begin(), stream.
data(), stream.
size());
69template <
typename LocalType,
typename Input,
typename ReadDest>
70decltype(
auto)
CustomReadField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest)
73 return read_dest.update([&](
auto& value) {
74 if (!input.has())
return;
75 auto data = input.get();
78 value.Unserialize(wrapper);
86template <
typename LocalType,
typename Input,
typename ReadDest>
87decltype(
auto)
CustomReadField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest)
91 auto data = input.get();
99template <
class Rep,
class Period,
typename Value,
typename Output>
100void CustomBuildField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1>, InvokeContext& invoke_context, Value&& value,
103 static_assert(std::numeric_limits<
decltype(output.get())>::lowest() <= std::numeric_limits<Rep>::lowest(),
104 "capnp type does not have enough range to hold lowest std::chrono::duration value");
105 static_assert(std::numeric_limits<
decltype(output.get())>::max() >= std::numeric_limits<Rep>::max(),
106 "capnp type does not have enough range to hold highest std::chrono::duration value");
107 output.set(value.count());
110template <
class Rep,
class Period,
typename Input,
typename ReadDest>
111decltype(
auto)
CustomReadField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1>, InvokeContext& invoke_context,
112 Input&& input, ReadDest&& read_dest)
114 return read_dest.construct(input.get());
119template <
typename Value,
typename Output>
120void CustomBuildField(TypeList<UniValue>, Priority<1>, InvokeContext& invoke_context, Value&& value, Output&& output)
122 std::string str = value.write();
123 auto result = output.init(str.size());
124 memcpy(result.begin(), str.data(), str.size());
127template <
typename Input,
typename ReadDest>
128decltype(
auto)
CustomReadField(TypeList<UniValue>, Priority<1>, InvokeContext& invoke_context, Input&& input,
129 ReadDest&& read_dest)
131 return read_dest.update([&](
auto& value) {
132 auto data = input.get();
133 value.read(std::string_view{
data.begin(),
data.size()});
150template <
typename LocalType,
typename Value,
typename Output>
151void CustomBuildField(TypeList<LocalType>, Priority<2>, InvokeContext& invoke_context, Value&& value, Output&& output)
153 (std::is_same_v<
decltype(output.get()), ::capnp::Data::Builder>) &&
154 (std::convertible_to<Value, std::span<const std::byte>> ||
155 std::convertible_to<Value, std::span<const char>> ||
156 std::convertible_to<Value, std::span<const unsigned char>> ||
157 std::convertible_to<Value, std::span<const signed char>>)
159 auto data = std::span{value};
160 auto result = output.init(
data.size());
161 memcpy(result.begin(),
data.data(),
data.size());
Double ended buffer combining vector and stream-like interfaces.
Wrapper that overrides the GetParams() function of a stream.
Minimal stream for reading from an existing byte array by Span.
If none of the specialized versions above matched, default to calling member function.
Detect if type has a deserialize_type constructor, which is used to deserialize types like CTransacti...
auto Wrap(S &s)
Construct a ParamStream wrapping a data stream with serialization parameters needed to pass transacti...
Functions to serialize / deserialize common bitcoin types.
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
#define S(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
static constexpr TransactionSerParams TX_WITH_WITNESS
constexpr deserialize_type deserialize