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

Function parse_value

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

Parse a RESP value starting at `buf[0]`. Returns `(value, bytes_consumed)`.

(buf: &[u8])

Source from the content-addressed store, hash-verified

210
211/// Parse a RESP value starting at `buf[0]`. Returns `(value, bytes_consumed)`.
212fn parse_value(buf: &[u8]) -> io::Result<Option<(RespValue, usize)>> {
213 if buf.is_empty() {
214 return Ok(None);
215 }
216
217 match buf[0] {
218 b'+' => parse_simple_string(&buf[1..])
219 .map(|opt| opt.map(|(s, n)| (RespValue::SimpleString(s), n + 1))),
220 b'-' => {
221 parse_simple_string(&buf[1..]).map(|opt| opt.map(|(s, n)| (RespValue::Error(s), n + 1)))
222 }
223 b':' => {
224 parse_integer(&buf[1..]).map(|opt| opt.map(|(i, n)| (RespValue::Integer(i), n + 1)))
225 }
226 b'$' => parse_bulk_string(&buf[1..]).map(|opt| opt.map(|(v, n)| (v, n + 1))),
227 b'*' => parse_array(&buf[1..]).map(|opt| opt.map(|(v, n)| (v, n + 1))),
228 other => Err(io::Error::new(
229 io::ErrorKind::InvalidData,
230 format!("unexpected RESP type byte: 0x{other:02x}"),
231 )),
232 }
233}
234
235fn parse_simple_string(buf: &[u8]) -> io::Result<Option<(String, usize)>> {
236 match find_crlf(buf) {

Callers 2

try_parseMethod · 0.70
parse_arrayFunction · 0.70

Calls 6

parse_simple_stringFunction · 0.85
ErrorEnum · 0.85
parse_integerFunction · 0.85
parse_bulk_stringFunction · 0.85
parse_arrayFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected