aboutsummaryrefslogtreecommitdiff
path: root/src/data.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-09 18:43:53 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-09 18:43:53 +0200
commit1d786c2c663ac6f6e3e3ef52accd6e9eca049988 (patch)
tree813720a682fe7cf4947129020d73ccf4797d0c3a /src/data.rs
parent101444abb3967770ec378ee09f24eb2845dc091d (diff)
downloadgarage-1d786c2c663ac6f6e3e3ef52accd6e9eca049988.tar.gz
garage-1d786c2c663ac6f6e3e3ef52accd6e9eca049988.zip
Something works
Diffstat (limited to 'src/data.rs')
-rw-r--r--src/data.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/data.rs b/src/data.rs
index 14846fe2..91b21b02 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -93,6 +93,20 @@ pub fn now_msec() -> u64 {
.as_millis() as u64
}
+// RMP serialization with names of fields and variants
+
+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)
+
+}
+
// Network management
#[derive(Clone, Debug, Serialize, Deserialize)]