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])
| 55 | /// Extract a value at a nested path (e.g., `["address", "city"]`). |
| 56 | /// Each segment must be a string key in a nested map. |
| 57 | pub 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`. |