-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an additional `pwpb_rpc` option to pw_proto_library, along with the pw_rpc support for encoding and decoding to pw_protobuf message structs. For simple services, the C++ types used by pw_protobuf result in a cleaner code, for example taking advantage of pw::Vector::operator=() #include "pw_rpc/echo.rpc.pwpb.h" namespace pw::rpc { class EchoService final : public pw_rpc::pwpb::EchoService::Service<EchoService> { public: Status Echo(const EchoMessage::Message& request, EchoMessage::Message& response) { response.msg = request.msg; return OkStatus(); } }; } // namespace pw::rpc Once complex callbacks are involved, the C++ types and pw_protobuf's codegen result in vastly cleaner code compared to other protobuf libraries. For example handling a repeated field without a maximum size through an encoder callback: Status WriteValues(const Request::Message&, Response::Message& response) { response.values.SetEncoder( [&this](Response::StreamEncoder& encoder) { return encoder.WriteValues(values_); }); return OkStatus(); } pw::Vector<uint32_t, 64> values_; Change-Id: I4d6eba4b8202e6deb7e66b80f6a57af9f0207bdf Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/90421 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
- Loading branch information
Showing
55 changed files
with
6,530 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
pw_protobuf_compiler/pw_protobuf_compiler_pwpb_protos/pwpb_test.options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2022 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
pw.protobuf_compiler.Point.name max_size:16 |
22 changes: 22 additions & 0 deletions
22
pw_protobuf_compiler/pw_protobuf_compiler_pwpb_protos/pwpb_test.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2022 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
syntax = "proto3"; | ||
|
||
package pw.protobuf_compiler; | ||
|
||
message Point { | ||
uint32 x = 1; | ||
uint32 y = 2; | ||
string name = 3; | ||
}; |
Oops, something went wrong.