MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / read_msg

Function read_msg

src/protocol.rs:78–89  ·  view source on GitHub ↗

Read a length-prefixed message from a stream.

(r: &mut R)

Source from the content-addressed store, hash-verified

76
77/// Read a length-prefixed message from a stream.
78pub async fn read_msg<R: AsyncReadExt + Unpin>(r: &mut R) -> anyhow::Result<Vec<u8>> {
79 let mut len_buf = [0u8; 4];
80 r.read_exact(&mut len_buf).await?;
81 let len =
82 usize::try_from(u32::from_be_bytes(len_buf)).context("Message length overflows usize")?;
83 if len > 64 * 1024 * 1024 {
84 anyhow::bail!("Message too large: {len} bytes");
85 }
86 let mut buf = vec![0u8; len];
87 r.read_exact(&mut buf).await?;
88 Ok(buf)
89}

Callers 2

handle_connectionFunction · 0.85
send_to_daemonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected