Skip to main content

Crate buffa_codegen

Crate buffa_codegen 

Source
Expand description

Shared code generation logic for buffa.

This crate takes protobuf descriptors (google.protobuf.FileDescriptorProto, decoded from binary FileDescriptorSet data) and emits Rust source code that uses the buffa runtime.

It is used by:

  • protoc-gen-reallyme-buffa (protoc plugin)
  • buffa-build (build.rs integration)

§Architecture

The code generator is intentionally decoupled from how descriptors are obtained. It receives fully-resolved FileDescriptorProtos and produces Rust source strings. This means:

  • It doesn’t parse .proto files.
  • It doesn’t invoke protoc.
  • It doesn’t do import resolution or name linking.

All of that is handled upstream (by protoc, buf, or a future parser).

Modules§

context
Code generation context and descriptor-to-Rust mapping state.
idents
Rust identifier and path construction helpers.

Structs§

AliasConflict
One CamelCase collision: a target identifier and the proto value names that would all convert onto it.
CodeGenConfig
Configuration for code generation.
FeatureGateNames
Crate feature names used by the gated impls, customizable per impl kind.
GeneratedFile
One generated output file.
SharedCorpusContext
The corpus-wide state CodeGenContext derives on every generate() call — which oneof variants are unboxed, which message fields are stored inline, and the raw comment text per fully-qualified name — none of which depends on the extern paths that legitimately vary per call in a one-crate-per-package workspace. Build one with SharedCorpusContext::new from the whole corpus and set CodeGenConfig::shared_corpus_context on every per-package config to skip that work on each call.
TableCodecFallbackReason
Why some messages selected for CodecStrategy::Table fell back to CodecStrategy::Unrolled, for CodeGenWarning::TableCodecFallbackSummary.

Enums§

BytesRepr
The Rust type a proto bytes field maps to in generated owned structs.
CodeGenError
Code generation error.
CodeGenWarning
A non-fatal diagnostic produced during code generation.
CodecStrategy
How a message’s binary Message implementation is generated. Select it with CodeGenConfig::codec_strategy and CodeGenConfig::codec_strategy_in.
EnumTypeOverride
Supported values for FeatureOverride::EnumType.
FdsEmbedding
How shared_descriptor_root_module embeds the descriptor set into the generated tree. Both forms decode to byte-identical runtime data; they differ only in generated-source size and whether a sidecar file is written.
FeatureOverride
A path-scoped protobuf editions feature override, applied by mutating the parsed descriptors before generation (see feature_overrides).
GeneratedFileKind
Kind of GeneratedFile.
IncludeMode
How generate_module_tree emits include! paths.
MapRepr
The owned Rust collection a proto map<K, V> field maps to in generated owned structs.
PointerRepr
The owned smart pointer a singular message field’s buffa::MessageField wraps in generated owned structs.
ReflectMode
How much reflection support generated types get.
RepeatedRepr
The owned Rust collection a proto repeated field maps to in generated owned structs.
StringRepr
The Rust type a proto string field maps to in generated owned structs.
ZeroizeConfigurationErrorReason
Why a selected message cannot use recursive cleanup.

Constants§

ALLOW_LINTS
Lints suppressed on generated code at module boundaries.
ELEMENT_MEMORY_LIMIT_ENV
Environment variable overriding the element-memory bound buffa’s tooling applies when decoding a descriptor set.
ELEMENT_MEMORY_LIMIT_OPT
Plugin option, settable in the protoc/buf parameter string, that sets the element-memory bound used to decode the request carrying it.
TOOLING_ELEMENT_MEMORY_LIMIT
Element-memory bound buffa’s build tooling applies to a descriptor set — the protoc plugins to a CodeGeneratorRequest, buffa-build to a FileDescriptorSet.

Functions§

allow_lints_attr
Render ALLOW_LINTS as a #[allow(…)] attribute token stream.
apply_companions
Merge downstream Companion files into the per-package stitcher produced by generate.
decode_failure
Describe a failure to decode a descriptor set, naming the override when the element-memory bound is what rejected it.
decode_request
Decode a CodeGeneratorRequest from a protoc plugin’s stdin.
element_memory_limit_opt
Find element_memory_limit=<value> in a protoc plugin parameter string.
encode_descriptor_set
Encode the shared reflection FileDescriptorSet for a codegen run, with source_code_info stripped, ready to embed once at the module-tree root in shared-pool mode.
generate
Generate Rust source files from a set of file descriptors.
generate_module_tree
Generate a module tree that assembles per-package .mod.rs files into nested pub mod blocks matching the protobuf package hierarchy.
generate_with_diagnostics
Like generate, but also returns the non-fatal CodeGenWarnings collected during generation (e.g. enums whose idiomatic CamelCase aliases were suppressed by a naming conflict).
normalize_exclude_package
Normalize and validate one exclude_package option value: trim whitespace, strip the optional leading dot, reject an empty result or a value with empty components (buf.validate., buf..validate) — those could never match a real package, so a typo would otherwise be a silent no-op.
normalize_extern_path_proto_name
Normalize and validate the proto side of one extern_path mapping.
package_is_excluded
Returns true if package is covered by any entry in excludes.
package_to_filename
Convert a proto package name to its file_per_package output filename.
package_to_mod_filename
Convert a proto package name to its .mod.rs stitcher filename.
peek_request_parameter
Read CodeGeneratorRequest.parameter (field 2) straight off the wire, without decoding the request.
proto_path_to_stem
Convert a .proto file path to its content-file stem.
shared_descriptor_root_module
Render the shared __buffa_fds root module as formatted Rust source, for a front-end to prepend to the module-tree file in shared-pool mode. Every package’s __buffa::reflect module delegates here, so the descriptor set is embedded once for the whole tree instead of once per package.
tooling_decode_options
Decode options for a descriptor set produced by the caller’s own build, honouring ELEMENT_MEMORY_LIMIT_ENV.