aboutsummaryrefslogblamecommitdiff
path: root/src/util.rs
blob: f09a3bc884f79be3d1c6665971978ab200a916d4 (plain) (tree)
1
2
3
4
5
6
7

                     




                                                                                 










                                                                                    
use serde::Serialize;

/// Utility function: encodes any serializable value in MessagePack binary format
/// using the RMP library.
///
/// Field names and variant names are included in the serialization.
/// This is used internally by the netapp communication protocol.
pub fn rmp_to_vec_all_named<T>(val: &T) -> Result<Vec<u8>, rmp_serde::encode::Error>
where
	T: Serialize + ?Sized,
{
	let mut wr = Vec::with_capacity(128);
	let mut se = rmp_serde::Serializer::new(&mut wr)
		.with_struct_map()
		.with_string_variants();
	val.serialize(&mut se)?;
	Ok(wr)
}