Decode a MessagePack-encoded array into a `Vec `.
(bytes: &[u8])
| 84 | |
| 85 | /// Decode a MessagePack-encoded array into a `Vec<MpValue>`. |
| 86 | fn 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. |
| 104 | fn encode_msgpack_array(rows: &[MpValue]) -> Result<Vec<u8>, rmpv::encode::Error> { |