Skip to main content

Crate krabka_protocol_codegen

Crate krabka_protocol_codegen 

Source
Expand description

Build-time code generator for the krabka-protocol crate.

The generator reads the vendored Apache Kafka JSON message schemas, validates the subset Krabka supports, resolves nested and common structs, and emits the owned and borrowed Rust protocol modules. tools/regenerate.sh drives the binary wrapper and writes the committed tree under crates/protocol/generated. The library API is useful for tests and for one-off schema audits.

§Loading and validating schemas

use std::path::Path;

use krabka_protocol_codegen::{ir, validate};

let specs = ir::load_dir(Path::new("crates/protocol/schemas"))?;
validate::validate(&specs)?;
println!("loaded {} protocol schemas", specs.len());

§Resolving generated type paths

use std::path::Path;

use krabka_protocol_codegen::{ir, resolve};

let specs = ir::load_dir(Path::new("crates/protocol/schemas"))?;
let metadata = specs.iter().find(|s| s.name == "MetadataRequest").unwrap();
let resolution = resolve::resolve_message(metadata)?;
println!("{} referenced struct types", resolution.len());

Modules§

driver
One generator run: load and validate the schemas, emit every message, and write the generated tree and its wrapper modules.
emit
fmt
Format generated Rust source: pretty-print the AST with prettyplease, then refine through rustfmt.
hoist
Hoist absolute paths in generated code into module-scope use items.
ir
name_conv
Convert Kafka schema identifiers (camelCase, PascalCase) into idiomatic Rust identifiers (snake_case for fields/modules, PascalCase for types), with reserved-keyword escape and acronym handling.
out
The output ledger: every path one generator run writes, and the sweep that deletes the generated files it did not.
resolve
Classify PascalCase type references in a MessageSpec as nested, common, or unknown.
type_map
Map a schema field type string to a Rust type expression.
validate