mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Reorganize protocol examples
This commit is contained in:
@@ -43,7 +43,7 @@ fn main() {
|
||||
}
|
||||
|
||||
println!();
|
||||
println!("Run `cargo run --example protocol_bench -- tools` to build and execute");
|
||||
println!("Run `cargo run --example bench -- tools` to build and execute");
|
||||
println!("the standalone operation binaries under strace, perf, and heaptrack.");
|
||||
}
|
||||
|
||||
@@ -302,11 +302,11 @@ fn run_external_tools() {
|
||||
build_examples(root);
|
||||
|
||||
let ops = [
|
||||
("encode_call", "protocol_op_encode_call"),
|
||||
("decode_call", "protocol_op_decode_call"),
|
||||
("forward_call_receive", "protocol_op_forward_call_receive"),
|
||||
("local_call_receive", "protocol_op_local_call_receive"),
|
||||
("hook_data_receive", "protocol_op_hook_data_receive"),
|
||||
("encode_call", "op_encode_call"),
|
||||
("decode_call", "op_decode_call"),
|
||||
("forward_call_receive", "op_forward_call_receive"),
|
||||
("local_call_receive", "op_local_call_receive"),
|
||||
("hook_data_receive", "op_hook_data_receive"),
|
||||
];
|
||||
|
||||
let heap_dir = root.join("heaptrack-cli");
|
||||
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_bench_common.rs"]
|
||||
#[path = "support/bench_common.rs"]
|
||||
mod common;
|
||||
|
||||
fn main() {
|
||||
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_bench_common.rs"]
|
||||
#[path = "support/bench_common.rs"]
|
||||
mod common;
|
||||
|
||||
fn main() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_bench_common.rs"]
|
||||
#[path = "support/bench_common.rs"]
|
||||
mod common;
|
||||
|
||||
fn main() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_bench_common.rs"]
|
||||
#[path = "support/bench_common.rs"]
|
||||
mod common;
|
||||
|
||||
fn main() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_bench_common.rs"]
|
||||
#[path = "support/bench_common.rs"]
|
||||
mod common;
|
||||
|
||||
fn main() {
|
||||
@@ -0,0 +1,46 @@
|
||||
use std::error::Error;
|
||||
|
||||
use unshell::Leaf;
|
||||
use unshell::protocol::tree::{Endpoint, Ingress, LocalEvent, ProtocolEndpoint};
|
||||
|
||||
#[derive(Leaf)]
|
||||
#[leaf(org = "org", product = "example", version = "v1", leaf_name = "echo")]
|
||||
#[leaf(procedures(call, stream))]
|
||||
struct EchoLeaf;
|
||||
|
||||
fn path(parts: &[&str]) -> Vec<String> {
|
||||
parts.iter().map(|part| (*part).to_owned()).collect()
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut endpoint = ProtocolEndpoint::new(
|
||||
path(&["agent"]),
|
||||
Some(Vec::new()),
|
||||
Vec::new(),
|
||||
vec![EchoLeaf::protocol_leaf_spec()],
|
||||
);
|
||||
|
||||
let hook_id = endpoint.allocate_hook_id();
|
||||
let frame = endpoint.make_call(
|
||||
path(&["agent"]),
|
||||
Some(EchoLeaf::protocol_leaf_name()),
|
||||
EchoLeaf::protocol_procedure_id("call").expect("known procedure suffix"),
|
||||
Some(hook_id),
|
||||
b"hello leaf".to_vec(),
|
||||
)?;
|
||||
|
||||
let outcome = endpoint.receive(&Ingress::Parent, frame)?;
|
||||
let Some(LocalEvent::Call { header, message }) = outcome.event else {
|
||||
return Err("expected local leaf call".into());
|
||||
};
|
||||
|
||||
assert_eq!(header.dst_leaf.as_deref(), Some("org.example.v1.echo"));
|
||||
assert_eq!(message.procedure_id, "org.example.v1.echo.call");
|
||||
|
||||
println!(
|
||||
"leaf={} procedure={}",
|
||||
EchoLeaf::protocol_leaf_name(),
|
||||
message.procedure_id
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_remote_shell_common.rs"]
|
||||
#[path = "support/remote_shell_common.rs"]
|
||||
mod common;
|
||||
|
||||
use std::error::Error;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#[path = "support/protocol_remote_shell_common.rs"]
|
||||
#[path = "support/remote_shell_common.rs"]
|
||||
mod common;
|
||||
|
||||
use std::error::Error;
|
||||
Reference in New Issue
Block a user