Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions include/mp/proxy-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ decltype(auto) CustomReadField(TypeList<std::vector<LocalType>>,
});
}

template <typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::vector<bool>>,
Priority<1>,
InvokeContext& invoke_context,
Input&& input,
ReadDest&& read_dest)
{
return read_dest.update([&](auto& value) {
auto data = input.get();
value.clear();
value.reserve(data.size());
for (auto item : data) {
value.push_back(ReadField(TypeList<bool>(), invoke_context, Make<ValueField>(item), ReadDestTemp<bool>()));
}
});
}

template <typename LocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::set<LocalType>>,
Priority<1>,
Expand Down Expand Up @@ -820,10 +837,8 @@ void CustomBuildField(TypeList<std::vector<LocalType>>,
// FIXME dedup with set handler below
auto list = output.init(value.size());
size_t i = 0;
for (auto& elem : value) {
BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i),
std::move(elem));
++i;
for (auto it = value.begin(); it != value.end(); ++it, ++i) {
BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), *it);
}
}

Expand Down Expand Up @@ -865,6 +880,11 @@ ::capnp::Void BuildPrimitive(InvokeContext& invoke_context, Value&&, TypeList<::
return {};
}

inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector<bool>::reference value, TypeList<bool>)
{
return value;
}

template <typename LocalType, typename Value>
LocalType BuildPrimitive(InvokeContext& invoke_context,
const Value& value,
Expand Down
2 changes: 2 additions & 0 deletions test/mp/test/foo.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ interface ExtendedCallback extends(FooCallback) $Proxy.wrap("mp::test::ExtendedC

struct FooStruct $Proxy.wrap("mp::test::FooStruct") {
name @0 :Text;
setint @1 :List(Int32);
vbool @2 :List(Bool);
}

struct FooCustom $Proxy.wrap("mp::test::FooCustom") {
Expand Down
4 changes: 3 additions & 1 deletion test/mp/test/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <map>
#include <memory>
#include <string>
#include <set>
#include <vector>

namespace mp {
Expand All @@ -16,7 +17,8 @@ namespace test {
struct FooStruct
{
std::string name;
std::vector<int> num_set;
std::set<int> setint;
std::vector<bool> vbool;
};

struct FooCustom
Expand Down
13 changes: 13 additions & 0 deletions test/mp/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@ KJ_TEST("Call FooInterface methods")

FooStruct in;
in.name = "name";
in.setint.insert(2);
in.setint.insert(1);
in.vbool.push_back(false);
in.vbool.push_back(true);
in.vbool.push_back(false);
FooStruct out = foo->pass(in);
KJ_EXPECT(in.name == out.name);
KJ_EXPECT(in.setint.size() == out.setint.size());
for (auto init{in.setint.begin()}, outit{out.setint.begin()}; init != in.setint.end() && outit != out.setint.end(); ++init, ++outit) {
KJ_EXPECT(*init == *outit);
}
KJ_EXPECT(in.vbool.size() == out.vbool.size());
for (size_t i = 0; i < in.vbool.size(); ++i) {
KJ_EXPECT(in.vbool[i] == out.vbool[i]);
}

FooStruct err;
try {
Expand Down