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

Function parse_bulk_string

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

Source from the content-addressed store, hash-verified

257}
258
259fn parse_bulk_string(buf: &[u8]) -> io::Result<Option<(RespValue, usize)>> {
260 let crlf_pos = match find_crlf(buf) {
261 Some(p) => p,
262 None => return Ok(None),
263 };
264
265 let len_str = std::str::from_utf8(&buf[..crlf_pos])
266 .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
267 let len: i64 = len_str
268 .parse()
269 .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
270
271 if len < 0 {
272 return Ok(Some((RespValue::nil(), crlf_pos + 2)));
273 }
274
275 let len = len as usize;
276 let data_start = crlf_pos + 2;
277 let data_end = data_start + len;
278 let frame_end = data_end + 2; // trailing \r\n
279
280 if buf.len() < frame_end {
281 return Ok(None); // Need more data.
282 }
283
284 let data = buf[data_start..data_end].to_vec();
285 Ok(Some((RespValue::BulkString(Some(data)), frame_end)))
286}
287
288fn parse_array(buf: &[u8]) -> io::Result<Option<(RespValue, usize)>> {
289 let crlf_pos = match find_crlf(buf) {

Callers 1

parse_valueFunction · 0.85

Calls 4

find_crlfFunction · 0.85
parseMethod · 0.45
lenMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected