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 throughrustfmt. - hoist
- Hoist absolute paths in generated code into module-scope
useitems. - ir
- name_
conv - Convert Kafka schema identifiers (camelCase,
PascalCase) into idiomatic Rust identifiers (snake_casefor fields/modules,PascalCasefor 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
PascalCasetype references in aMessageSpecas nested, common, or unknown. - type_
map - Map a schema field type string to a Rust type expression.
- validate