From 2c7ed27f0ecf89cdf2883586ad40dde1f216df6e Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Sat, 7 Sep 2019 12:32:24 +0200 Subject: [PATCH] Add packed serialized test for struct See issue #144 --- tests/value.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/value.rs b/tests/value.rs index 6714069a..404a7ea7 100644 --- a/tests/value.rs +++ b/tests/value.rs @@ -80,4 +80,21 @@ mod std_tests { assert_eq!(value, data_de_value); } + + #[derive(Debug, Deserialize, Serialize)] + struct SmallStruct { + spam: u32, + eggs: u32, + } + + #[test] + fn small_struct() { + // Test whether the packed format works. + // Field names should not be serialized, + // instead field indizes are serialized. + let value = SmallStruct { spam: 17, eggs: 42 }; + let data = serde_cbor::ser::to_vec_packed(&value).unwrap(); + let reference = b"\xa2\x00\x11\x01\x18\x2a"; + assert_eq!(data, reference); + } }