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

Function extract_field_str

nodedb/src/control/server/post_aggregate.rs:102–123  ·  view source on GitHub ↗

Extract a field value as string from a msgpack map row. Handles "collection.field" suffix matching.

(row: &[u8], field: &str)

Source from the content-addressed store, hash-verified

100/// Extract a field value as string from a msgpack map row.
101/// Handles "collection.field" suffix matching.
102fn extract_field_str(row: &[u8], field: &str) -> Option<String> {
103 use nodedb_query::msgpack_scan::reader;
104
105 // Try exact match first.
106 if let Some((start, end)) = nodedb_query::msgpack_scan::extract_field(row, 0, field) {
107 return Some(read_value_as_string(row, start, end));
108 }
109
110 // Suffix match: iterate map keys looking for "*.{field}".
111 let suffix = format!(".{field}");
112 let (count, mut pos) = reader::map_header(row, 0)?;
113 for _ in 0..count {
114 let key = reader::read_str(row, pos)?;
115 let key_end = reader::skip_value(row, pos)?;
116 let val_end = reader::skip_value(row, key_end)?;
117 if key.ends_with(&suffix) {
118 return Some(read_value_as_string(row, key_end, val_end));
119 }
120 pos = val_end;
121 }
122 None
123}
124
125/// Extract a numeric field value from a msgpack map row.
126fn extract_number(row: &[u8], field: &str) -> Option<f64> {

Callers 1

apply_post_aggregationFunction · 0.85

Calls 5

extract_fieldFunction · 0.85
read_value_as_stringFunction · 0.85
map_headerFunction · 0.85
skip_valueFunction · 0.85
read_strFunction · 0.50

Tested by

no test coverage detected