Skip to content

protoc-gen-buffa: expose map_type / map_type_in #574

Open

Description

@DenisCarriere

buffa_build can generate a proto map field as a BTreeMap, with map_type(MapRepr::BTreeMap) or map_type_in(MapRepr::BTreeMap, &[...]). protoc-gen-buffa has no option for it: its parameter parser accepts codec_strategy_in=<path>=<strategy>, unknown_fields_in=<path> and the rest, but no map_type. So crates generated by buf generate with the remote plugin always get the default HashMap.

Why it matters. A map encodes its entries in iteration order. On wasm32-unknown-unknown, the default map's foldhash state is seeded from stack and heap addresses, so the order is fixed for one binary but changes whenever the binary changes. Substreams modules are such binaries. A module that emits a message with a map field therefore emits different bytes for the same entries after any rebuild, for example a toolchain bump. The wire format allows any order, but a BTreeMap keeps the output byte-stable, so builds can be compared by output digest.

Concrete case. streamingfast/substreams-sink-database-changes generates sf.substreams.sink.database.v1 with buf.build/anthropics/buffa:v0.9.2 (lazy_views=true, unknown_fields=false). CompositePrimaryKey.keys is a map<string, string>, so every database-change module that emits composite keys changes its output bytes on each rebuild (streamingfast/substreams-sink-database-changes#14).

Proposal. Mirror the builder in the plugin, using the grammar of codec_strategy_in:

  • map_type=<repr>: the default for every map field;
  • map_type_in=<proto_path>=<repr>: repeatable, last matching rule wins. For example, map_type_in=.sf.substreams.sink.database.v1.CompositePrimaryKey.keys=btree_map.

<repr> would be hash_map or btree_map. map_type_custom names a Rust path and could stay builder-only. #492 asks whether plugin options should mirror the builder's path-scoped options; this is one concrete case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions