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

Method parse

nodedb/src/control/server/resp/command.rs:20–40  ·  view source on GitHub ↗

Parse a RESP value (expected to be an array of bulk strings) into a command. Returns `None` if the value is not a valid command (empty array, non-array, etc.).

(value: &RespValue)

Source from the content-addressed store, hash-verified

18 ///
19 /// Returns `None` if the value is not a valid command (empty array, non-array, etc.).
20 pub fn parse(value: &RespValue) -> Option<Self> {
21 let items = match value {
22 RespValue::Array(Some(items)) if !items.is_empty() => items,
23 _ => return None,
24 };
25
26 let name = match &items[0] {
27 RespValue::BulkString(Some(data)) => String::from_utf8_lossy(data).to_uppercase(),
28 _ => return None,
29 };
30
31 let args: Vec<Vec<u8>> = items[1..]
32 .iter()
33 .filter_map(|item| match item {
34 RespValue::BulkString(Some(data)) => Some(data.clone()),
35 _ => None,
36 })
37 .collect();
38
39 Some(Self { name, args })
40 }
41
42 /// Get argument at index as bytes. Returns None if out of bounds.
43 pub fn arg(&self, index: usize) -> Option<&[u8]> {

Callers 15

extract_numberFunction · 0.45
arg_i64Method · 0.45
handle_incrbyfloatFunction · 0.45
parse_integerFunction · 0.45
parse_bulk_stringFunction · 0.45
parse_arrayFunction · 0.45
handle_zaddFunction · 0.45
parse_roleFunction · 0.45
parse_valueFunction · 0.45
transaction_lifecycleFunction · 0.45

Calls 4

collectMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45