Repository navigation
Conversation
`buffa-build` can generate `bytes` fields as `bytes::Bytes` (`bytes_type`, `bytes_type_in`, `use_bytes_type`), which decode from a `Bytes`-backed buffer without a copy. The plugin had no option that sets `CodeGenConfig::bytes_fields`, so a `buf generate` or `protoc` workflow always got `Vec<u8>` and copied every `bytes` payload on decode. The plugin now accepts: - `bytes_type=<repr>`: a rule for every `bytes` field; - `bytes_type_in=<proto_path>=<repr>`: repeatable, path-scoped. `<repr>` is `vec` or `bytes`. Rules accumulate in option order and the last matching rule wins, as in the builder. The grammar follows `codec_strategy_in`. Custom types (`bytes_type_custom`) and `string_type` stay builder-only: a string has no built-in alternative to `String`, so a string option would only be useful with a Rust path. Tests cover each option, path normalization, rule order, rejected values and malformed rules, and one CLI test checks that `bytes_type=bytes` generates a `::buffa::bytes::Bytes` field. The CLI tests share a `run_plugin` helper that spawns the plugin and decodes its response. The guide lists the options.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
recheck |
This was referenced Nov 13, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
buffa-buildcan generatebytesfields asbytes::Bytes(bytes_type,bytes_type_in,use_bytes_type), which decode from aBytes-backed buffer without a copy. The plugin has no option that setsCodeGenConfig::bytes_fields, so abuf generateorprotocworkflow always getsVec<u8>and copies everybytespayload on decode. The guide notes the gap ("there is noprotoc-gen-buffaplugin equivalent yet").Our case: a service whose responses carry Arrow IPC frames of about 100 KB in one
bytesfield. With the plugin, each frame is copied on decode. We generate the Rust code throughconnectrpc-buildwithCodeGenConfig::bytes_fields = [(".", BytesRepr::Bytes)]instead ofbuf generate, only to get this setting.Change
The plugin accepts:
bytes_type=<repr>bytesfield (path.)bytes_type_in=<proto_path>=<repr><repr>isvecorbytes. Rules accumulate in option order and the last matching rule wins, as withbuffa_build::Config::bytes_type/bytes_type_in. Paths go through the existingnormalize_proto_path. The grammar followscodec_strategy_in, and the map options proposed in #767 (#574).Example
buf.gen.yaml:Not included:
bytes_type_custom). They need a dependency the plugin cannot check, and protoc-gen-buffa: expose map container options #767 leavesmap_type_custombuilder-only for the same reason.string_type.StringReprhas no built-in alternative toString, so a string option would only be useful with a custom Rust path.#492 asks whether plugin options should mirror the builder's path-scoped options in general; this is one more concrete case.
Tests
parse_config's test module: no rules by default;bytes_typeadds a.rule;bytes_type_inis repeatable, normalized and kept in option order; unknown representations (Bytes, a Rust path, empty) are rejected; a rule without=<repr>or with an empty path is rejected.CodeGeneratorRequestwith onebytesfield andbytes_type=bytes, and checks that the generated struct haspub payload: ::buffa::bytes::Bytes. The CLI tests get arun_plugin(&CodeGeneratorRequest) -> CodeGeneratorResponsehelper (spawn, write stdin, check the exit status, decode), which the existinginvalid_plugin_option_returns_response_errornow uses too.cargo test -p protoc-gen-buffapasses (85 unit, 6 CLI) on the pinned 1.95.0 toolchain. The steps oftask lintpass (cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings, markdownlint-cli 0.47.0). I have not run the full workspace tests.The guide's plugin option table lists both options, and the note in "String and bytes field representations" now says which options the plugin has. A changelog fragment is included.
Follow-up
codec_strategy_in,bytes_type_inand, once #767 lands,map_type_inparse the same<path>=<value>shape with the same error message. They could share one generic helper, for exampleparse_scoped_rule(key, value, parse) -> Result<(String, T), String>. I have left that out of this PR to avoid conflicts with #767, and can send it separately after both are merged.