repe-rs
Rust implementation of the REPE RPC protocol with JSON and BEVE body support.
Features
- REPE header and message types with correct little-endian wire encoding.
- Streaming and zero-copy I/O (
MessageView,write_message_streaming) for large bodies. - JSON bodies via
serde_json; BEVE bodies via thebevecrate. - Sync and async (tokio) clients and servers, with multiplexed in-flight requests, per-call timeouts, batching, and notify support.
- Dynamic
Registryrouting with JSON Pointer semantics. FleetAPIs for multi-node TCP and UDP fanout.- Optional WebSocket transport, including a wasm browser client and server-pushed notify subscriptions.
- Optional
streammodule for backpressure-controlled bulk transfers with reconnect-resume. - Optional
repeCLI for talking to any REPE server over TCP or WebSocket.
Installation
Add to your Cargo.toml:
[]
= "2.3"
Or run cargo add repe.
Quick Start
Build, serialize, and parse a JSON message:
use ;
let msg = builder
.id
.query_str
.query_format
.body_json?
.build;
let bytes = msg.to_vec;
let parsed = from_slice?;
assert_eq!;
assert_eq!;
let val: Value = parsed.json_body?;
assert_eq!;
# Ok::
Replace body_json with body_beve to encode the body with BEVE; everything else is identical.
Server and Client
A minimal TCP server with one route, plus a client call:
use ;
use json;
let router = new.with;
let server = new;
let listener = server.listen?;
let addr = listener.local_addr?;
spawn;
let client = connect?;
let pong = client.call_json?;
assert_eq!;
# Ok::
The async (tokio) variant uses AsyncServer and AsyncClient and exposes the same shape. See the Server guide for routers, typed handlers, middleware, struct registration, and peer-aware handlers, and the Client guide for the full client surface (typed and BEVE helpers, multiplexing, timeouts, batches, notifies, error handling).
Bulk numeric arrays
When a request and response are whole contiguous numeric arrays (f32, f64, integer widths), Router::with_typed_slice and Client::call_typed_slice (also AsyncClient::call_typed_slice) carry them on BEVE's typed-slice fast path: one bulk copy each way, skipping serde's per-element walk. The wire bytes are identical to the serde path, so a with_typed_slice route and a with_typed / call_typed_beve peer interoperate freely.
use ;
let router = new
.;
let server = new;
let listener = server.listen?;
let addr = listener.local_addr?;
spawn;
let client = connect?;
let out: = client.call_typed_slice?;
assert_eq!;
# Ok::
For the request decode, Router::with_typed_slice_ref goes one step further and hands the handler a &[T] borrowed straight out of the receive buffer, with no allocation or element copy, when the client sends the aligned wire form via call_typed_slice_aligned:
use ;
let router = new
.;
let server = new;
let listener = server.listen?;
let addr = listener.local_addr?;
spawn;
let client = connect?;
let out: = client.call_typed_slice_aligned?;
assert_eq!;
# Ok::
A with_typed_slice_ref route is a drop-in superset of with_typed_slice: it still accepts the regular call_typed_slice / serde clients (bulk-copying those), and falls back to a bulk copy whenever a borrow isn't possible, so correctness never depends on the alignment landing.
Feature Flags
| Flag | Effect |
|---|---|
websocket |
Native WebSocketClient, WebSocketServer, and proxy_connection. |
websocket-wasm |
Browser WasmClient on wasm32-unknown-unknown. |
fleet-udp |
UDP fanout via UniUdpFleet. |
parking-lot |
Lockable impls for parking_lot::Mutex / RwLock. |
cli |
Builds the repe command-line client (pulls in clap and websocket). |
Documentation
Full documentation is hosted at repe-org.github.io/repe-rs.
- Server, routers, and handlers
- Client APIs
- Registry (dynamic routing)
- Fleet (multi-node control)
- WebSocket transport
- Streaming with backpressure
- Command-line client
- Wire format and JSON Pointer helpers
Examples
cargo run --example json_roundtrip
cargo run --example server
cargo run --example client
cargo run --example registry_server
cargo run --example registry_roundtrip
cargo run --example async_server
cargo run --example async_client
cargo run --example typed_numeric_body
Testing
Run cargo test to execute unit and integration tests. The crate denies warnings and includes async tests, so a recent tokio is required. Integration tests cover sync and async server/client calls, unknown routes, handler error mapping, ID mismatches, and timeouts.
License
MIT, see LICENSE.