dubbo-rs-codegen
protoc code generation plugin for dubbo-rs.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Or use cargo add:
Integrates with tonic-prost-build to compile .proto files, generating standard proto types + tonic service stubs to OUT_DIR. Then produces Dubbo-specific integration wrappers (service registration helpers, channel-based and invoker-based clients) as GeneratedCode.
Key Types
| Type | Description |
|---|---|
CodeGenerator |
Main entry point — takes GeneratorConfig, runs code generation |
GeneratorConfig |
Configuration: proto_paths, output_dir, enable_client, enable_server, client_mode |
GeneratorConfigBuilder |
Builder for GeneratorConfig — validates proto_paths is non-empty |
GeneratedCode |
Output container — files: HashMap<String, String>, with write_to_dir |
ClientMode |
Client generation mode: Channel, Invoker, or Both (default) |
Client Modes
| Mode | Description |
|---|---|
Channel |
Generates a channel-based client wrapping tonic's typed GreeterClient<Channel> |
Invoker |
Generates an invoker-based client using Box<dyn Invoker> with prost encoding |
Both (default) |
Generates both client types |
Channel Client
Wraps the tonic-generated typed client. Provides connect(), from_channel(), and from_dubbo_client() constructors. Supports all 4 RPC types (unary, server-streaming, client-streaming, bidi-streaming).
Invoker Client
Uses Box<dyn dubbo_rs_protocol::Invoker> with prost::Message encoding/decoding. Unary methods are fully supported. Streaming methods generate a comment indicating they are not supported via Invoker and the user should use the Channel client instead.
Usage
use ;
let config = new
.proto_path
.proto_path
.output_dir
.enable_client
.enable_server
.client_mode
.build?;
let generator = new;
let generated = generator.generate?;
// Write generated files to disk
generated.write_to_dir?;
Generated Output
For a proto with package greeter and service Greeter, generates greeter_dubbo.rs:
//! Dubbo integration for `greeter` package.
//! Generated by dubbo-codegen. DO NOT EDIT.
/// Proto types and tonic stubs.
// === Service Registration ===
/// Register a `Greeter` service with a Dubbo server.
// === Channel Client ===
// === Invoker Client ===
Streaming Support
All 4 RPC types are supported in generated code:
| RPC Type | Channel Client | Invoker Client |
|---|---|---|
| Unary | ✅ Forwarded to tonic | ✅ prost encode/decode |
| Server Streaming | ✅ tonic::codec::Streaming<T> |
❌ Use Channel client |
| Client Streaming | ✅ IntoStreamingRequest |
❌ Use Channel client |
| Bidi Streaming | ✅ Both streaming | ❌ Use Channel client |
Streaming Proto Example
For a streaming proto like:
service TelephoneExchange {
rpc Dial(DialRequest) returns (stream DialProgress);
}
The generated channel client method returns:
pub async
License
Apache-2.0