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

Function decode_msgpack_array

nodedb/src/control/gateway/fuser.rs:86–101  ·  view source on GitHub ↗

Decode a MessagePack-encoded array into a `Vec `.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

84
85/// Decode a MessagePack-encoded array into a `Vec<MpValue>`.
86fn decode_msgpack_array(bytes: &[u8]) -> Result<Vec<MpValue>, Error> {
87 if bytes.is_empty() {
88 return Ok(Vec::new());
89 }
90 let mut cursor = std::io::Cursor::new(bytes);
91 let value: MpValue =
92 rmpv::decode::read_value(&mut cursor).map_err(|e| Error::Serialization {
93 format: "msgpack".into(),
94 detail: format!("fuser: decode failed: {e}"),
95 })?;
96 match value {
97 MpValue::Array(rows) => Ok(rows),
98 // A single non-array value is treated as a 1-element array.
99 other => Ok(vec![other]),
100 }
101}
102
103/// Re-encode a `Vec<MpValue>` as a MessagePack array.
104fn encode_msgpack_array(rows: &[MpValue]) -> Result<Vec<u8>, rmpv::encode::Error> {

Callers 3

fuse_payloadsFunction · 0.85
fuse_two_arraysFunction · 0.85

Calls 2

read_valueFunction · 0.50
is_emptyMethod · 0.45

Tested by 2

fuse_two_arraysFunction · 0.68