diff options
Diffstat (limited to 'pw_rpc/nanopb/public/pw_rpc/nanopb/client_server_testing.h')
-rw-r--r-- | pw_rpc/nanopb/public/pw_rpc/nanopb/client_server_testing.h | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/pw_rpc/nanopb/public/pw_rpc/nanopb/client_server_testing.h b/pw_rpc/nanopb/public/pw_rpc/nanopb/client_server_testing.h index 429cb719c..c1dec95b9 100644 --- a/pw_rpc/nanopb/public/pw_rpc/nanopb/client_server_testing.h +++ b/pw_rpc/nanopb/public/pw_rpc/nanopb/client_server_testing.h @@ -15,6 +15,8 @@ #include <cinttypes> +#include "pb_decode.h" +#include "pb_encode.h" #include "pw_rpc/internal/client_server_testing.h" #include "pw_rpc/nanopb/fake_channel_output.h" @@ -45,7 +47,11 @@ class NanopbForwardingChannelOutput final kPayloadsBufferSizeBytes>; public: - constexpr NanopbForwardingChannelOutput() = default; + constexpr NanopbForwardingChannelOutput( + TestPacketProcessor&& server_packet_processor = nullptr, + TestPacketProcessor&& client_packet_processor = nullptr) + : Base(std::move(server_packet_processor), + std::move(client_packet_processor)) {} template <auto kMethod> Response<kMethod> response(uint32_t channel_id, uint32_t index) { @@ -54,6 +60,17 @@ class NanopbForwardingChannelOutput final } template <auto kMethod> + void response(uint32_t channel_id, + uint32_t index, + Response<kMethod>& response) { + PW_ASSERT(Base::PacketCount() >= index); + auto payloads_view = Base::output_.template responses<kMethod>(channel_id); + PW_ASSERT(payloads_view.serde() + .Decode(payloads_view.payloads()[index], response) + .ok()); + } + + template <auto kMethod> Request<kMethod> request(uint32_t channel_id, uint32_t index) { PW_ASSERT(Base::PacketCount() >= index); return Base::output_.template requests<kMethod>(channel_id)[index]; @@ -90,7 +107,11 @@ class NanopbClientServerTestContext final kPayloadsBufferSizeBytes>; public: - NanopbClientServerTestContext() = default; + NanopbClientServerTestContext( + TestPacketProcessor&& server_packet_processor = nullptr, + TestPacketProcessor&& client_packet_processor = nullptr) + : Base(std::move(server_packet_processor), + std::move(client_packet_processor)) {} // Retrieve copy of request indexed by order of occurance template <auto kMethod> @@ -99,12 +120,21 @@ class NanopbClientServerTestContext final index); } - // Retrieve copy of resonse indexed by order of occurance + // Retrieve copy of response indexed by order of occurance template <auto kMethod> Response<kMethod> response(uint32_t index) { return Base::channel_output_.template response<kMethod>( Base::channel().id(), index); } + + // Gives access to the RPC's indexed by order of occurance using passed + // Response object to parse using nanopb. Use this version when you need + // to set callback fields in the Response object before parsing. + template <auto kMethod> + void response(uint32_t index, Response<kMethod>& response) { + return Base::channel_output_.template response<kMethod>( + Base::channel().id(), index, response); + } }; } // namespace pw::rpc |