commit | fb5f2ca113295de9a149082e5401420c56e12fc4 | [log] [tgz] |
---|---|---|
author | Jonathon Reinhart <jrreinhart@google.com> | Wed Aug 30 20:39:28 2023 +0000 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Wed Aug 30 20:39:28 2023 +0000 |
tree | b72792cc94ff50bd0cfadca93c02829159a09097 | |
parent | 3011a52d1c50c87f6ec03ecbb6e23c02b265dc82 [diff] |
pw_protobuf: Expose max_size, max_count in generated header file For fields with max_size or max_count set in the codegen options, generate a constant (static constexpr size_t) named k{FieldName}MaxSize which is set to that size. The constant is defined in the message namespace. Use this constant in the Message struct field definitions and in the calculation of kMaxEncodedSizeBytes. For example, see this diff of the generated file out/protocol_buffer/gen/pw_i2c/protos.proto_library/pwpb/pw_i2c/i2c.pwpb.h: namespace I2cWriteRequest { // ... +static constexpr size_t kRegisterAddressMaxSize = 4; +static constexpr size_t kValueMaxSize = 32; // ... } // ... struct I2cWriteRequest::Message { uint32_t bus_index; uint32_t target_address; - ::pw::Vector<std::byte, 4> register_address; - ::pw::Vector<std::byte, 32> value; + ::pw::Vector<std::byte, kRegisterAddressMaxSize> register_address; + ::pw::Vector<std::byte, kValueMaxSize> value; // ... }; namespace I2cWriteRequest { inline constexpr size_t kMaxEncodedSizeBytes = ::pw::protobuf::SizeOfFieldUint32(static_cast<uint32_t>(Fields::kBusIndex)) + ::pw::protobuf::SizeOfFieldUint32(static_cast<uint32_t>(Fields::kTargetAddress)) + - ::pw::protobuf::SizeOfDelimitedFieldWithoutValue(static_cast<uint32_t>(Fields::kRegisterAddress)) + 4 + - ::pw::protobuf::SizeOfDelimitedFieldWithoutValue(static_cast<uint32_t>(Fields::kValue)) + 32; + ::pw::protobuf::SizeOfDelimitedFieldWithoutValue(static_cast<uint32_t>(Fields::kRegisterAddress)) + kRegisterAddressMaxSize + + ::pw::protobuf::SizeOfDelimitedFieldWithoutValue(static_cast<uint32_t>(Fields::kValue)) + kValueMaxSize; inline constexpr size_t kScratchBufferSizeBytes = 0; } // namespace I2cWriteRequest Test: ninja -C out Bug: 297364973 Change-Id: I165da974e1e17699bd87ddb2311df4efb1808804 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/168973 Reviewed-by: Alexei Frolov <frolv@google.com> Pigweed-Auto-Submit: Jonathon Reinhart <jrreinhart@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.
For more information please see our website: https://pigweed.dev/.