MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / read_frame

Function read_frame

nodedb/tests/native_protocol.rs:234–246  ·  view source on GitHub ↗

Read a length-prefixed frame from the stream. Returns `None` on EOF.

(stream: &mut TcpStream)

Source from the content-addressed store, hash-verified

232/// Read a length-prefixed frame from the stream.
233/// Returns `None` on EOF.
234async fn read_frame(stream: &mut TcpStream) -> Option<Vec<u8>> {
235 let mut len_buf = [0u8; FRAME_HEADER_LEN];
236 match stream.read_exact(&mut len_buf).await {
237 Ok(_) => {}
238 Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => return None,
239 Err(e) if e.kind() == std::io::ErrorKind::ConnectionReset => return None,
240 Err(e) => panic!("read_frame error: {e}"),
241 }
242 let payload_len = u32::from_be_bytes(len_buf) as usize;
243 let mut payload = vec![0u8; payload_len];
244 stream.read_exact(&mut payload).await.expect("read payload");
245 Some(payload)
246}
247
248// ─── Tests ──────────────────────────────────────────────────────────────────
249

Calls 3

kindMethod · 0.80
read_exactMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected