[TieredStorage] AccountMetaOptionalFields::size_from_flags() (#32242)
#### Summary of Changes This PR adds AccountMetaOptionalFields::size_from_flags that takes `&AccountMegaFlags` and returns the size of the AccountMetaOptionalFields based on the input AccountMegaFlags. This function is needed because the reader of the TieredAccountMeta directly extract all the Some fields of AccountMetaOptionalFields from its account block without constructing the AccountMetaOptionalFields instance. #### Test plan Improve existing unit tests that further verify the correctness of the function.
This commit is contained in:
parent
1c618f2479
commit
d95e976a71
|
@ -103,6 +103,23 @@ impl AccountMetaOptionalFields {
|
||||||
.write_version
|
.write_version
|
||||||
.map_or(0, |_| std::mem::size_of::<StoredMetaWriteVersion>())
|
.map_or(0, |_| std::mem::size_of::<StoredMetaWriteVersion>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Given the specified AccountMetaFlags, returns the size of its
|
||||||
|
/// associated AccountMetaOptionalFields.
|
||||||
|
pub fn size_from_flags(flags: &AccountMetaFlags) -> usize {
|
||||||
|
let mut fields_size = 0;
|
||||||
|
if flags.has_rent_epoch() {
|
||||||
|
fields_size += std::mem::size_of::<Epoch>();
|
||||||
|
}
|
||||||
|
if flags.has_account_hash() {
|
||||||
|
fields_size += std::mem::size_of::<Hash>();
|
||||||
|
}
|
||||||
|
if flags.has_write_version() {
|
||||||
|
fields_size += std::mem::size_of::<StoredMetaWriteVersion>();
|
||||||
|
}
|
||||||
|
|
||||||
|
fields_size
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -206,6 +223,12 @@ pub mod tests {
|
||||||
+ write_version
|
+ write_version
|
||||||
.map_or(0, |_| std::mem::size_of::<StoredMetaWriteVersion>())
|
.map_or(0, |_| std::mem::size_of::<StoredMetaWriteVersion>())
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
opt_fields.size(),
|
||||||
|
AccountMetaOptionalFields::size_from_flags(&AccountMetaFlags::new_from(
|
||||||
|
&opt_fields
|
||||||
|
))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue