MCPcopy Create free account
hub / github.com/SamSaffron/op-cache / write_message

Function write_message

src/protocol.rs:34–47  ·  view source on GitHub ↗

Wire format: [4-byte length (big-endian)][MessagePack payload]

(writer: &mut W, msg: &T)

Source from the content-addressed store, hash-verified

32
33/// Wire format: [4-byte length (big-endian)][MessagePack payload]
34pub async fn write_message<W, T>(writer: &mut W, msg: &T) -> std::io::Result<()>
35where
36 W: AsyncWriteExt + Unpin,
37 T: Serialize,
38{
39 let payload = rmp_serde::to_vec(msg)
40 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
41
42 let len = payload.len() as u32;
43 writer.write_all(&len.to_be_bytes()).await?;
44 writer.write_all(&payload).await?;
45 writer.flush().await?;
46 Ok(())
47}
48
49pub async fn read_message<R, T>(reader: &mut R) -> std::io::Result<T>
50where

Callers 1

send_requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected