aboutsummaryrefslogtreecommitdiff
path: root/pw_protobuf
AgeCommit message (Collapse)Author
2022-03-24pw_protobuf: Refactor field parsingScott James Remnant
Refactor the field parsing of individual and packed fixed and varint fields to take the same basic approach, with a consistent internal API. Internal ReadFixedField, ReadVarintField, ReadPackedFixedField, and ReadPackedVarintField methods now consistently output into the passed span of bytes. This provides a better foundation API for future decoding extensions. Change-Id: I8306677a8639acca7525dcaf75d786cf2edd3ed8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/88860 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2022-03-22pw_protobuf: Return DataLoss() when reading unknown enum valueScott James Remnant
Consumers reading a typed enum field should be assured that the value read from the wire protocol matches the possible values of the codegen enum type. Validate the read value and return DataLoss() when an unknown value is found on the wire. Change-Id: I25e015c4ed87e1d5f9f2dc5b1c7f90acb2a33455 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/88761 Reviewed-by: Austin Foxley <afoxley@google.com> Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2022-03-18pw_protobuf: Codegen for packed typesScott James Remnant
This extends the typed StreamDecoder codegen to include named and typed methods for repeated fields using packed encoding. Change-Id: I4d41023aa8e362c24aa32040aa8ec13c6e6ac5fa Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/87380 Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-03-18pw_protobuf: Add codegen for typed StreamDecoder::Field()Scott James Remnant
Since the codegen StreamDecoder knows what type its Fields enum is, add a Field() accessor that converts FieldNumber() into the correct type. Change-Id: I5b889b6a61455984f14a5e4d9b97e1278ad2995e Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/88407 Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-03-17pw_protobuf: Codegen for non-packed typesScott James Remnant
This extends the typed StreamDecoder codegen to include named and typed methods for each non-packed proto field. Change-Id: Ida6f1ffd9790606de4e4a6a446eec6bebba36713 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/86800 Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Alexei Frolov <frolv@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-03-16pw_protobuf: Generate a StreamDecoder class for messagesScott James Remnant
This refactors the existing codegen to be able to generate both encoders and decoders, and starts by creating a simple StreamDecoder with member functions only for obtaining a typed StreamDecoder for child message types. Change-Id: Ib71207a1855a791c55cd4d6b4fe18a1d031fb5e7 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/86402 Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Alexei Frolov <frolv@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-03-16pw_protobuf: Endian-flip doubles and floatsScott James Remnant
The double and float types are serialized in little-endian format, so also need to be endian-flipped if running on a big-endian architecture. Since this flip applies to all fixed types, move to the ReadFixedField() method, and have all code paths use it. Change-Id: I0212c8f5bdc43eaf8c38b9d2404d42639a0365b8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/88380 Reviewed-by: Alexei Frolov <frolv@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-03-14pw_protobuf: StreamDecoder support for packed fieldsScott James Remnant
Implements support for packed fixed and packed varint fields to the StreamDecoder. This now allows StreamDecoder to parse everything that StreamEncoder can encode. Change-Id: I259c64adb18ebcf84b1edb2589cfbb47e37da7c2 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/87180 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2022-03-04pw_protobuf: rename codegen write method classesScott James Remnant
Include the term Write or Encoder in the method classes to free up the namespace for new Read and Decoder classes to sit alongside. Change-Id: I86b1fbb58ca4784121a2700e60338475b26436df Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/86401 Reviewed-by: Alexei Frolov <frolv@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-03-04pw_protobuf: allow StreamDecoder subclasses to moveScott James Remnant
Code generated subclasses will be able to be initialized with an existing StreamDecoder, moving its members to themselves, in the same way that StreamEncoder works. Change-Id: I5874615937895cb7d410432da04c8b2b4ad24209 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/86400 Reviewed-by: Alexei Frolov <frolv@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2022-02-07Reland "pw_protobuf_compiler: Adds Nanopb to Bazel build"Ted Pudlik
This reverts commit 0e718cbd4b6716ad3a7ca979076aac00e08919b0. Reason for revert: After investigation we've determined that this CL is not at fault, and the failures we observed were due to a combination of https://bugs.chromium.org/p/pigweed/issues/detail?id=623 and bugs in a pending CL. Original change's description: > Revert "pw_protobuf_compiler: Adds Nanopb to Bazel build" > > This reverts commit 059e10ae69cfb22ef53731dee2ef374d341beab0. > > Reason for revert: Breaks the bazel build (https://ci.chromium.org/p/pigweed/builders/try/pigweed-linux-bazel-build-host-clang) > > Original change's description: > > pw_protobuf_compiler: Adds Nanopb to Bazel build > > > > This change adds support for Protobuf code generation in the Bazel build > > using the Nanopb plugin. As a side affect this also fixes a number of > > packages, however requires some renaming to prevent clashes. > > > > Fixed: 507 > > Bug: 317 > > Change-Id: Ie4a25a9cc7a7b550b4ef73e67f71308e48bdbc4c > > Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/78020 > > Reviewed-by: Ted Pudlik <tpudlik@google.com> > > Commit-Queue: Ted Pudlik <tpudlik@google.com> > > TBR=frolv@google.com,pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com,tpudlik@google.com,nathaniel.brough@gmail.com > > Change-Id: I92ba10efa39d131a07607b0f17d201bdb9a5c87e > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: 317 > Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/83081 > Pigweed-Auto-Submit: Ted Pudlik <tpudlik@google.com> > Reviewed-by: Keir Mierle <keir@google.com> > Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> # Not skipping CQ checks because this is a reland. Bug: 317 Change-Id: Ie425bfb9c612e602de9f627997c69a17bc360697 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/83082 Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Ted Pudlik <tpudlik@google.com>
2022-02-04Revert "pw_protobuf_compiler: Adds Nanopb to Bazel build"Ted Pudlik
This reverts commit 059e10ae69cfb22ef53731dee2ef374d341beab0. Reason for revert: Breaks the bazel build (https://ci.chromium.org/p/pigweed/builders/try/pigweed-linux-bazel-build-host-clang) Original change's description: > pw_protobuf_compiler: Adds Nanopb to Bazel build > > This change adds support for Protobuf code generation in the Bazel build > using the Nanopb plugin. As a side affect this also fixes a number of > packages, however requires some renaming to prevent clashes. > > Fixed: 507 > Bug: 317 > Change-Id: Ie4a25a9cc7a7b550b4ef73e67f71308e48bdbc4c > Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/78020 > Reviewed-by: Ted Pudlik <tpudlik@google.com> > Commit-Queue: Ted Pudlik <tpudlik@google.com> TBR=frolv@google.com,pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com,tpudlik@google.com,nathaniel.brough@gmail.com Change-Id: I92ba10efa39d131a07607b0f17d201bdb9a5c87e No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: 317 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/83081 Pigweed-Auto-Submit: Ted Pudlik <tpudlik@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2022-02-04bazel: Add missing bazel deps and includesTed Pudlik
Also remove one unused header include from pw_rpc/system_server (instead of adding deps that would provide it). Bug: b/210876793 Change-Id: I1e0afe18e18c05932829d7854e8d64b8fb356c33 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/81680 Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Ted Pudlik <tpudlik@google.com>
2022-02-04pw_protobuf_compiler: Adds Nanopb to Bazel buildNathaniel Brough
This change adds support for Protobuf code generation in the Bazel build using the Nanopb plugin. As a side affect this also fixes a number of packages, however requires some renaming to prevent clashes. Fixed: 507 Bug: 317 Change-Id: Ie4a25a9cc7a7b550b4ef73e67f71308e48bdbc4c Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/78020 Reviewed-by: Ted Pudlik <tpudlik@google.com> Commit-Queue: Ted Pudlik <tpudlik@google.com>
2022-02-02pw_protobuf: Remove the use of PW_CHECK()Yecheng Zhao
Remove PW_CHECK() from pw_protobuf message.h/.cc. Propagate a status code that can be checked instead. Change-Id: Ifc0f7a7d82b47021f41f830ac12ef2ae9c37b835 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/82187 Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2022-01-29pw_protobuf: SizeOfDelimitedFieldWithoutValue functionWyatt Hepler
SizeOfDelimitedFieldWithoutValue() calculates the size of a delimited field tag and length, without counting the bytes required for the data itself. Change-Id: I6f1d679f47d66627e39a8c4a6a9d50c80ce88e69 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/82080 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2022-01-28pw_protobuf: Expand functions for calculating encoded proto sizeWyatt Hepler
- Add SizeOf* functions for each basic protobuf field type. - Add tests for serialized_size.h. Change-Id: Icb6fb674d1904bdbdd73cd66f792e8047734baf2 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/81800 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Wyatt Hepler <hepler@google.com>
2022-01-27cmake: Improve CMake support across multiple modulesEwout van Bekkum
Corrects and extends CMake support for pw_log, pw_thread, pw_tokenizer, pw_snapshot, pw_log_tokenized, pw_protobuf, and pw_varint. Change-Id: I6ae7bcdd6a697a7c70d43cef69bcd167a0e33e1e Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/81627 Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2022-01-19pw_protobuf: Correct MaxScratchBufferSize typeTed Pudlik
It is unusual for a free function in a header to be marked static, because it tells the compiler to generate a separate function in each translation unit that includes it (https://stackoverflow.com/a/22103109). It makes more sense to mark it for inlining. Change-Id: Ie8685bf7ae726b38bf9fc050dfdef8c4fdf3e2a6 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/79260 Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Ted Pudlik <tpudlik@google.com>
2022-01-08pw_build: Add module configuration support for CMakeEwout van Bekkum
Change-Id: I73a8cb3b91fd9793c001cc289074e0d7ef921eb4 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/75643 Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Ewout van Bekkum <ewout@google.com> Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
2022-01-04pw_protobuf: Support providing known length to StreamDecoderScott James Remnant
When a protobuf is encoded on a stream, the wire format may include advance details of the length of the message. Allow this to be specified to StreamDecoder so that it does not read (and consume) bytes beyond the bounds of the message to be decoded. Change-Id: Ifabed2ab4f39dda50c3945f9cc943852aee898d9 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/74722 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-12-24pw_protobuf: Support decoding from non-seekable ReaderScott James Remnant
Allowing a StreamDecoder to operate on a non-seekable Reader means that protobuf messages can be decoded directly from a SocketStream and other similar streams. The previous requirement was to support skipping fields, and advancing to the end of nested length-delimited fields that were not fully read. Since this use is always forwards, it can be replaced in those streams by simply reading and discarding the data. For the requirement of maintaining the bounds of nested length-delimited fields, the decoder can maintain the position itself as it reads. StreamDecoder (and StreamDecoder::BytesReader) can still support seeking where the underlying stream supports it, updating the tracked position within the bounds of the field. Change-Id: Id4d1d41ae0492693bb231732546caba8db871cb3 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/74721 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-12-16Replace ssize_t with ptrdiff_t in Pigweed codeWyatt Hepler
ssize_t is not part of the C or C++ standard and is not provided by all toolchains. Use ptrdiff_t instead for a signed size or index type. Change-Id: I88e96ccb2ef13b0d019da3789646cc474e39a580 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/74920 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-12-15pw_varint: Add function to read from streamScott James Remnant
pw::protobuf::StreamDecoder has a function to read a varint from a stream that's far too useful to hide as a private member. Separate it out as a public member of a varint stream API. Change-Id: If2afe5b8993028e18ec78001380fecf10bd5a673 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/74380 Reviewed-by: Yecheng Zhao <zyecheng@google.com> Reviewed-by: Keir Mierle <keir@google.com> Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Alexei Frolov <frolv@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-12-13pw_software_update: Verify target payloadsYecheng Zhao
Bug: 456 Change-Id: I5cf4586d772f8e52d75cae7718827b1aee7e6ce9 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/62021 Reviewed-by: Ali Zhang <alizhang@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2021-12-12pw_protobuf: fix ReadDelimitedBytes read rangeScott James Remnant
Bug: 580 Change-Id: I99219cb463869f64ac1ecf5ddab86bb7ced6714a Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/73600 Reviewed-by: Yecheng Zhao <zyecheng@google.com> Commit-Queue: Scott James Remnant <keybuk@google.com>
2021-12-06pw_protobuf: Extend message to support BoolScott James Remnant
Change-Id: I30e351a96722214fd46da1f52180b05f8fdc34e4 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/72460 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-12-06pw_protobuf: Extend message to support Float and DoubleScott James Remnant
Change-Id: Ic71fc7ce9babfff98fe01eaf10a0e22744b9a2aa Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/72420 Pigweed-Auto-Submit: Scott James Remnant <keybuk@google.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-11-19pw_protobuf: Add common_protos to match BUILD.gnCarlos Chinchilla
Change-Id: I54b6d3d374d5b526d41fea6da190c5a4bafd9b51 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/70141 Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Carlos Chinchilla <cachinchilla@google.com>
2021-11-15pw_rpc: Prefix Nanopb struct names with "::"Wyatt Hepler
This prevents prevents Nanopb names from incorrectly resolving to names in namespaces. Change-Id: I7e44354df24e872095e8b9029312efd6a6f66555 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/68096 Commit-Queue: Wyatt Hepler <hepler@google.com> Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Alexei Frolov <frolv@google.com>
2021-11-15docs: Assorted documentation fixesTed Pudlik
Three small changes: 1. Adjust certain headings to better comply with the Style Guide. This is done only where the document reused title-level headings, leading to section titles listed in the Module Guides TOC (https://snipboard.io/2OBQjA.jpg). 2. No-Docs-Update-Reason can only be in Gerrit comments now. 3. Specify code highlighting language for a C++ snippet in pw_fuzzer docs (the default is Python). Tested by examining the generated docs. Change-Id: Ic95e49f370e23102ec5bc0b03c34b6da29dcee15 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/68702 Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Pigweed-Auto-Submit: Ted Pudlik <tpudlik@google.com> Reviewed-by: Rob Mohr <mohrr@google.com>
2021-11-12pw_{log, pw_protobuf}: Add module name to log protoCarlos Chinchilla
- Add a module_name, optionally tokenized, field to the LogEntry message. - Updated and fixed affected unit tests. - Updated RpcLogDrain minimum log entry estimate. - Added helper functions to decode byte fields optionally tokenized and saved to uint32_t. Change-Id: Ia09185599127294ff54a426bfda5e04ff57626d7 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/66120 Commit-Queue: Carlos Chinchilla <cachinchilla@google.com> Reviewed-by: Keir Mierle <keir@google.com>
2021-11-03OWNERS: Add throughout treeRob Mohr
These are likely incomplete but not incorrect. Change-Id: Ie6a240fccea8c7f61420ed684b649390d3eb840f Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/67140 Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Reviewed-by: Keir Mierle <keir@google.com>
2021-10-19pw_rpc: Rework C++ client; implement raw clientWyatt Hepler
- Rework the Client class to share code with the Server class. - Replace BaseClientCall with a call object also derived from the internal::Call used for server calls. - Implement a system for testing RPC client invocations. - Implement the raw RPC client API and codegen. - Reimplement the Nanopb RPC client API and codegen to share code. - Implement Nanopb client & bidirectional streaming. - Add an integration test that calls RPCs on a C++ server from a C++ client. Requires: pigweed-internal:16720 Change-Id: Id3a0fd31bb3b3259fb9386dae617e68b9bfe6985 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/65745 Reviewed-by: Ewout van Bekkum <ewout@google.com> Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-10-07pw_protobuf: Add enum for pw::StatusJ. Silva
Fix: b/201822235 Change-Id: Ia7ecd0dc3084a1be85f3271b80b4b2a091168593 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/63380 Commit-Queue: Jennifer Silva <jennifersilva@google.com> Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
2021-10-01pw_software_update: Add coarse Apply progress reportingEwout van Bekkum
Adds coarse Apply progress reporting which updates after every successful target file application. Also adds some missing locks. Also fixes the RepeatedFieldParser to get a copy of the Message to avoid invalidation during iteration. No-Docs-Update-Reason: module under heavy initial development. Change-Id: I7735eb615896fe7a657bc8c10fbf4011b63095ab Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/63168 Commit-Queue: Ewout van Bekkum <ewout@google.com> Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com>
2021-09-24pw_protobuf: return a mutable BytesReaderEwout van Bekkum
Change-Id: I9f935d385babcccb62f679f7cd575ad79bf19434 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/62083 Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Reviewed-by: Yecheng Zhao <zyecheng@google.com> Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
2021-09-22pw_rpc: Do not alias deprecated raw client namesWyatt Hepler
- Don't create aliases for the deprecated ServiceNameClient class for the raw client, since it doesn't exist yet and will never use the old style. - Make it possible to get the ProtoService from a ProtoServiceMethod. - Add a comment that marks the static member RPC functions as deprecated. Change-Id: I5625bb5d1c7f7789ebce9f88adf0aa2c7da61f9c Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/61681 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Alexei Frolov <frolv@google.com> Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-09-21pw_software_update: Parse bundlesYecheng Zhao
Bug: 456 Change-Id: I21e6f8a4e69a037e4c028fc59f9049be1c3b8cdb Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/61341 Reviewed-by: David Rogers <davidrogers@google.com> Reviewed-by: Ewout van Bekkum <ewout@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2021-09-21pw_protobuf: Add TODO for Result<> migrationYecheng Zhao
Currently, Bytes, StringTOXXX and Message all implement Result<> like API such as ok(), status(). This is mainly due to the IntervalReader not being compatible with Result<>. The CL adds a few TODO comments that once pw_bug/363 is resolved, migrate these API to use Result<> instead. Bug: 456 Change-Id: I7856088da50acd1a6f9e9bb4aef9b54cfeb95f83 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/61580 Reviewed-by: Ewout van Bekkum <ewout@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2021-09-18pw_protobuf: Adds a Message class for parsingYecheng Zhao
Implement a `Message` class for processing common field types such as uint32, string, bytes, map<string, >, repeated and nested messages. The class works on top of protobuf::StreamDecoder. The purpose is to wrap low level details of StreamDecoder operations, and have an abstraction layer where proto messages and fields can be represented and handled like objects. This faciliates implementation of higher level functionalities that involves sophisticated processing logic on proto messages, such as update bundle verification. Bug: 456 Change-Id: I75c30e183c9df0e260f251f51363d3dc79d36703 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/60780 Reviewed-by: Armando Montanez <amontanez@google.com> Reviewed-by: Ali Zhang <alizhang@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2021-09-13pw_protobuf: Add helper for map entry writeYecheng Zhao
Expose low level APIs in pw_protobuf for estimating field size and writing length-delimited field key and length prefix. Use them to implement a helper function in pw_software_update for writing proto map<string, bytes> entries. Context: UpdateBundle needs to construct the following Manifest proto message from blob storage: message Manifest { optional SnapshotMetadata snapshot_metadata = 1; map<string, TargetsMetadata> targets_metadata = 2; } For wire format generation, it is essentially equivalent to the following definition with a nested `Entry` message. message Entry { string key = 1; bytes value = 2; } message Manifest { optional bytes snapshot_metadata = 1; repeated Entry targets_metadata = 2; } Although protobuf::StreamEncoder has capability for nested message encoding, it requires a scratch buffer that shall be at least the largest sub-message size. In this case, it will be largest target metadata in the update software bundle, which however, can be fairly large and difficult to estimate. To avoid the issue, the CL takes an approach to construct the message from lower level. Specifically, the CL constructs the delimited field key and length prefix for `Entry` on its own and write to output, then followed by writing a regular string field of `key` and bytes field of `value` via the normal StreamEncoder approach. Change-Id: Ie5f10f483ebceb587660a4a36e5c6674a09ce096 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/59681 Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2021-09-13pw_protobuf: Add StreamDecoderAlexei Frolov
This adds a protobuf decoder that operates on stream readers instead of buffers. It exists as a parallel implementation to the buffer decoder. Change-Id: I1870ac012c54a4712a12d364ac09525210a89bc7 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/58744 Reviewed-by: Armando Montanez <amontanez@google.com> Reviewed-by: David Rogers <davidrogers@google.com> Commit-Queue: Alexei Frolov <frolv@google.com>
2021-09-11pw_protobuf: FieldKey classAlexei Frolov
This replaces the MakeKey function with a FieldKey class, which can be used to both create and parse a protobuf field key. Change-Id: Ib37265fd539feabd923e558a395a6f1a1856d915 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/59641 Commit-Queue: Yecheng Zhao <zyecheng@google.com> Reviewed-by: David Rogers <davidrogers@google.com>
2021-09-04pw_protobuf: Support WriteBytes from ReaderYecheng Zhao
Adds a new variant of WriteBytes method in StreamEncoder that takes payload from a stream::Reader. This can be useful for scenarios where payload comes from non-in-memory sources such as storage. A use case is UpdateBundle in pw_software_update, which needs to construct a proto-format manifest from metadata on storage. Bug: 456 Change-Id: I05eff998f815b7470bd222f5f7828d16095a78c3 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/59481 Reviewed-by: Armando Montanez <amontanez@google.com> Reviewed-by: Ewout van Bekkum <ewout@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Yecheng Zhao <zyecheng@google.com>
2021-09-01bazel: Missing Python rulesAnthony DiGirolamo
- Update com_google_protobuf to 3.17.3, allows proto3 compiling. - Use filegroup for common Python sources in pw_protobuf and rpc - Add pw_cli py_tests No-Docs-Update-Reason: Bazel fixes Change-Id: I7ca506365981e3cf74224ae48dc1a05724c5f4bd Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/57720 Commit-Queue: Anthony DiGirolamo <tonymd@google.com> Reviewed-by: Keir Mierle <keir@google.com>
2021-08-25pw_protobuf/encoder: Deprecate the Finalize() APIEwout van Bekkum
Deprecates the Finalize() encoder API, instead requiring explicit nested encoders to be closed via RAII (i.e. destruction) before the parent encoders are closed. This simplifies the API as it was unclear before when Finalize() should be correctly used. Note that this also adds a precondition to status() that there are no open nested encoders. Change-Id: I2c872b45cb4ecd476e12ba5a1c145bfe3ce91a4d Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/57922 Reviewed-by: Alexei Frolov <frolv@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-08-25pw_protobuf: Squash docs into a single fileEwout van Bekkum
Squashes the 3 separate docs for pw_protobuf into a single docs.rst to improve discoverability. Change-Id: If97c6007d3824b263b1ac6b06a6e2b60dc38c58f Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/58200 Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com> Reviewed-by: Keir Mierle <keir@google.com> Reviewed-by: Alexei Frolov <frolv@google.com>
2021-08-24pw_presubmit: Add cfg+toml to sources build checkAnthony DiGirolamo
Add missing setup.cfg and pyproject.toml files to pw_python_package. No-Docs-Update-Reason: BUILD.gn fix Change-Id: Ice610d8cb061193582e39ec38d584b047c0cee65 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/57866 Commit-Queue: Anthony DiGirolamo <tonymd@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
2021-08-24pw_protobuf: Fixes Python path on LUCI/presubmitNathaniel Brough
This change passes through the PATH environment variable to Bazel allowing pw_env_setup to override the system Python installation. This partially fixes pwbug/437 allowing for Protobuf/RPC rules to be run on the CI and locally. This however introduces a dependency for Pigweed/Bazel on pw_env_setup or system Python-3.6+ for downstream projects. Bug: 437 No-Docs-Update-Reason: Fixes build configuration. Change-Id: I1626b3e9884422786bed84db52a0d519f0dd89a0 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/57660 Reviewed-by: Rob Mohr <mohrr@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Rob Mohr <mohrr@google.com>