Expand description
Starpc - Streaming Protobuf RPC Framework
This crate provides a streaming RPC framework built on protobuf, offering full-duplex bidirectional streaming with support for unary, server-streaming, client-streaming, and bidirectional streaming RPC patterns.
§Features
- Wire-compatible with the Go and TypeScript implementations
- Streaming support for all RPC patterns
- Transport agnostic - works with TCP, WebSocket, or any AsyncRead/AsyncWrite
- Code generation via the optional
buildfeature
§Quick Start
§Client
ⓘ
use starpc::{Client, SrpcClient};
use starpc::client::transport::SingleStreamOpener;
use tokio::net::TcpStream;
// Connect to a server
let stream = TcpStream::connect("127.0.0.1:8080").await?;
let opener = SingleStreamOpener::new(stream);
let client = SrpcClient::new(opener);
// Make a unary call
let response: MyResponse = client
.exec_call("my.Service", "MyMethod", &request)
.await?;§Server
ⓘ
use starpc::{Server, Mux, Handler};
use std::sync::Arc;
// Create a mux and register handlers
let mux = Arc::new(Mux::new());
mux.register(Arc::new(MyServiceHandler))?;
// Create the server
let server = Server::with_arc(mux);
// Handle a connection
server.handle_stream(tcp_stream).await?;§Wire Format
Starpc uses a simple length-prefixed framing:
- 4-byte little-endian u32 length prefix
- Protobuf-encoded Packet message
This format is compatible with the Go and TypeScript implementations.
Re-exports§
pub use client::BoxClient;pub use client::Client;pub use client::OpenStream;pub use client::SrpcClient;pub use codec::PacketCodec;pub use codec::MAX_MESSAGE_SIZE;pub use error::Error;pub use error::Result;pub use handler::BoxHandler;pub use handler::Handler;pub use invoker::BoxInvoker;pub use invoker::Invoker;pub use message::Message;pub use mux::Mux;pub use mux::QueryableInvoker;pub use packet::Validate;pub use rpc::ClientRpc;pub use rpc::PacketWriter;pub use rpc::ServerRpc;pub use server::Server;pub use server::ServerConfig;pub use stream::ArcStream;pub use stream::BoxStream;pub use stream::Context;pub use stream::Stream;pub use stream::StreamExt;pub use transport::create_packet_channel;pub use transport::decode_optional_data;pub use transport::encode_optional_data;pub use transport::TransportPacketWriter;
Modules§
- client
- Client implementation for starpc.
- codec
- Length-prefixed packet codec for starpc wire format.
- error
- Error types for starpc.
- handler
- Handler trait for RPC service implementations.
- invoker
- Invoker trait for RPC method invocation.
- message
- Message trait for protobuf messages.
- mux
- Service multiplexer for routing RPC calls.
- packet
- Packet utility functions and validation.
- prelude
- Prelude module for convenient imports.
- proto
- Protocol buffer definitions for starpc.
- rpc
- RPC state machines for client and server.
- rpcstream
- RpcStream module for nested RPC calls.
- server
- Server implementation for starpc.
- stream
- Stream abstraction for RPC communication.
- testing
- Testing utilities for starpc.
- transport
- Transport utilities for starpc.
Traits§
- Prost
Message - A Protocol Buffers message.