5#ifndef BITCOIN_IPC_CAPNP_COMMON_TYPES_H
6#define BITCOIN_IPC_CAPNP_COMMON_TYPES_H
13#include <mp/proxy-types.h>
25 static std::true_type
test(
decltype(std::declval<C>().
Serialize(std::declval<std::nullptr_t&>()))*);
27 static std::false_type
test(...);
39 static std::true_type
test(
decltype(std::declval<C>().
Unserialize(std::declval<std::nullptr_t&>()))*);
41 static std::false_type
test(...);
55template <
typename LocalType,
typename Value,
typename Output>
57 TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Value&& value, Output&& output,
64 std::is_same_v<LocalType, std::remove_cv_t<std::remove_reference_t<LocalType>>>>* enable =
nullptr)
67 value.Serialize(stream);
68 auto result = output.init(stream.
size());
69 memcpy(result.begin(), stream.
data(), stream.
size());
76template <
typename LocalType,
typename Input,
typename ReadDest>
78CustomReadField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest,
81 return read_dest.update([&](
auto& value) {
82 if (!input.has())
return;
83 auto data = input.get();
85 value.Unserialize(stream);
89template <
typename Value,
typename Output>
90void CustomBuildField(TypeList<UniValue>, Priority<1>, InvokeContext& invoke_context, Value&& value, Output&& output)
92 std::string str = value.write();
93 auto result = output.init(str.size());
94 memcpy(result.begin(), str.data(), str.size());
97template <
typename Input,
typename ReadDest>
98decltype(
auto)
CustomReadField(TypeList<UniValue>, Priority<1>, InvokeContext& invoke_context, Input&& input,
101 return read_dest.update([&](
auto& value) {
102 auto data = input.get();
103 value.read(std::string_view{data.begin(), data.size()});
Double ended buffer combining vector and stream-like interfaces.
Minimal stream for reading from an existing byte array by Span.
If none of the specialized versions above matched, default to calling member function.
Functions to serialize / deserialize common bitcoin types.
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output, std::enable_if_t< ipc::capnp::Serializable< LocalType >::value &&std::is_same_v< LocalType, std::remove_cv_t< std::remove_reference_t< LocalType > > > > *enable=nullptr)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest, std::enable_if_t< ipc::capnp::Unserializable< LocalType >::value > *enable=nullptr)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
void Serialize(Stream &, V)=delete
void Unserialize(Stream &, V)=delete
Use SFINAE to define Serializeable<T> trait which is true if type T has a Serialize(stream) method,...
static std::true_type test(decltype(std::declval< C >().Serialize(std::declval< std::nullptr_t & >())) *)
static std::false_type test(...)
static constexpr bool value
Use SFINAE to define Unserializeable<T> trait which is true if type T has an Unserialize(stream) meth...
static std::false_type test(...)
static constexpr bool value
static std::true_type test(decltype(std::declval< C >().Unserialize(std::declval< std::nullptr_t & >())) *)