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

Function write_str

nodedb-query/src/msgpack_scan/writer.rs:40–56  ·  view source on GitHub ↗
(buf: &mut Vec<u8>, s: &str)

Source from the content-addressed store, hash-verified

38/// Write a msgpack string (header + UTF-8 bytes).
39#[inline]
40pub fn write_str(buf: &mut Vec<u8>, s: &str) {
41 let bytes = s.as_bytes();
42 let len = bytes.len();
43 if len < 32 {
44 buf.push(0xA0 | len as u8);
45 } else if len <= u8::MAX as usize {
46 buf.push(0xD9);
47 buf.push(len as u8);
48 } else if len <= u16::MAX as usize {
49 buf.push(0xDA);
50 buf.extend_from_slice(&(len as u16).to_be_bytes());
51 } else {
52 buf.push(0xDB);
53 buf.extend_from_slice(&(len as u32).to_be_bytes());
54 }
55 buf.extend_from_slice(bytes);
56}
57
58/// Write a msgpack integer using the most compact encoding.
59#[inline]

Callers 9

write_kv_strFunction · 0.70
write_kv_i64Function · 0.70
write_kv_f64Function · 0.70
write_kv_boolFunction · 0.70
write_kv_rawFunction · 0.70
write_kv_nullFunction · 0.70
inject_str_fieldFunction · 0.70
merge_fieldsFunction · 0.70

Calls 3

as_bytesMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by 1