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

Function append_field_value

nodedb-query/src/msgpack_scan/group_key.rs:54–80  ·  view source on GitHub ↗

Append a single field's value to the key buffer as a JSON literal.

(buf: &mut String, doc: &[u8], field: &str)

Source from the content-addressed store, hash-verified

52
53/// Append a single field's value to the key buffer as a JSON literal.
54fn 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.
83fn append_field_value_range(buf: &mut String, doc: &[u8], range: Option<(usize, usize)>) {

Callers 1

build_group_keyFunction · 0.85

Calls 6

extract_fieldFunction · 0.85
read_nullFunction · 0.85
read_i64Function · 0.85
read_strFunction · 0.70
read_f64Function · 0.70
pushMethod · 0.45

Tested by

no test coverage detected