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

Method try_parse

nodedb/src/control/server/resp/codec.rs:146–178  ·  view source on GitHub ↗

Try to parse a complete RESP frame from the buffer. Returns `Ok(Some(value))` if a complete frame was parsed (consumed from buffer). Returns `Ok(None)` if more data is needed. Returns `Err` on protocol errors.

(&mut self)

Source from the content-addressed store, hash-verified

144 /// Returns `Ok(None)` if more data is needed.
145 /// Returns `Err` on protocol errors.
146 pub fn try_parse(&mut self) -> io::Result<Option<RespValue>> {
147 if self.buf.is_empty() {
148 return Ok(None);
149 }
150
151 match self.buf[0] {
152 b'+' | b'-' | b':' | b'$' | b'*' => {
153 let (value, consumed) = match parse_value(&self.buf) {
154 Ok(Some((v, n))) => (v, n),
155 Ok(None) => return Ok(None),
156 Err(e) => return Err(e),
157 };
158 self.buf.drain(..consumed);
159 Ok(Some(value))
160 }
161 // Inline command: plain text terminated by \r\n or \n.
162 _ => {
163 if let Some(pos) = find_line_end(&self.buf) {
164 let line = &self.buf[..pos];
165 let parts = parse_inline_command(line);
166 let consumed = if self.buf.get(pos + 1) == Some(&b'\n') {
167 pos + 2
168 } else {
169 pos + 1
170 };
171 self.buf.drain(..consumed);
172 Ok(Some(parts))
173 } else {
174 Ok(None) // Need more data.
175 }
176 }
177 }
178 }
179
180 /// Number of bytes in the parser buffer (for backpressure).
181 pub fn buffered(&self) -> usize {

Callers 7

parse_bulk_string_arrayFunction · 0.80
parse_inline_commandFunction · 0.80
parse_set_commandFunction · 0.80
parse_nil_bulk_stringFunction · 0.80
parse_multiple_commandsFunction · 0.80
roundtripFunction · 0.80
handle_connectionFunction · 0.80

Calls 6

find_line_endFunction · 0.85
parse_inline_commandFunction · 0.85
parse_valueFunction · 0.70
is_emptyMethod · 0.45
drainMethod · 0.45
getMethod · 0.45

Tested by 5

parse_bulk_string_arrayFunction · 0.64
parse_set_commandFunction · 0.64
parse_nil_bulk_stringFunction · 0.64
parse_multiple_commandsFunction · 0.64
roundtripFunction · 0.64