pw_rpc: Basic client implementation

This implements an RPC client class which is used to make RPC requests
to a server. Like the server, the client exists globally and processes
incoming RPC packets. The client keeps track of active RPC request
contexts through ClientCall objects, and dispatches packets to them when
an expected response is received.

A nanopb implementation of a ClientCall is added as well, supporting
unary and server-streaming RPC calls, with a codegen-ready API.

Change-Id: If9615877199e0d4bc468c33d3d9ecf85da32440a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/15741
Commit-Queue: Alexei Frolov <frolv@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_rpc/BUILD.gn b/pw_rpc/BUILD.gn
index fbf3a74..3ec6c52 100644
--- a/pw_rpc/BUILD.gn
+++ b/pw_rpc/BUILD.gn
@@ -28,30 +28,19 @@
 
 pw_source_set("server") {
   public_configs = [ ":default_config" ]
-  public_deps = [
-    ":protos_pwpb",
-    "$dir_pw_containers:intrusive_list",
-    dir_pw_assert,
-    dir_pw_span,
-    dir_pw_status,
-  ]
+  public_deps = [ ":common" ]
   deps = [ dir_pw_log ]
   public = [
-    "public/pw_rpc/channel.h",
     "public/pw_rpc/server.h",
     "public/pw_rpc/server_context.h",
     "public/pw_rpc/service.h",
   ]
   sources = [
     "base_server_writer.cc",
-    "channel.cc",
-    "packet.cc",
     "public/pw_rpc/internal/base_server_writer.h",
     "public/pw_rpc/internal/call.h",
-    "public/pw_rpc/internal/channel.h",
     "public/pw_rpc/internal/hash.h",
     "public/pw_rpc/internal/method.h",
-    "public/pw_rpc/internal/packet.h",
     "public/pw_rpc/internal/server.h",
     "server.cc",
     "service.cc",
@@ -59,6 +48,43 @@
   friend = [ "./*" ]
 }
 
+pw_source_set("client") {
+  public_configs = [ ":default_config" ]
+  public_deps = [ ":common" ]
+  deps = [ dir_pw_log ]
+  public = [
+    "public/pw_rpc/client.h",
+    "public/pw_rpc/internal/base_client_call.h",
+  ]
+  sources = [
+    "base_client_call.cc",
+    "client.cc",
+  ]
+}
+
+# Classes shared by the server and client.
+pw_source_set("common") {
+  public_configs = [ ":default_config" ]
+  public_deps = [
+    ":protos_pwpb",
+    "$dir_pw_containers:intrusive_list",
+    dir_pw_assert,
+    dir_pw_bytes,
+    dir_pw_span,
+    dir_pw_status,
+  ]
+  deps = [ dir_pw_log ]
+  public = [ "public/pw_rpc/channel.h" ]
+  sources = [
+    "channel.cc",
+    "packet.cc",
+    "public/pw_rpc/internal/channel.h",
+    "public/pw_rpc/internal/method_type.h",
+    "public/pw_rpc/internal/packet.h",
+  ]
+  friend = [ "./*" ]
+}
+
 pw_source_set("test_utils") {
   public = [
     "public/pw_rpc/internal/test_method.h",
@@ -66,6 +92,7 @@
   ]
   public_configs = [ ":private_includes" ]
   public_deps = [
+    ":client",
     ":server",
     dir_pw_span,
   ]
@@ -145,8 +172,10 @@
 
 pw_test_group("tests") {
   tests = [
+    ":base_client_call_test",
     ":base_server_writer_test",
     ":channel_test",
+    ":client_test",
     ":packet_test",
     ":server_test",
     ":service_test",
@@ -156,6 +185,7 @@
 
 pw_proto_library("test_protos") {
   sources = [ "pw_rpc_test_protos/test.proto" ]
+  inputs = [ "pw_rpc_test_protos/test.options" ]
   visibility = [ "./*" ]
 }
 
@@ -198,6 +228,22 @@
   sources = [ "service_test.cc" ]
 }
 
+pw_test("client_test") {
+  deps = [
+    ":client",
+    ":test_utils",
+  ]
+  sources = [ "client_test.cc" ]
+}
+
+pw_test("base_client_call_test") {
+  deps = [
+    ":client",
+    ":test_utils",
+  ]
+  sources = [ "base_client_call_test.cc" ]
+}
+
 pw_test("server_test") {
   deps = [
     ":protos_pwpb",