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

Function write_prefixed_entries

nodedb/src/data/executor/handlers/join/mod.rs:68–114  ·  view source on GitHub ↗

Iterate msgpack map entries and write each key prefixed with `prefix.` and its value bytes verbatim.

(buf: &mut Vec<u8>, bytes: &[u8], prefix: &str)

Source from the content-addressed store, hash-verified

66/// Iterate msgpack map entries and write each key prefixed with `prefix.`
67/// and its value bytes verbatim.
68fn write_prefixed_entries(buf: &mut Vec<u8>, bytes: &[u8], prefix: &str) {
69 let Some((count, mut pos)) = msgpack_scan::map_header(bytes, 0) else {
70 return;
71 };
72 for _ in 0..count {
73 // Read key string.
74 let key = msgpack_scan::read_str(bytes, pos);
75 pos = match msgpack_scan::skip_value(bytes, pos) {
76 Some(p) => p,
77 None => return,
78 };
79 // Copy value bytes verbatim.
80 let value_start = pos;
81 let value_end = match msgpack_scan::skip_value(bytes, pos) {
82 Some(p) => p,
83 None => return,
84 };
85
86 // Write prefixed key.
87 if let Some(k) = key {
88 if prefix.is_empty() {
89 write_str(buf, k);
90 } else {
91 // Avoid allocation: write prefix.key directly.
92 let prefixed_len = prefix.len() + 1 + k.len();
93 if prefixed_len < 32 {
94 buf.push(0xA0 | prefixed_len as u8);
95 } else if prefixed_len <= u8::MAX as usize {
96 buf.push(0xD9);
97 buf.push(prefixed_len as u8);
98 } else if prefixed_len <= u16::MAX as usize {
99 buf.push(0xDA);
100 buf.extend_from_slice(&(prefixed_len as u16).to_be_bytes());
101 } else {
102 buf.push(0xDB);
103 buf.extend_from_slice(&(prefixed_len as u32).to_be_bytes());
104 }
105 buf.extend_from_slice(prefix.as_bytes());
106 buf.push(b'.');
107 buf.extend_from_slice(k.as_bytes());
108 }
109 }
110 // Write value bytes verbatim — zero decode.
111 buf.extend_from_slice(&bytes[value_start..value_end]);
112 pos = value_end;
113 }
114}
115
116/// Compare two documents using pre-extracted key byte ranges.
117/// `a_ranges`/`b_ranges` are `(start, end)` byte slices into the respective docs.

Callers 1

merge_join_docs_binaryFunction · 0.85

Calls 8

map_headerFunction · 0.85
skip_valueFunction · 0.85
read_strFunction · 0.50
write_strFunction · 0.50
is_emptyMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected