aboutsummaryrefslogtreecommitdiff
path: root/src/ipc
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2023-11-20 15:49:55 -0500
committerRyan Ofsky <ryan@ofsky.org>2023-11-28 12:35:50 -0500
commit6acec6b9ff02b91de132bb1575d75908a8a2d27b (patch)
tree386e62fb027e0d3ca0d4d2e491e82f8916594825 /src/ipc
parent0cc74fce72e0c79849109ee5d7afe707991b3512 (diff)
downloadbitcoin-6acec6b9ff02b91de132bb1575d75908a8a2d27b.tar.xz
multiprocess: Add type conversion code for UniValue types
Extend IPC unit test to cover this and verify the serialization happens correctly.
Diffstat (limited to 'src/ipc')
-rw-r--r--src/ipc/capnp/common-types.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ipc/capnp/common-types.h b/src/ipc/capnp/common-types.h
index d1343c40dd..39e368491b 100644
--- a/src/ipc/capnp/common-types.h
+++ b/src/ipc/capnp/common-types.h
@@ -7,6 +7,7 @@
#include <clientversion.h>
#include <streams.h>
+#include <univalue.h>
#include <cstddef>
#include <mp/proxy-types.h>
@@ -84,6 +85,24 @@ CustomReadField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context,
value.Unserialize(stream);
});
}
+
+template <typename Value, typename Output>
+void CustomBuildField(TypeList<UniValue>, Priority<1>, InvokeContext& invoke_context, Value&& value, Output&& output)
+{
+ std::string str = value.write();
+ auto result = output.init(str.size());
+ memcpy(result.begin(), str.data(), str.size());
+}
+
+template <typename Input, typename ReadDest>
+decltype(auto) CustomReadField(TypeList<UniValue>, Priority<1>, InvokeContext& invoke_context, Input&& input,
+ ReadDest&& read_dest)
+{
+ return read_dest.update([&](auto& value) {
+ auto data = input.get();
+ value.read(std::string_view{data.begin(), data.size()});
+ });
+}
} // namespace mp
#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H