mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
multiprocess: Add type conversion code for UniValue types
Extend IPC unit test to cover this and verify the serialization happens correctly.
This commit is contained in:
parent
0cc74fce72
commit
6acec6b9ff
4 changed files with 28 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <univalue.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <mp/proxy-types.h>
|
#include <mp/proxy-types.h>
|
||||||
|
@ -84,6 +85,24 @@ CustomReadField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context,
|
||||||
value.Unserialize(stream);
|
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
|
} // namespace mp
|
||||||
|
|
||||||
#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H
|
#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H
|
||||||
|
|
|
@ -14,4 +14,5 @@ $Proxy.includeTypes("ipc/capnp/common-types.h");
|
||||||
interface FooInterface $Proxy.wrap("FooImplementation") {
|
interface FooInterface $Proxy.wrap("FooImplementation") {
|
||||||
add @0 (a :Int32, b :Int32) -> (result :Int32);
|
add @0 (a :Int32, b :Int32) -> (result :Int32);
|
||||||
passOutPoint @1 (arg :Data) -> (result :Data);
|
passOutPoint @1 (arg :Data) -> (result :Data);
|
||||||
|
passUniValue @2 (arg :Text) -> (result :Text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,12 @@ void IpcTest()
|
||||||
COutPoint txout2{foo->passOutPoint(txout1)};
|
COutPoint txout2{foo->passOutPoint(txout1)};
|
||||||
BOOST_CHECK(txout1 == txout2);
|
BOOST_CHECK(txout1 == txout2);
|
||||||
|
|
||||||
|
UniValue uni1{UniValue::VOBJ};
|
||||||
|
uni1.pushKV("i", 1);
|
||||||
|
uni1.pushKV("s", "two");
|
||||||
|
UniValue uni2{foo->passUniValue(uni1)};
|
||||||
|
BOOST_CHECK_EQUAL(uni1.write(), uni2.write());
|
||||||
|
|
||||||
// Test cleanup: disconnect pipe and join thread
|
// Test cleanup: disconnect pipe and join thread
|
||||||
disconnect_client();
|
disconnect_client();
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|
|
@ -6,12 +6,14 @@
|
||||||
#define BITCOIN_TEST_IPC_TEST_H
|
#define BITCOIN_TEST_IPC_TEST_H
|
||||||
|
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
#include <univalue.h>
|
||||||
|
|
||||||
class FooImplementation
|
class FooImplementation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int add(int a, int b) { return a + b; }
|
int add(int a, int b) { return a + b; }
|
||||||
COutPoint passOutPoint(COutPoint o) { return o; }
|
COutPoint passOutPoint(COutPoint o) { return o; }
|
||||||
|
UniValue passUniValue(UniValue v) { return v; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void IpcTest();
|
void IpcTest();
|
||||||
|
|
Loading…
Add table
Reference in a new issue