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:
+36
@@ -50,6 +50,42 @@ chrono = { workspace = true, optional = true }
|
|||||||
static_init = { workspace = true }
|
static_init = { workspace = true }
|
||||||
unshell-macros = { path = "./unshell-macros" }
|
unshell-macros = { path = "./unshell-macros" }
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "leaf_derive"
|
||||||
|
path = "examples/protocol/leaf_derive.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "remote_shell_endpoint"
|
||||||
|
path = "examples/protocol/remote_shell_endpoint.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "remote_shell_receive"
|
||||||
|
path = "examples/protocol/remote_shell_receive.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "bench"
|
||||||
|
path = "examples/protocol/bench/bench.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "op_encode_call"
|
||||||
|
path = "examples/protocol/bench/op_encode_call.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "op_decode_call"
|
||||||
|
path = "examples/protocol/bench/op_decode_call.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "op_forward_call_receive"
|
||||||
|
path = "examples/protocol/bench/op_forward_call_receive.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "op_local_call_receive"
|
||||||
|
path = "examples/protocol/bench/op_local_call_receive.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "op_hook_data_receive"
|
||||||
|
path = "examples/protocol/bench/op_hook_data_receive.rs"
|
||||||
|
|
||||||
[profile.minimize]
|
[profile.minimize]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
strip = true # Strip symbols from the binary
|
strip = true # Strip symbols from the binary
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!();
|
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.");
|
println!("the standalone operation binaries under strace, perf, and heaptrack.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,11 +302,11 @@ fn run_external_tools() {
|
|||||||
build_examples(root);
|
build_examples(root);
|
||||||
|
|
||||||
let ops = [
|
let ops = [
|
||||||
("encode_call", "protocol_op_encode_call"),
|
("encode_call", "op_encode_call"),
|
||||||
("decode_call", "protocol_op_decode_call"),
|
("decode_call", "op_decode_call"),
|
||||||
("forward_call_receive", "protocol_op_forward_call_receive"),
|
("forward_call_receive", "op_forward_call_receive"),
|
||||||
("local_call_receive", "protocol_op_local_call_receive"),
|
("local_call_receive", "op_local_call_receive"),
|
||||||
("hook_data_receive", "protocol_op_hook_data_receive"),
|
("hook_data_receive", "op_hook_data_receive"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let heap_dir = root.join("heaptrack-cli");
|
let heap_dir = root.join("heaptrack-cli");
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#[path = "support/protocol_bench_common.rs"]
|
#[path = "support/bench_common.rs"]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#[path = "support/protocol_bench_common.rs"]
|
#[path = "support/bench_common.rs"]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#[path = "support/protocol_bench_common.rs"]
|
#[path = "support/bench_common.rs"]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#[path = "support/protocol_bench_common.rs"]
|
#[path = "support/bench_common.rs"]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#[path = "support/protocol_bench_common.rs"]
|
#[path = "support/bench_common.rs"]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
fn main() {
|
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;
|
mod common;
|
||||||
|
|
||||||
use std::error::Error;
|
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;
|
mod common;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
Reference in New Issue
Block a user