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>
9 files changed
tree: abd37cf8f592d2e64bd63b06d7a2090f9c124d29
  1. build_overrides/
  2. docker/
  3. docs/
  4. pw_allocator/
  5. pw_analog/
  6. pw_android_toolchain/
  7. pw_arduino_build/
  8. pw_assert/
  9. pw_assert_basic/
  10. pw_assert_log/
  11. pw_base64/
  12. pw_bloat/
  13. pw_blob_store/
  14. pw_bluetooth_hci/
  15. pw_boot/
  16. pw_boot_cortex_m/
  17. pw_build/
  18. pw_build_info/
  19. pw_bytes/
  20. pw_checksum/
  21. pw_chrono/
  22. pw_chrono_embos/
  23. pw_chrono_freertos/
  24. pw_chrono_stl/
  25. pw_chrono_threadx/
  26. pw_cli/
  27. pw_console/
  28. pw_containers/
  29. pw_cpu_exception/
  30. pw_cpu_exception_cortex_m/
  31. pw_crypto/
  32. pw_docgen/
  33. pw_doctor/
  34. pw_env_setup/
  35. pw_file/
  36. pw_function/
  37. pw_fuzzer/
  38. pw_hdlc/
  39. pw_hex_dump/
  40. pw_i2c/
  41. pw_interrupt/
  42. pw_interrupt_cortex_m/
  43. pw_kvs/
  44. pw_libc/
  45. pw_log/
  46. pw_log_basic/
  47. pw_log_null/
  48. pw_log_rpc/
  49. pw_log_tokenized/
  50. pw_malloc/
  51. pw_malloc_freelist/
  52. pw_metric/
  53. pw_minimal_cpp_stdlib/
  54. pw_module/
  55. pw_multisink/
  56. pw_package/
  57. pw_persistent_ram/
  58. pw_polyfill/
  59. pw_preprocessor/
  60. pw_presubmit/
  61. pw_protobuf/
  62. pw_protobuf_compiler/
  63. pw_random/
  64. pw_result/
  65. pw_ring_buffer/
  66. pw_router/
  67. pw_rpc/
  68. pw_snapshot/
  69. pw_software_update/
  70. pw_span/
  71. pw_status/
  72. pw_stm32cube_build/
  73. pw_stream/
  74. pw_string/
  75. pw_symbolizer/
  76. pw_sync/
  77. pw_sync_baremetal/
  78. pw_sync_embos/
  79. pw_sync_freertos/
  80. pw_sync_stl/
  81. pw_sync_threadx/
  82. pw_sys_io/
  83. pw_sys_io_arduino/
  84. pw_sys_io_baremetal_lm3s6965evb/
  85. pw_sys_io_baremetal_stm32f429/
  86. pw_sys_io_stdio/
  87. pw_target_runner/
  88. pw_thread/
  89. pw_thread_embos/
  90. pw_thread_freertos/
  91. pw_thread_stl/
  92. pw_thread_threadx/
  93. pw_tls_client/
  94. pw_tls_client_boringssl/
  95. pw_tls_client_mbedtls/
  96. pw_tokenizer/
  97. pw_tool/
  98. pw_toolchain/
  99. pw_trace/
  100. pw_trace_tokenized/
  101. pw_transfer/
  102. pw_unit_test/
  103. pw_varint/
  104. pw_watch/
  105. pw_web_ui/
  106. pw_work_queue/
  107. targets/
  108. third_party/
  109. .bazelignore
  110. .bazelrc
  111. .clang-format
  112. .clang-tidy
  113. .eslintrc.json
  114. .gitattributes
  115. .gitignore
  116. .gn
  117. .prettierrc.js
  118. .pylintrc
  119. activate.bat
  120. AUTHORS
  121. bootstrap.bat
  122. bootstrap.sh
  123. BUILD.bazel
  124. BUILD.gn
  125. BUILDCONFIG.gn
  126. CMakeLists.txt
  127. LICENSE
  128. modules.gni
  129. OWNERS
  130. package.json
  131. PW_PLUGINS
  132. README.md
  133. tsconfig.json
  134. WORKSPACE
  135. yarn.lock
README.md

See our website: http://pigweed.dev