sausage-plugin part 2: import! with typed clients (sausage_interface::client_rs), TCP endpoints with rpc.endpoint, examples

Part 1 fixes: complete stdout writes, buffered stdin, Rust type names
in schemas, enum variant docs, -32603 for serde errors in handlers,
crate docs and modules. End-to-end check of a generated consumer through
a fake core.
This commit is contained in:
2026-10-23 00:35:45 +01:00
parent ae1cb4cc99
commit 8d3c163992
42 changed files with 3020 additions and 856 deletions
+33 -1
View File
@@ -16,14 +16,32 @@ struct Retired {
/// The previous hash.
previous: String,
}
#[rpc(grace_seconds = 12)]
/// A large payload.
#[schema]
struct Echo {
/// The text to return unchanged.
text: String,
}
#[rpc(grace_seconds = 12,endpoints(control=Control))]
impl Probe {
/// Publish a control endpoint until EOF.
async fn serve(&self) -> Result<()> {
sausage_plugin::listen("/endpoint", std::rc::Rc::new(Control)).await
}
/// Add two numbers.
///
/// The result is their sum.
fn add(&self, p: Add) -> Result<i32> {
Ok(p.a + p.b)
}
/// Echo a payload larger than a host I/O buffer.
fn echo(&self, p: Echo) -> Result<String> {
Ok(p.text)
}
/// Return an internal serialization error.
fn serde_error(&self) -> Result<String> {
Ok(sausage_plugin::serde_json::from_str::<String>("invalid")?)
}
/// Return a deliberate error.
fn fail(&self) -> Result<String> {
Err(sausage_plugin::Error::new(-32010, "deliberate"))
@@ -109,6 +127,20 @@ async fn join(
})
.await
}
struct Control;
#[rpc]
impl Control {
/// Report progress and return a stable counter.
fn stats(&self, ctx: &Ctx) -> Result<u64> {
ctx.notify("endpoint-progress", json!({"value":7}))?;
Ok(7)
}
/// End the endpoint process after the response.
fn stop(&self, ctx: &Ctx) -> Result<()> {
ctx.exit_after_response();
Ok(())
}
}
fn main() {
sausage_plugin::run(Probe)
}