repe 8.0.0

Rust implementation of the REPE RPC protocol (JSON-focused)
Documentation

repe-rs

Rust implementation of the REPE RPC protocol with JSON and BEVE body support.

crates.io docs

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 the beve crate.
  • Sync and async (tokio) clients and servers, with multiplexed in-flight requests, per-call timeouts, batching, and notify support.
  • Dynamic Registry routing with JSON Pointer semantics.
  • Fleet APIs for multi-node TCP and UDP fanout.
  • Optional WebSocket transport, including a wasm browser client and server-pushed notify subscriptions.
  • Optional stream module for backpressure-controlled bulk transfers with reconnect-resume.
  • Optional repe CLI for talking to any REPE server over TCP or WebSocket.

Installation

Add to your Cargo.toml:

[dependencies]
repe = "8"

Or run cargo add repe.

Quick Start

Build, serialize, and parse a JSON message:

use repe::{BodyFormat, Message, QueryFormat};

let msg = Message::builder()
    .id(42)
    .query_str("/status")
    .query_format(QueryFormat::JsonPointer)
    .body_json(&serde_json::json!({"ping": true}))?
    .build();

let bytes = msg.to_vec();
let parsed = repe::Message::from_slice(&bytes)?;

assert_eq!(parsed.header.id, 42);
assert_eq!(parsed.header.body_format, BodyFormat::Json as u16);
let val: serde_json::Value = parsed.json_body()?;
assert_eq!(val["ping"], true);
# Ok::<(), Box<dyn std::error::Error>>(())

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 repe::{Client, Router, Server};
use serde_json::json;

let router = Router::new().with("/ping", |_v| Ok(json!({"pong": true})));
let server = Server::new(router);
let listener = server.listen("127.0.0.1:0")?;
let addr = listener.local_addr()?;
std::thread::spawn(move || { let _ = server.serve(listener); });

let client = Client::connect(addr)?;
let pong = client.call_json("/ping", &json!({}))?;
assert_eq!(pong["pong"], true);
# Ok::<(), Box<dyn std::error::Error>>(())

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 repe::{Client, Router, Server};

let router = Router::new()
    .with_typed_slice::<f64, f64, _>("/scale", |xs| Ok(xs.iter().map(|x| x * 2.0).collect()));
let server = Server::new(router);
let listener = server.listen("127.0.0.1:0")?;
let addr = listener.local_addr()?;
std::thread::spawn(move || { let _ = server.serve(listener); });

let client = Client::connect(addr)?;
let out: Vec<f64> = client.call_typed_slice("/scale", &[1.0, 2.0, 3.0])?;
assert_eq!(out, vec![2.0, 4.0, 6.0]);
# Ok::<(), Box<dyn std::error::Error>>(())

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 repe::{Client, Router, Server};

let router = Router::new()
    .with_typed_slice_ref::<f64, f64, _>("/sum", |xs| Ok(vec![xs.iter().sum()]));
let server = Server::new(router);
let listener = server.listen("127.0.0.1:0")?;
let addr = listener.local_addr()?;
std::thread::spawn(move || { let _ = server.serve(listener); });

let client = Client::connect(addr)?;
let out: Vec<f64> = client.call_typed_slice_aligned("/sum", &[1.0, 2.0, 3.0])?;
assert_eq!(out, vec![6.0]);
# Ok::<(), Box<dyn std::error::Error>>(())

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.

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.