Skip to main content

parse_file_descriptor_set

Function parse_file_descriptor_set 

Source
pub fn parse_file_descriptor_set(
    file_descriptor_set: &FileDescriptorSet,
) -> Result<CodeGenMetadata>
Expand description

Parse a compiled protobuf FileDescriptorSet into CodeGenMetadata.

This is the first stage of the code-generation pipeline. It walks every message, enum, and service in the descriptor set and extracts the annotations that drive generation (google.api.http, google.api.resource, field_behavior, debug_redact, …) into a structured form.

The full pipeline is three stages:

FileDescriptorSet
  │  parse_file_descriptor_set
  ▼
CodeGenMetadata
  │  analyze_metadata          (analysis/mod.rs)
  ▼
GenerationPlan
  │  generate_code             (codegen/mod.rs)
  ▼
Rust / Python / TypeScript source written to disk

Typical usage from a build script:

ⓘ
let fds = prost_types::FileDescriptorSet::decode(&bytes[..])?;
let metadata = parse_file_descriptor_set(&fds)?;
let config = CodeGenConfig::new(/* … */);
generate_code(&metadata, &config)?;

Methods without HTTP annotations are not an error here; they are recorded later, during analyze_metadata.

§Errors

Returns:

  • Error::InvalidAnnotation if a google.api.http, google.api.resource, or field_behavior annotation is present but malformed (e.g. a resource pattern or HTTP rule that cannot be interpreted).
  • Error::Build if an annotation extension cannot be decoded from its raw descriptor bytes.