commit | 931f4d54ab96caa81e736ab7341cf82b3c973028 | [log] [tgz] |
---|---|---|
author | Yecheng Zhao <zyecheng@google.com> | Thu Sep 02 23:15:13 2021 -0700 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Mon Sep 13 21:12:25 2021 +0000 |
tree | abd37cf8f592d2e64bd63b06d7a2090f9c124d29 | |
parent | 03e1b265752f327972242e634e2029c416536ad9 [diff] |
pw_protobuf: Add helper for map entry write 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>
See our website: http://pigweed.dev