use proto_build_kit::{Stager, compile_protos};
const HELLO_PROTO: &[u8] = br#"
syntax = "proto3";
package hello.v1;
service HelloService {
rpc Greet(GreetRequest) returns (Greeting);
rpc ListGreetings(ListGreetingsRequest) returns (ListGreetingsResponse);
}
message GreetRequest { string name = 1; }
message Greeting { string message = 1; }
message ListGreetingsRequest { uint32 page_size = 1; }
message ListGreetingsResponse { repeated Greeting items = 1; }
"#;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let staged = Stager::new()
.add("hello/v1/hello.proto", HELLO_PROTO)
.stage()?;
println!("Staged proto at: {}", staged.path().display());
let out = compile_protos(&["hello/v1/hello.proto"], &[staged.path()])?;
println!("Compiled. FDS size: {} bytes", out.fds_bytes.len());
for service in out.pool.services() {
println!("\nService: {}", service.full_name());
for method in service.methods() {
println!(
" {} ({} → {})",
method.name(),
method.input().full_name(),
method.output().full_name()
);
}
}
Ok(())
}