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

Function encode_value_vec

nodedb/src/data/executor/response_codec/encode.rs:56–77  ·  view source on GitHub ↗

Encode a slice of `nodedb_types::Value` as a msgpack array. No JSON intermediary — values are serialized directly to standard msgpack.

(
    values: &[nodedb_types::Value],
)

Source from the content-addressed store, hash-verified

54///
55/// No JSON intermediary — values are serialized directly to standard msgpack.
56pub(in crate::data::executor) fn encode_value_vec(
57 values: &[nodedb_types::Value],
58) -> crate::Result<Vec<u8>> {
59 let mut buf = Vec::with_capacity(values.len() * 64);
60 let n = values.len();
61 if n <= 15 {
62 buf.push(0x90 | n as u8);
63 } else if n <= 0xFFFF {
64 buf.push(0xDC);
65 buf.extend_from_slice(&(n as u16).to_be_bytes());
66 } else {
67 buf.push(0xDD);
68 buf.extend_from_slice(&(n as u32).to_be_bytes());
69 }
70 for val in values {
71 let encoded = nodedb_types::value_to_msgpack(val).map_err(|e| crate::Error::Codec {
72 detail: format!("value serialization: {e}"),
73 })?;
74 buf.extend_from_slice(&encoded);
75 }
76 Ok(buf)
77}
78
79/// Encode a simple `{"key": count}` response (for insert confirmations).
80pub(in crate::data::executor) fn encode_count(key: &str, count: usize) -> crate::Result<Vec<u8>> {

Callers 2

execute_spatial_scanMethod · 0.85
spatial_full_scanMethod · 0.85

Calls 3

value_to_msgpackFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected