MCPcopy Create free account
hub / github.com/Botloader/botloader / read_message

Function read_message

components/simpleproto/src/lib.rs:7–21  ·  view source on GitHub ↗
(
    src: &mut (impl AsyncRead + Unpin),
)

Source from the content-addressed store, hash-verified

5};
6
7pub async fn read_message<T: DeserializeOwned>(
8 src: &mut (impl AsyncRead + Unpin),
9) -> std::io::Result<T> {
10 let len = src.read_u32().await?;
11
12 let mut payload_buf = vec![0; len as usize];
13 src.read_exact(&mut payload_buf).await?;
14
15 // Uncomment the below to debug the output
16 // let s = String::from_utf8_lossy(&payload_buf);
17 // dbg!(s);
18
19 let decoded = serde_json::from_slice(&payload_buf)?;
20 Ok(decoded)
21}
22
23pub async fn write_message<T: Serialize>(
24 msg: &T,

Callers 4

listen_for_workersFunction · 0.85
runMethod · 0.85
wait_for_ackMethod · 0.85
message_readerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected