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

Function read_message

src/protocol.rs:49–71  ·  view source on GitHub ↗
(reader: &mut R)

Source from the content-addressed store, hash-verified

47}
48
49pub async fn read_message<R, T>(reader: &mut R) -> std::io::Result<T>
50where
51 R: AsyncReadExt + Unpin,
52 T: for<'de> Deserialize<'de>,
53{
54 let mut len_buf = [0u8; 4];
55 reader.read_exact(&mut len_buf).await?;
56 let len = u32::from_be_bytes(len_buf) as usize;
57
58 // Sanity check to prevent OOM
59 if len > 10 * 1024 * 1024 {
60 return Err(std::io::Error::new(
61 std::io::ErrorKind::InvalidData,
62 "message too large",
63 ));
64 }
65
66 let mut payload = vec![0u8; len];
67 reader.read_exact(&mut payload).await?;
68
69 rmp_serde::from_slice(&payload)
70 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
71}

Callers 1

send_requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected