diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index d3d5dfc5..f41ae58e 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -362,6 +362,23 @@ decltype(auto) CustomReadField(TypeList>, }); } +template +decltype(auto) CustomReadField(TypeList>, + 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(), invoke_context, Make(item), ReadDestTemp())); + } + }); +} + template decltype(auto) CustomReadField(TypeList>, Priority<1>, @@ -820,10 +837,8 @@ void CustomBuildField(TypeList>, // FIXME dedup with set handler below auto list = output.init(value.size()); size_t i = 0; - for (auto& elem : value) { - BuildField(TypeList(), invoke_context, ListOutput(list, i), - std::move(elem)); - ++i; + for (auto it = value.begin(); it != value.end(); ++it, ++i) { + BuildField(TypeList(), invoke_context, ListOutput(list, i), *it); } } @@ -865,6 +880,11 @@ ::capnp::Void BuildPrimitive(InvokeContext& invoke_context, Value&&, TypeList<:: return {}; } +inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector::reference value, TypeList) +{ + return value; +} + template LocalType BuildPrimitive(InvokeContext& invoke_context, const Value& value, diff --git a/test/mp/test/foo.capnp b/test/mp/test/foo.capnp index 409c4531..01987a45 100644 --- a/test/mp/test/foo.capnp +++ b/test/mp/test/foo.capnp @@ -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") { diff --git a/test/mp/test/foo.h b/test/mp/test/foo.h index b9f881d1..bc6a22e5 100644 --- a/test/mp/test/foo.h +++ b/test/mp/test/foo.h @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace mp { @@ -16,7 +17,8 @@ namespace test { struct FooStruct { std::string name; - std::vector num_set; + std::set setint; + std::vector vbool; }; struct FooCustom diff --git a/test/mp/test/test.cpp b/test/mp/test/test.cpp index e7c1c711..457d2c65 100644 --- a/test/mp/test/test.cpp +++ b/test/mp/test/test.cpp @@ -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 {