pw_multibuf: Restructure ChunkIterable

MultiBuf is a byte-oriented view of a list of chunks, and this change
structures MultiBuf accordingly. This replaces the ChunkIterable class
with a private MultiBufChunks base class that provides the
Chunk-oriented view for MultiBuf.

Restructuring this way fixes an issue where MultiBuf data can be
modified from a const reference. MultiBuf originally returned a const
ChunkIterable, but since return values are copied, this becomes a
non-const ChunkIterable, giving mutable access to the multibuf.

  const MultiBuf& const_mb = mb;
  auto chunk_iterable = cmb.Chunks();  // chunk_iterable is non-const
  iterable.front()[0] = std::byte();  // uh oh, chunk data is mutable!

Change-Id: I9819eb23c9cdf745691ba15b20648b824620cf68
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230892
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Taylor Cramer <cramertj@google.com>
5 files changed
tree: 944bde515c5115c87fa1184e6a75ad6ee9809e67
  1. .allstar/
  2. .github/
  3. .vscode/
  4. build_overrides/
  5. docker/
  6. docs/
  7. kudzu/
  8. pw_alignment/
  9. pw_allocator/
  10. pw_analog/
  11. pw_android_toolchain/
  12. pw_arduino_build/
  13. pw_assert/
  14. pw_assert_basic/
  15. pw_assert_log/
  16. pw_assert_tokenized/
  17. pw_assert_trap/
  18. pw_assert_zephyr/
  19. pw_async/
  20. pw_async2/
  21. pw_async2_basic/
  22. pw_async2_epoll/
  23. pw_async_basic/
  24. pw_base64/
  25. pw_bloat/
  26. pw_blob_store/
  27. pw_bluetooth/
  28. pw_bluetooth_hci/
  29. pw_bluetooth_profiles/
  30. pw_bluetooth_proxy/
  31. pw_bluetooth_sapphire/
  32. pw_boot/
  33. pw_boot_cortex_m/
  34. pw_build/
  35. pw_build_android/
  36. pw_build_info/
  37. pw_build_mcuxpresso/
  38. pw_bytes/
  39. pw_channel/
  40. pw_checksum/
  41. pw_chre/
  42. pw_chrono/
  43. pw_chrono_embos/
  44. pw_chrono_freertos/
  45. pw_chrono_rp2040/
  46. pw_chrono_stl/
  47. pw_chrono_threadx/
  48. pw_chrono_zephyr/
  49. pw_cli/
  50. pw_clock_tree/
  51. pw_clock_tree_mcuxpresso/
  52. pw_compilation_testing/
  53. pw_config_loader/
  54. pw_console/
  55. pw_containers/
  56. pw_cpu_exception/
  57. pw_cpu_exception_cortex_m/
  58. pw_cpu_exception_risc_v/
  59. pw_crypto/
  60. pw_digital_io/
  61. pw_digital_io_linux/
  62. pw_digital_io_mcuxpresso/
  63. pw_digital_io_rp2040/
  64. pw_display/
  65. pw_dma_mcuxpresso/
  66. pw_docgen/
  67. pw_doctor/
  68. pw_emu/
  69. pw_env_setup/
  70. pw_env_setup_zephyr/
  71. pw_file/
  72. pw_format/
  73. pw_function/
  74. pw_fuzzer/
  75. pw_grpc/
  76. pw_hdlc/
  77. pw_hex_dump/
  78. pw_i2c/
  79. pw_i2c_linux/
  80. pw_i2c_mcuxpresso/
  81. pw_i2c_rp2040/
  82. pw_ide/
  83. pw_interrupt/
  84. pw_interrupt_cortex_m/
  85. pw_interrupt_xtensa/
  86. pw_interrupt_zephyr/
  87. pw_intrusive_ptr/
  88. pw_json/
  89. pw_kvs/
  90. pw_libc/
  91. pw_libcxx/
  92. pw_log/
  93. pw_log_android/
  94. pw_log_basic/
  95. pw_log_null/
  96. pw_log_rpc/
  97. pw_log_string/
  98. pw_log_tokenized/
  99. pw_log_zephyr/
  100. pw_malloc/
  101. pw_malloc_freelist/
  102. pw_malloc_freertos/
  103. pw_metric/
  104. pw_minimal_cpp_stdlib/
  105. pw_module/
  106. pw_multibuf/
  107. pw_multisink/
  108. pw_package/
  109. pw_perf_test/
  110. pw_persistent_ram/
  111. pw_polyfill/
  112. pw_preprocessor/
  113. pw_presubmit/
  114. pw_protobuf/
  115. pw_protobuf_compiler/
  116. pw_random/
  117. pw_result/
  118. pw_ring_buffer/
  119. pw_router/
  120. pw_rpc/
  121. pw_rpc_transport/
  122. pw_rust/
  123. pw_sensor/
  124. pw_snapshot/
  125. pw_software_update/
  126. pw_span/
  127. pw_spi/
  128. pw_spi_linux/
  129. pw_spi_mcuxpresso/
  130. pw_spi_rp2040/
  131. pw_status/
  132. pw_stm32cube_build/
  133. pw_stream/
  134. pw_stream_shmem_mcuxpresso/
  135. pw_stream_uart_linux/
  136. pw_stream_uart_mcuxpresso/
  137. pw_string/
  138. pw_symbolizer/
  139. pw_sync/
  140. pw_sync_baremetal/
  141. pw_sync_embos/
  142. pw_sync_freertos/
  143. pw_sync_stl/
  144. pw_sync_threadx/
  145. pw_sync_zephyr/
  146. pw_sys_io/
  147. pw_sys_io_ambiq_sdk/
  148. pw_sys_io_arduino/
  149. pw_sys_io_baremetal_lm3s6965evb/
  150. pw_sys_io_baremetal_stm32f429/
  151. pw_sys_io_emcraft_sf2/
  152. pw_sys_io_mcuxpresso/
  153. pw_sys_io_rp2040/
  154. pw_sys_io_stdio/
  155. pw_sys_io_stm32cube/
  156. pw_sys_io_zephyr/
  157. pw_system/
  158. pw_target_runner/
  159. pw_thread/
  160. pw_thread_embos/
  161. pw_thread_freertos/
  162. pw_thread_stl/
  163. pw_thread_threadx/
  164. pw_thread_zephyr/
  165. pw_tls_client/
  166. pw_tls_client_boringssl/
  167. pw_tls_client_mbedtls/
  168. pw_tokenizer/
  169. pw_toolchain/
  170. pw_toolchain_bazel/
  171. pw_trace/
  172. pw_trace_tokenized/
  173. pw_transfer/
  174. pw_uart/
  175. pw_unit_test/
  176. pw_unit_test_zephyr/
  177. pw_varint/
  178. pw_watch/
  179. pw_web/
  180. pw_work_queue/
  181. seed/
  182. targets/
  183. third_party/
  184. ts/
  185. zephyr/
  186. .bazelignore
  187. .bazelrc
  188. .bazelversion
  189. .black.toml
  190. .clang-format
  191. .clang-tidy
  192. .eslintrc.cjs
  193. .git-blame-ignore-revs
  194. .gitattributes
  195. .gitignore
  196. .gn
  197. .mypy.ini
  198. .prettierignore
  199. .prettierrc.cjs
  200. .pw_ide.yaml
  201. .pylintrc
  202. activate.bat
  203. Android.bp
  204. AUTHORS
  205. bootstrap.bat
  206. bootstrap.fish
  207. bootstrap.sh
  208. BUILD.bazel
  209. BUILD.gn
  210. BUILDCONFIG.gn
  211. CMakeLists.txt
  212. go.mod
  213. go.sum
  214. jest.config.ts
  215. Kconfig.zephyr
  216. LICENSE
  217. MODULE.bazel
  218. modules.gni
  219. OWNERS
  220. package-lock.json
  221. package.json
  222. pigweed.json
  223. PIGWEED_MODULES
  224. README.md
  225. rollup.config.js
  226. tsconfig.json
  227. WORKSPACE
  228. WORKSPACE_OWNERS
README.md

Pigweed

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/.

Links