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

Function parse_array

nodedb/src/control/server/resp/codec.rs:288–319  ·  view source on GitHub ↗
(buf: &[u8])

Source from the content-addressed store, hash-verified

286}
287
288fn parse_array(buf: &[u8]) -> io::Result<Option<(RespValue, usize)>> {
289 let crlf_pos = match find_crlf(buf) {
290 Some(p) => p,
291 None => return Ok(None),
292 };
293
294 let count_str = std::str::from_utf8(&buf[..crlf_pos])
295 .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
296 let count: i64 = count_str
297 .parse()
298 .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
299
300 if count < 0 {
301 return Ok(Some((RespValue::nil_array(), crlf_pos + 2)));
302 }
303
304 let count = count as usize;
305 let mut offset = crlf_pos + 2;
306 let mut items = Vec::with_capacity(count);
307
308 for _ in 0..count {
309 match parse_value(&buf[offset..])? {
310 Some((value, consumed)) => {
311 items.push(value);
312 offset += consumed;
313 }
314 None => return Ok(None), // Need more data.
315 }
316 }
317
318 Ok(Some((RespValue::Array(Some(items)), offset)))
319}
320
321/// Parse an inline command (plain text) into a RESP array of bulk strings.
322fn parse_inline_command(line: &[u8]) -> RespValue {

Callers 1

parse_valueFunction · 0.70

Calls 4

find_crlfFunction · 0.85
parse_valueFunction · 0.70
parseMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected