Extract a field value as string from a msgpack map row. Handles "collection.field" suffix matching.
(row: &[u8], field: &str)
| 100 | /// Extract a field value as string from a msgpack map row. |
| 101 | /// Handles "collection.field" suffix matching. |
| 102 | fn 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. |
| 126 | fn extract_number(row: &[u8], field: &str) -> Option<f64> { |
no test coverage detected