Append a single field's value to the key buffer as a JSON literal.
(buf: &mut String, doc: &[u8], field: &str)
| 52 | |
| 53 | /// Append a single field's value to the key buffer as a JSON literal. |
| 54 | fn append_field_value(buf: &mut String, doc: &[u8], field: &str) { |
| 55 | let Some((start, end)) = extract_field(doc, 0, field) else { |
| 56 | buf.push_str("null"); |
| 57 | return; |
| 58 | }; |
| 59 | |
| 60 | if read_null(doc, start) { |
| 61 | buf.push_str("null"); |
| 62 | } else if let Some(s) = read_str(doc, start) { |
| 63 | buf.push('"'); |
| 64 | buf.push_str(s); |
| 65 | buf.push('"'); |
| 66 | } else if let Some(n) = read_i64(doc, start) { |
| 67 | use std::fmt::Write; |
| 68 | let _ = write!(buf, "{n}"); |
| 69 | } else if let Some(n) = read_f64(doc, start) { |
| 70 | use std::fmt::Write; |
| 71 | let _ = write!(buf, "{n}"); |
| 72 | } else { |
| 73 | // Complex value (array/map/bin) — hex-encode raw bytes as key. |
| 74 | let bytes = &doc[start..end]; |
| 75 | for b in bytes { |
| 76 | use std::fmt::Write; |
| 77 | let _ = write!(buf, "{b:02x}"); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /// Append a field value from a pre-resolved range. |
| 83 | fn append_field_value_range(buf: &mut String, doc: &[u8], range: Option<(usize, usize)>) { |
no test coverage detected