mirror of https://git.sr.ht/~stygianentity/bincode
Add an optional context for decoding allowing additional data to be passed to decoded structs. --------- Co-authored-by: branchseer <dk4rest@gmail.com> |
||
|---|---|---|
| .. | ||
| src | ||
| Cargo.toml | ||
| README.md | ||
README.md
Bincode compatibility test
Hello! We are working on releasing bincode 2, and we want to make sure that bincode 2 produces the same output as bincode 1.3.
For this, we need your help. Please read on if you're using bincode in one of your projects.
We have created a test project that can be used to test the compatibility between bincode 1 and 2. It encodes structs with a wide range of settings, checks if the outputs are the same, and then deserializes the struct and checks if the output is the same.
Adding a test case for your project
To add a test case for your project, please follow the following steps:
- Fork https://github.com/bincode-org/bincode
- create a new file
compatibility/src/<name>.rs. - Add a link to your project
- Add
Licence: MIT OR Apache-2.0if you agree to distribute your code under this license - Add a
mod <name>;in thelib.rs. Make sure it's alphabetically ordered (check the ordering in your file system). - Add your structs.
- Adding references to libraries is not recommended. Libraries will not be implementing
bincode 2's encoding/decoding system. - If you need references to libraries, consider adding a test case for that library, and then referencing that test.
- Adding references to libraries is not recommended. Libraries will not be implementing
- Make sure structs derive the following traits:
serde::Serializeandserde::Deserialize, like normalbincode_2::Encodeandbincode_2::Decode, for the bincode 2 encode/decode mechanic- Because the crate is renamed to
bincode_2, you also need to add#[bincode(crate = "bincode_2")] Debug, PartialEq
#[derive(Serialize, Deserialize, bincode_2::Encode, bincode_2::Decode, Debug, PartialEq)]
#[bincode(crate = "bincode_2")]
pub struct YourStruct {
}
- Use
randto be able to generate a random test case for your project.- For strings there is a helper function in
crate:gen_string(rng: &mut impl Rng) -> String
- For strings there is a helper function in
- Add the following code:
#[test]
pub fn test() {
let mut rng = rand::thread_rng();
for _ in 0..1000 {
crate::test_same(<your_rand_function>(&mut rng));
}
}
For examples, see the existing cases in compatibility/src/.
- Open a pull request with the title
Bincode 1 compatibility: <name of your project>