From 2da84857a5376c2f5b07ce565605064590defba3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 27 Apr 2022 16:35:55 +0100 Subject: [PATCH] CfgPath: Test serialisation round-trip with a binary format Use MessagePack. Signed-off-by: Ian Jackson --- Cargo.lock | 29 +++++++++++++++++++++++++++++ crates/tor-config/Cargo.toml | 1 + crates/tor-config/src/path.rs | 8 ++++++++ 3 files changed, 38 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8ec1f6b65..31d0b0cad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2162,6 +2162,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "paste" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" + [[package]] name = "pathdiff" version = "0.2.1" @@ -2536,6 +2542,28 @@ dependencies = [ "libc", ] +[[package]] +name = "rmp" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25786b0d276110195fa3d6f3f31299900cf71dfbd6c28450f3f58a0e7f7a347e" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + [[package]] name = "rsa" version = "0.5.0" @@ -3296,6 +3324,7 @@ dependencies = [ "directories", "dirs", "once_cell", + "rmp-serde", "serde", "serde_json", "shellexpand-fork", diff --git a/crates/tor-config/Cargo.toml b/crates/tor-config/Cargo.toml index 7951437ba..2dcbd3121 100644 --- a/crates/tor-config/Cargo.toml +++ b/crates/tor-config/Cargo.toml @@ -30,6 +30,7 @@ directories = { version = "4", optional = true } [dev-dependencies] config = { version = "0.12.0", default-features = false, features = ["toml"] } dirs = "4.0.0" +rmp-serde = "1" serde_json = "1.0.50" toml = "0.5" tracing-test = "0.2" diff --git a/crates/tor-config/src/path.rs b/crates/tor-config/src/path.rs index 1012895a7..3a4a9c465 100644 --- a/crates/tor-config/src/path.rs +++ b/crates/tor-config/src/path.rs @@ -420,4 +420,12 @@ mod test_serde { fn roundtrip_toml() { test_roundtrip_cases(|input| toml::to_string(&input), |toml| toml::from_str(toml)); } + + #[test] + fn roundtrip_mpack() { + test_roundtrip_cases( + |input| rmp_serde::to_vec(&input), + |mpack| rmp_serde::from_slice(mpack), + ); + } }