Skip to content

Commit ad9f21c

Browse files
VictorKoendersppamorim
authored andcommitted
Made the compatibility check also include bincode 2 serde, and added comments (bincode-org#501)
* Made the compatibility check also include bincode 2 serde, and added comments * Added a CI step to run the compatibility tests
1 parent 874f43c commit ad9f21c

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

.github/workflows/rust.yml

+27
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,33 @@ fi",
158158
}
159159
]
160160
},
161+
"compatibility": {
162+
"name": "Compatibility",
163+
"runs-on": "ubuntu-latest",
164+
"steps": [
165+
{
166+
"uses": "actions/checkout@v2",
167+
"name": "Checkout"
168+
},
169+
{
170+
"uses": "actions-rs/toolchain@v1",
171+
"with": {
172+
"profile": "minimal",
173+
"toolchain": "stable",
174+
"override": true,
175+
},
176+
"name": "Install Rust stable"
177+
},
178+
{
179+
"uses": "actions-rs/cargo@v1",
180+
"with": {
181+
"command": "test",
182+
"args": "--manifest-path compatibility/Cargo.toml"
183+
},
184+
"name": "Run compatibility tests"
185+
}
186+
]
187+
},
161188
"coverage": {
162189
"name": "Code Coverage",
163190
"runs-on": "ubuntu-latest",

compatibility/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
bincode_2 = { path = "..", package = "bincode" }
9+
bincode_2 = { path = "..", package = "bincode", features = ["serde"] }
1010
bincode_1 = { version = "1", package = "bincode" }
1111
serde = { version = "1", features = ["derive"] }
1212
rand = "0.8"

compatibility/src/lib.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,33 @@ where
1818
C: bincode_2::config::Config,
1919
O: bincode_1::Options + Copy,
2020
{
21-
let bincode_1_output = bincode_1_options.serialize(t).unwrap();
21+
// This is what bincode 1 serializes to. This will be our comparison value.
22+
let encoded = bincode_1_options.serialize(t).unwrap();
23+
24+
// Test bincode 2 encode
2225
let bincode_2_output = bincode_2::encode_to_vec(t, bincode_2_config).unwrap();
26+
assert_eq!(encoded, bincode_2_output, "{:?} serializes differently", t);
2327

28+
// Test bincode 2 serde serialize
29+
let bincode_2_serde_output = bincode_2::serde::encode_to_vec(t, bincode_2_config).unwrap();
2430
assert_eq!(
25-
bincode_1_output, bincode_2_output,
31+
encoded, bincode_2_serde_output,
2632
"{:?} serializes differently",
2733
t
2834
);
2935

30-
let decoded: T = bincode_1_options.deserialize(&bincode_1_output).unwrap();
31-
assert_eq!(&decoded, t);
32-
let decoded: T = bincode_1_options.deserialize(&bincode_2_output).unwrap();
36+
// Test bincode 1 deserialize
37+
let decoded: T = bincode_1_options.deserialize(&encoded).unwrap();
3338
assert_eq!(&decoded, t);
3439

35-
let decoded: T = bincode_2::decode_from_slice(&bincode_1_output, bincode_2_config)
40+
// Test bincode 2 decode
41+
let decoded: T = bincode_2::decode_from_slice(&encoded, bincode_2_config)
3642
.unwrap()
3743
.0;
3844
assert_eq!(&decoded, t);
39-
let decoded: T = bincode_2::decode_from_slice(&bincode_2_output, bincode_2_config)
45+
46+
// Test bincode 2 serde deserialize
47+
let decoded: T = bincode_2::serde::decode_from_slice(&encoded, bincode_2_config)
4048
.unwrap()
4149
.0;
4250
assert_eq!(&decoded, t);

0 commit comments

Comments
 (0)