Skip to content

Commit

Permalink
Ensure latest version from VersionMap contains...
Browse files Browse the repository at this point in the history
...all structures at their current versions.

Signed-off-by: Ioana Chirca <[email protected]>
  • Loading branch information
ioanachirca committed Jun 18, 2020
1 parent f74d248 commit b4e199a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "versionize_derive"
version = "0.1.1"
version = "0.1.2"
license = "Apache-2.0"
authors = ["Amazon Firecracker team <[email protected]>"]
description = "Implements the Versionize derive proc macro."
Expand Down
4 changes: 4 additions & 0 deletions src/descriptors/struct_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ impl Descriptor for StructDescriptor {

// Generate code to map the app version to struct version and wrap the
// deserializers with the `version` match.
let current_version = self.version();
quote! {
let version = version_map.get_type_version(app_version, <Self as Versionize>::type_id());
if app_version == version_map.latest_version() && version != #current_version {
return Err(VersionizeError::VersionMapNotUpdated);
}
match version {
#versioned_deserializers
_ => panic!("Unknown {:?} version {}.", <Self as Versionize>::type_id(), version)
Expand Down
4 changes: 4 additions & 0 deletions src/descriptors/union_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ impl Descriptor for UnionDescriptor {
});
}

let current_version = self.version();
quote! {
let version = version_map.get_type_version(app_version, Self::type_id());
if app_version == version_map.latest_version() && version != #current_version {
return Err(VersionizeError::VersionMapNotUpdated);
}
match version {
#versioned_deserializers
_ => panic!("Unknown {:?} version {}.", Self::type_id(), version)
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ pub fn impl_versionize(input: TokenStream) -> proc_macro::TokenStream {
let version = descriptor.version();
let versioned_serializer = descriptor.generate_serializer();
let deserializer = descriptor.generate_deserializer();
let current_version = version;
let serializer = quote! {
// Get the struct version for the input app_version.
let version = version_map.get_type_version(app_version, <Self as Versionize>::type_id());
if app_version == version_map.latest_version() && version != #current_version {
return Err(VersionizeError::VersionMapNotUpdated);
}
// We will use this copy to perform semantic serialization.
let mut copy_of_self = self.clone();
match version {
Expand Down

0 comments on commit b4e199a

Please sign in to comment.