Skip to content

Commit b4e199a

Browse files
committed
Ensure latest version from VersionMap contains...
...all structures at their current versions. Signed-off-by: Ioana Chirca <[email protected]>
1 parent f74d248 commit b4e199a

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "versionize_derive"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
license = "Apache-2.0"
55
authors = ["Amazon Firecracker team <[email protected]>"]
66
description = "Implements the Versionize derive proc macro."

src/descriptors/struct_desc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ impl Descriptor for StructDescriptor {
7171

7272
// Generate code to map the app version to struct version and wrap the
7373
// deserializers with the `version` match.
74+
let current_version = self.version();
7475
quote! {
7576
let version = version_map.get_type_version(app_version, <Self as Versionize>::type_id());
77+
if app_version == version_map.latest_version() && version != #current_version {
78+
return Err(VersionizeError::VersionMapNotUpdated);
79+
}
7680
match version {
7781
#versioned_deserializers
7882
_ => panic!("Unknown {:?} version {}.", <Self as Versionize>::type_id(), version)

src/descriptors/union_desc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ impl Descriptor for UnionDescriptor {
4040
});
4141
}
4242

43+
let current_version = self.version();
4344
quote! {
4445
let version = version_map.get_type_version(app_version, Self::type_id());
46+
if app_version == version_map.latest_version() && version != #current_version {
47+
return Err(VersionizeError::VersionMapNotUpdated);
48+
}
4549
match version {
4650
#versioned_deserializers
4751
_ => panic!("Unknown {:?} version {}.", Self::type_id(), version)

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ pub fn impl_versionize(input: TokenStream) -> proc_macro::TokenStream {
5050
let version = descriptor.version();
5151
let versioned_serializer = descriptor.generate_serializer();
5252
let deserializer = descriptor.generate_deserializer();
53+
let current_version = version;
5354
let serializer = quote! {
5455
// Get the struct version for the input app_version.
5556
let version = version_map.get_type_version(app_version, <Self as Versionize>::type_id());
57+
if app_version == version_map.latest_version() && version != #current_version {
58+
return Err(VersionizeError::VersionMapNotUpdated);
59+
}
5660
// We will use this copy to perform semantic serialization.
5761
let mut copy_of_self = self.clone();
5862
match version {

0 commit comments

Comments
 (0)