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

Function extract_path

nodedb-query/src/msgpack_scan/field.rs:57–73  ·  view source on GitHub ↗

Extract a value at a nested path (e.g., `["address", "city"]`). Each segment must be a string key in a nested map.

(buf: &[u8], offset: usize, path: &[&str])

Source from the content-addressed store, hash-verified

55/// Extract a value at a nested path (e.g., `["address", "city"]`).
56/// Each segment must be a string key in a nested map.
57pub fn extract_path(buf: &[u8], offset: usize, path: &[&str]) -> Option<FieldRange> {
58 if path.is_empty() {
59 return None;
60 }
61
62 let mut current_offset = offset;
63 for (i, segment) in path.iter().enumerate() {
64 let (value_start, value_end) = extract_field(buf, current_offset, segment)?;
65 if i == path.len() - 1 {
66 return Some((value_start, value_end));
67 }
68 // Intermediate segments must be maps — descend into the value
69 current_offset = value_start;
70 }
71
72 None
73}
74
75/// Extract a value using a dot-separated path string (e.g., `"address.city"`).
76/// Convenience wrapper over `extract_path`.

Callers 4

extract_dot_pathFunction · 0.85
extract_nested_pathFunction · 0.85
fuzz_truncated_buffersFunction · 0.85
fuzz_random_payloadsFunction · 0.85

Calls 4

extract_fieldFunction · 0.85
is_emptyMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by 3

extract_nested_pathFunction · 0.68
fuzz_truncated_buffersFunction · 0.68
fuzz_random_payloadsFunction · 0.68