Skip to main content

encode_hello

Function encode_hello 

Source
pub fn encode_hello(h: &Hello) -> Vec<u8> 
Examples found in repository?
examples/bench.rs (lines 29-34)
25fn main() {
26    let iters = 2_000_000usize;
27
28    bench("encode+decode Hello (small)", iters, || {
29        let b = pxb::encode_hello(&pxb::Hello {
30            name: "greet".into(),
31            version: "1.0.0".into(),
32            caps: 3,
33            protocol: 1,
34        });
35        std::hint::black_box(pxb::decode_hello(&b).unwrap());
36    });
37
38    let req = pxb::InterceptReq {
39        event: pxb::Event::ToolCall.code(),
40        tool_name: "bash".into(),
41        tool_call_id: "call_01JX9K2M".into(),
42        input: br#"{"command":"ls -la /tmp","cwd":"/workspace"}"#.to_vec(),
43        turn_index: 3,
44        ..Default::default()
45    };
46    let frame = pxb::encode_intercept_req(&req);
47    println!("\nInterceptReq payload: {} bytes", frame.len());
48    bench("encode+decode InterceptReq (tool_call)", iters, || {
49        let b = pxb::encode_intercept_req(&req);
50        let d = pxb::decode_intercept_req(&b).unwrap();
51        std::hint::black_box(d.tool_call_id);
52    });
53
54    let ev = pxb::EventNotify {
55        event: pxb::Event::ToolResult.code(),
56        tool_name: "bash".into(),
57        tool_call_id: "call_01JX9K2M".into(),
58        input: req.input.clone(),
59        turn_index: 3,
60        session_id: "sess_01JX".into(),
61        ..Default::default()
62    };
63    let frame = pxb::encode_event_notify(&ev);
64    println!("EventNotify payload: {} bytes", frame.len());
65    bench("encode+decode EventNotify (tool_result)", iters, || {
66        let b = pxb::encode_event_notify(&ev);
67        let d = pxb::decode_event_notify(&b).unwrap();
68        std::hint::black_box(d.session_id);
69    });
70
71    // In-memory frame read/write: the syscall-free floor for one RPC.
72    bench("write_frame+read_frame (in-memory)", iters / 4, || {
73        let mut buf = Vec::new();
74        pxb::write_frame(&mut buf, pxb::TYPE_INTERCEPT, pxb::FLAG_HAS_ID, 42, &frame).unwrap();
75        let mut cur = std::io::Cursor::new(buf);
76        let f = pxb::read_frame(&mut cur).unwrap();
77        std::hint::black_box(f.body.len());
78    });
79}