MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / parse

Method parse

src/protocol/parser.rs:51–84  ·  view source on GitHub ↗
(&mut self, input: BufferParameter, mut callback: F)

Source from the content-addressed store, hash-verified

49 }
50
51 pub fn parse<F>(&mut self, input: BufferParameter, mut callback: F) -> Result<()>
52 where
53 F: FnMut(BackendMessage) -> Result<()>,
54 {
55 self.buffer.extend_from_slice(input);
56
57 let mut cursor = 0usize;
58 while self.buffer.len().saturating_sub(cursor) >= HEADER_LEN {
59 let code = self.buffer[cursor];
60 let length_bytes = &self.buffer[cursor + 1..cursor + HEADER_LEN];
61 let length = u32::from_be_bytes([
62 length_bytes[0],
63 length_bytes[1],
64 length_bytes[2],
65 length_bytes[3],
66 ]) as usize;
67 let total_len = 1 + length;
68
69 if self.buffer.len() - cursor < total_len {
70 break; // wait for more data
71 }
72
73 let body = &self.buffer[cursor + HEADER_LEN..cursor + total_len]; // exclude code+length header
74 let message = self.handle_packet(code, body, length)?;
75 callback(message)?;
76 cursor += total_len;
77 }
78
79 if cursor > 0 {
80 self.buffer.drain(0..cursor);
81 }
82
83 Ok(())
84 }
85
86 fn handle_packet(&self, code: u8, bytes: &[u8], length: usize) -> Result<BackendMessage> {
87 let mut reader = BufferReader::default();

Callers 15

perf_warmFunction · 0.45
perf_benchFunction · 0.45
perf_native_postgresFunction · 0.45
perf_pglite_nodefs_sqlxFunction · 0.45
perf_prepared_updatesFunction · 0.45
parsed_numeric_updatesFunction · 0.45
parsed_text_updatesFunction · 0.45
parse_u64_fieldFunction · 0.45
parse_vec_chunksFunction · 0.45
parse_slicesFunction · 0.45
retrieve_row_countFunction · 0.45

Calls 2

lenMethod · 0.80
handle_packetMethod · 0.80

Tested by 2

parse_vec_chunksFunction · 0.36
parse_slicesFunction · 0.36