Merge "aconfig: syntax update, as_bytes to into_bytes to be more appropriate" into main
This commit is contained in:
commit
88899887c0
13 changed files with 69 additions and 69 deletions
|
@ -95,10 +95,10 @@ pub fn create_flag_table(container: &str, packages: &[FlagPackage]) -> Result<Fl
|
|||
.concat();
|
||||
|
||||
// initialize all header fields
|
||||
header.bucket_offset = header.as_bytes().len() as u32;
|
||||
header.bucket_offset = header.into_bytes().len() as u32;
|
||||
header.node_offset = header.bucket_offset + num_buckets * 4;
|
||||
header.file_size = header.node_offset
|
||||
+ node_wrappers.iter().map(|x| x.node.as_bytes().len()).sum::<usize>() as u32;
|
||||
+ node_wrappers.iter().map(|x| x.node.into_bytes().len()).sum::<usize>() as u32;
|
||||
|
||||
// sort nodes by bucket index for efficiency
|
||||
node_wrappers.sort_by(|a, b| a.bucket_index.cmp(&b.bucket_index));
|
||||
|
@ -116,7 +116,7 @@ pub fn create_flag_table(container: &str, packages: &[FlagPackage]) -> Result<Fl
|
|||
if buckets[node_bucket_idx as usize].is_none() {
|
||||
buckets[node_bucket_idx as usize] = Some(offset);
|
||||
}
|
||||
offset += node_wrappers[i].node.as_bytes().len() as u32;
|
||||
offset += node_wrappers[i].node.into_bytes().len() as u32;
|
||||
|
||||
if let Some(index) = next_node_bucket_idx {
|
||||
if index == node_bucket_idx {
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn create_flag_value(container: &str, packages: &[FlagPackage]) -> Result<Fl
|
|||
}
|
||||
|
||||
// initialize all header fields
|
||||
list.header.boolean_value_offset = list.header.as_bytes().len() as u32;
|
||||
list.header.boolean_value_offset = list.header.into_bytes().len() as u32;
|
||||
list.header.file_size = list.header.boolean_value_offset + num_flags;
|
||||
|
||||
Ok(list)
|
||||
|
|
|
@ -97,15 +97,15 @@ where
|
|||
match file {
|
||||
StorageFileType::PackageMap => {
|
||||
let package_table = create_package_table(container, &packages)?;
|
||||
Ok(package_table.as_bytes())
|
||||
Ok(package_table.into_bytes())
|
||||
}
|
||||
StorageFileType::FlagMap => {
|
||||
let flag_table = create_flag_table(container, &packages)?;
|
||||
Ok(flag_table.as_bytes())
|
||||
Ok(flag_table.into_bytes())
|
||||
}
|
||||
StorageFileType::FlagVal => {
|
||||
let flag_value = create_flag_value(container, &packages)?;
|
||||
Ok(flag_value.as_bytes())
|
||||
Ok(flag_value.into_bytes())
|
||||
}
|
||||
_ => Err(anyhow!("aconfig does not support the creation of this storage file type")),
|
||||
}
|
||||
|
|
|
@ -66,10 +66,10 @@ pub fn create_package_table(container: &str, packages: &[FlagPackage]) -> Result
|
|||
packages.iter().map(|pkg| PackageTableNodeWrapper::new(pkg, num_buckets)).collect();
|
||||
|
||||
// initialize all header fields
|
||||
header.bucket_offset = header.as_bytes().len() as u32;
|
||||
header.bucket_offset = header.into_bytes().len() as u32;
|
||||
header.node_offset = header.bucket_offset + num_buckets * 4;
|
||||
header.file_size = header.node_offset
|
||||
+ node_wrappers.iter().map(|x| x.node.as_bytes().len()).sum::<usize>() as u32;
|
||||
+ node_wrappers.iter().map(|x| x.node.into_bytes().len()).sum::<usize>() as u32;
|
||||
|
||||
// sort node_wrappers by bucket index for efficiency
|
||||
node_wrappers.sort_by(|a, b| a.bucket_index.cmp(&b.bucket_index));
|
||||
|
@ -87,7 +87,7 @@ pub fn create_package_table(container: &str, packages: &[FlagPackage]) -> Result
|
|||
if buckets[node_bucket_idx as usize].is_none() {
|
||||
buckets[node_bucket_idx as usize] = Some(offset);
|
||||
}
|
||||
offset += node_wrappers[i].node.as_bytes().len() as u32;
|
||||
offset += node_wrappers[i].node.into_bytes().len() as u32;
|
||||
|
||||
if let Some(index) = next_node_bucket_idx {
|
||||
if index == node_bucket_idx {
|
||||
|
|
|
@ -55,7 +55,7 @@ impl fmt::Debug for FlagInfoHeader {
|
|||
|
||||
impl FlagInfoHeader {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&self.version.to_le_bytes());
|
||||
let container_bytes = self.container.as_bytes();
|
||||
|
@ -118,7 +118,7 @@ impl fmt::Debug for FlagInfoNode {
|
|||
|
||||
impl FlagInfoNode {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&self.attributes.to_le_bytes());
|
||||
result
|
||||
|
@ -154,10 +154,10 @@ impl fmt::Debug for FlagInfoList {
|
|||
|
||||
impl FlagInfoList {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
[
|
||||
self.header.as_bytes(),
|
||||
self.nodes.iter().map(|v| v.as_bytes()).collect::<Vec<_>>().concat(),
|
||||
self.header.into_bytes(),
|
||||
self.nodes.iter().map(|v| v.into_bytes()).collect::<Vec<_>>().concat(),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
@ -166,11 +166,11 @@ impl FlagInfoList {
|
|||
pub fn from_bytes(bytes: &[u8]) -> Result<Self, AconfigStorageError> {
|
||||
let header = FlagInfoHeader::from_bytes(bytes)?;
|
||||
let num_flags = header.num_flags;
|
||||
let mut head = header.as_bytes().len();
|
||||
let mut head = header.into_bytes().len();
|
||||
let nodes = (0..num_flags)
|
||||
.map(|_| {
|
||||
let node = FlagInfoNode::from_bytes(&bytes[head..])?;
|
||||
head += node.as_bytes().len();
|
||||
head += node.into_bytes().len();
|
||||
Ok(node)
|
||||
})
|
||||
.collect::<Result<Vec<_>, AconfigStorageError>>()
|
||||
|
@ -196,17 +196,17 @@ mod tests {
|
|||
let flag_info_list = create_test_flag_info_list();
|
||||
|
||||
let header: &FlagInfoHeader = &flag_info_list.header;
|
||||
let reinterpreted_header = FlagInfoHeader::from_bytes(&header.as_bytes());
|
||||
let reinterpreted_header = FlagInfoHeader::from_bytes(&header.into_bytes());
|
||||
assert!(reinterpreted_header.is_ok());
|
||||
assert_eq!(header, &reinterpreted_header.unwrap());
|
||||
|
||||
let nodes: &Vec<FlagInfoNode> = &flag_info_list.nodes;
|
||||
for node in nodes.iter() {
|
||||
let reinterpreted_node = FlagInfoNode::from_bytes(&node.as_bytes()).unwrap();
|
||||
let reinterpreted_node = FlagInfoNode::from_bytes(&node.into_bytes()).unwrap();
|
||||
assert_eq!(node, &reinterpreted_node);
|
||||
}
|
||||
|
||||
let flag_info_bytes = flag_info_list.as_bytes();
|
||||
let flag_info_bytes = flag_info_list.into_bytes();
|
||||
let reinterpreted_info_list = FlagInfoList::from_bytes(&flag_info_bytes);
|
||||
assert!(reinterpreted_info_list.is_ok());
|
||||
assert_eq!(&flag_info_list, &reinterpreted_info_list.unwrap());
|
||||
|
@ -218,7 +218,7 @@ mod tests {
|
|||
// bytes
|
||||
fn test_version_number() {
|
||||
let flag_info_list = create_test_flag_info_list();
|
||||
let bytes = &flag_info_list.as_bytes();
|
||||
let bytes = &flag_info_list.into_bytes();
|
||||
let mut head = 0;
|
||||
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
|
||||
assert_eq!(version, 1234)
|
||||
|
@ -229,7 +229,7 @@ mod tests {
|
|||
fn test_file_type_check() {
|
||||
let mut flag_info_list = create_test_flag_info_list();
|
||||
flag_info_list.header.file_type = 123u8;
|
||||
let error = FlagInfoList::from_bytes(&flag_info_list.as_bytes()).unwrap_err();
|
||||
let error = FlagInfoList::from_bytes(&flag_info_list.into_bytes()).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
format!("BytesParseFail(binary file is not a flag info file)")
|
||||
|
|
|
@ -59,7 +59,7 @@ impl fmt::Debug for FlagTableHeader {
|
|||
|
||||
impl FlagTableHeader {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&self.version.to_le_bytes());
|
||||
let container_bytes = self.container.as_bytes();
|
||||
|
@ -118,7 +118,7 @@ impl fmt::Debug for FlagTableNode {
|
|||
|
||||
impl FlagTableNode {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&self.package_id.to_le_bytes());
|
||||
let name_bytes = self.flag_name.as_bytes();
|
||||
|
@ -178,11 +178,11 @@ impl fmt::Debug for FlagTable {
|
|||
/// Flag table struct
|
||||
impl FlagTable {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
[
|
||||
self.header.as_bytes(),
|
||||
self.header.into_bytes(),
|
||||
self.buckets.iter().map(|v| v.unwrap_or(0).to_le_bytes()).collect::<Vec<_>>().concat(),
|
||||
self.nodes.iter().map(|v| v.as_bytes()).collect::<Vec<_>>().concat(),
|
||||
self.nodes.iter().map(|v| v.into_bytes()).collect::<Vec<_>>().concat(),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ impl FlagTable {
|
|||
let header = FlagTableHeader::from_bytes(bytes)?;
|
||||
let num_flags = header.num_flags;
|
||||
let num_buckets = crate::get_table_size(num_flags)?;
|
||||
let mut head = header.as_bytes().len();
|
||||
let mut head = header.into_bytes().len();
|
||||
let buckets = (0..num_buckets)
|
||||
.map(|_| match read_u32_from_bytes(bytes, &mut head).unwrap() {
|
||||
0 => None,
|
||||
|
@ -202,7 +202,7 @@ impl FlagTable {
|
|||
let nodes = (0..num_flags)
|
||||
.map(|_| {
|
||||
let node = FlagTableNode::from_bytes(&bytes[head..])?;
|
||||
head += node.as_bytes().len();
|
||||
head += node.into_bytes().len();
|
||||
Ok(node)
|
||||
})
|
||||
.collect::<Result<Vec<_>, AconfigStorageError>>()
|
||||
|
@ -226,17 +226,17 @@ mod tests {
|
|||
let flag_table = create_test_flag_table();
|
||||
|
||||
let header: &FlagTableHeader = &flag_table.header;
|
||||
let reinterpreted_header = FlagTableHeader::from_bytes(&header.as_bytes());
|
||||
let reinterpreted_header = FlagTableHeader::from_bytes(&header.into_bytes());
|
||||
assert!(reinterpreted_header.is_ok());
|
||||
assert_eq!(header, &reinterpreted_header.unwrap());
|
||||
|
||||
let nodes: &Vec<FlagTableNode> = &flag_table.nodes;
|
||||
for node in nodes.iter() {
|
||||
let reinterpreted_node = FlagTableNode::from_bytes(&node.as_bytes()).unwrap();
|
||||
let reinterpreted_node = FlagTableNode::from_bytes(&node.into_bytes()).unwrap();
|
||||
assert_eq!(node, &reinterpreted_node);
|
||||
}
|
||||
|
||||
let flag_table_bytes = flag_table.as_bytes();
|
||||
let flag_table_bytes = flag_table.into_bytes();
|
||||
let reinterpreted_table = FlagTable::from_bytes(&flag_table_bytes);
|
||||
assert!(reinterpreted_table.is_ok());
|
||||
assert_eq!(&flag_table, &reinterpreted_table.unwrap());
|
||||
|
@ -248,7 +248,7 @@ mod tests {
|
|||
// bytes
|
||||
fn test_version_number() {
|
||||
let flag_table = create_test_flag_table();
|
||||
let bytes = &flag_table.as_bytes();
|
||||
let bytes = &flag_table.into_bytes();
|
||||
let mut head = 0;
|
||||
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
|
||||
assert_eq!(version, 1234)
|
||||
|
@ -259,7 +259,7 @@ mod tests {
|
|||
fn test_file_type_check() {
|
||||
let mut flag_table = create_test_flag_table();
|
||||
flag_table.header.file_type = 123u8;
|
||||
let error = FlagTable::from_bytes(&flag_table.as_bytes()).unwrap_err();
|
||||
let error = FlagTable::from_bytes(&flag_table.into_bytes()).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
format!("BytesParseFail(binary file is not a flag map)")
|
||||
|
|
|
@ -55,7 +55,7 @@ impl fmt::Debug for FlagValueHeader {
|
|||
|
||||
impl FlagValueHeader {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&self.version.to_le_bytes());
|
||||
let container_bytes = self.container.as_bytes();
|
||||
|
@ -108,9 +108,9 @@ impl fmt::Debug for FlagValueList {
|
|||
|
||||
impl FlagValueList {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
[
|
||||
self.header.as_bytes(),
|
||||
self.header.into_bytes(),
|
||||
self.booleans.iter().map(|&v| u8::from(v).to_le_bytes()).collect::<Vec<_>>().concat(),
|
||||
]
|
||||
.concat()
|
||||
|
@ -120,7 +120,7 @@ impl FlagValueList {
|
|||
pub fn from_bytes(bytes: &[u8]) -> Result<Self, AconfigStorageError> {
|
||||
let header = FlagValueHeader::from_bytes(bytes)?;
|
||||
let num_flags = header.num_flags;
|
||||
let mut head = header.as_bytes().len();
|
||||
let mut head = header.into_bytes().len();
|
||||
let booleans =
|
||||
(0..num_flags).map(|_| read_u8_from_bytes(bytes, &mut head).unwrap() == 1).collect();
|
||||
let list = Self { header, booleans };
|
||||
|
@ -139,11 +139,11 @@ mod tests {
|
|||
let flag_value_list = create_test_flag_value_list();
|
||||
|
||||
let header: &FlagValueHeader = &flag_value_list.header;
|
||||
let reinterpreted_header = FlagValueHeader::from_bytes(&header.as_bytes());
|
||||
let reinterpreted_header = FlagValueHeader::from_bytes(&header.into_bytes());
|
||||
assert!(reinterpreted_header.is_ok());
|
||||
assert_eq!(header, &reinterpreted_header.unwrap());
|
||||
|
||||
let flag_value_bytes = flag_value_list.as_bytes();
|
||||
let flag_value_bytes = flag_value_list.into_bytes();
|
||||
let reinterpreted_value_list = FlagValueList::from_bytes(&flag_value_bytes);
|
||||
assert!(reinterpreted_value_list.is_ok());
|
||||
assert_eq!(&flag_value_list, &reinterpreted_value_list.unwrap());
|
||||
|
@ -155,7 +155,7 @@ mod tests {
|
|||
// bytes
|
||||
fn test_version_number() {
|
||||
let flag_value_list = create_test_flag_value_list();
|
||||
let bytes = &flag_value_list.as_bytes();
|
||||
let bytes = &flag_value_list.into_bytes();
|
||||
let mut head = 0;
|
||||
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
|
||||
assert_eq!(version, 1234)
|
||||
|
@ -166,7 +166,7 @@ mod tests {
|
|||
fn test_file_type_check() {
|
||||
let mut flag_value_list = create_test_flag_value_list();
|
||||
flag_value_list.header.file_type = 123u8;
|
||||
let error = FlagValueList::from_bytes(&flag_value_list.as_bytes()).unwrap_err();
|
||||
let error = FlagValueList::from_bytes(&flag_value_list.into_bytes()).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
format!("BytesParseFail(binary file is not a flag value file)")
|
||||
|
|
|
@ -258,10 +258,10 @@ mod tests {
|
|||
// this test point locks down the flag list api
|
||||
fn test_list_flag() {
|
||||
let package_table =
|
||||
write_bytes_to_temp_file(&create_test_package_table().as_bytes()).unwrap();
|
||||
let flag_table = write_bytes_to_temp_file(&create_test_flag_table().as_bytes()).unwrap();
|
||||
write_bytes_to_temp_file(&create_test_package_table().into_bytes()).unwrap();
|
||||
let flag_table = write_bytes_to_temp_file(&create_test_flag_table().into_bytes()).unwrap();
|
||||
let flag_value_list =
|
||||
write_bytes_to_temp_file(&create_test_flag_value_list().as_bytes()).unwrap();
|
||||
write_bytes_to_temp_file(&create_test_flag_value_list().into_bytes()).unwrap();
|
||||
|
||||
let package_table_path = package_table.path().display().to_string();
|
||||
let flag_table_path = flag_table.path().display().to_string();
|
||||
|
|
|
@ -56,7 +56,7 @@ impl fmt::Debug for PackageTableHeader {
|
|||
|
||||
impl PackageTableHeader {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&self.version.to_le_bytes());
|
||||
let container_bytes = self.container.as_bytes();
|
||||
|
@ -116,7 +116,7 @@ impl fmt::Debug for PackageTableNode {
|
|||
|
||||
impl PackageTableNode {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
let mut result = Vec::new();
|
||||
let name_bytes = self.package_name.as_bytes();
|
||||
result.extend_from_slice(&(name_bytes.len() as u32).to_le_bytes());
|
||||
|
@ -175,11 +175,11 @@ impl fmt::Debug for PackageTable {
|
|||
|
||||
impl PackageTable {
|
||||
/// Serialize to bytes
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
pub fn into_bytes(&self) -> Vec<u8> {
|
||||
[
|
||||
self.header.as_bytes(),
|
||||
self.header.into_bytes(),
|
||||
self.buckets.iter().map(|v| v.unwrap_or(0).to_le_bytes()).collect::<Vec<_>>().concat(),
|
||||
self.nodes.iter().map(|v| v.as_bytes()).collect::<Vec<_>>().concat(),
|
||||
self.nodes.iter().map(|v| v.into_bytes()).collect::<Vec<_>>().concat(),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ impl PackageTable {
|
|||
let header = PackageTableHeader::from_bytes(bytes)?;
|
||||
let num_packages = header.num_packages;
|
||||
let num_buckets = crate::get_table_size(num_packages)?;
|
||||
let mut head = header.as_bytes().len();
|
||||
let mut head = header.into_bytes().len();
|
||||
let buckets = (0..num_buckets)
|
||||
.map(|_| match read_u32_from_bytes(bytes, &mut head).unwrap() {
|
||||
0 => None,
|
||||
|
@ -199,7 +199,7 @@ impl PackageTable {
|
|||
let nodes = (0..num_packages)
|
||||
.map(|_| {
|
||||
let node = PackageTableNode::from_bytes(&bytes[head..])?;
|
||||
head += node.as_bytes().len();
|
||||
head += node.into_bytes().len();
|
||||
Ok(node)
|
||||
})
|
||||
.collect::<Result<Vec<_>, AconfigStorageError>>()
|
||||
|
@ -225,17 +225,17 @@ mod tests {
|
|||
fn test_serialization() {
|
||||
let package_table = create_test_package_table();
|
||||
let header: &PackageTableHeader = &package_table.header;
|
||||
let reinterpreted_header = PackageTableHeader::from_bytes(&header.as_bytes());
|
||||
let reinterpreted_header = PackageTableHeader::from_bytes(&header.into_bytes());
|
||||
assert!(reinterpreted_header.is_ok());
|
||||
assert_eq!(header, &reinterpreted_header.unwrap());
|
||||
|
||||
let nodes: &Vec<PackageTableNode> = &package_table.nodes;
|
||||
for node in nodes.iter() {
|
||||
let reinterpreted_node = PackageTableNode::from_bytes(&node.as_bytes()).unwrap();
|
||||
let reinterpreted_node = PackageTableNode::from_bytes(&node.into_bytes()).unwrap();
|
||||
assert_eq!(node, &reinterpreted_node);
|
||||
}
|
||||
|
||||
let package_table_bytes = package_table.as_bytes();
|
||||
let package_table_bytes = package_table.into_bytes();
|
||||
let reinterpreted_table = PackageTable::from_bytes(&package_table_bytes);
|
||||
assert!(reinterpreted_table.is_ok());
|
||||
assert_eq!(&package_table, &reinterpreted_table.unwrap());
|
||||
|
@ -247,7 +247,7 @@ mod tests {
|
|||
// bytes
|
||||
fn test_version_number() {
|
||||
let package_table = create_test_package_table();
|
||||
let bytes = &package_table.as_bytes();
|
||||
let bytes = &package_table.into_bytes();
|
||||
let mut head = 0;
|
||||
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
|
||||
assert_eq!(version, 1234)
|
||||
|
@ -258,7 +258,7 @@ mod tests {
|
|||
fn test_file_type_check() {
|
||||
let mut package_table = create_test_package_table();
|
||||
package_table.header.file_type = 123u8;
|
||||
let error = PackageTable::from_bytes(&package_table.as_bytes()).unwrap_err();
|
||||
let error = PackageTable::from_bytes(&package_table.into_bytes()).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
format!("BytesParseFail(binary file is not a package map)")
|
||||
|
|
|
@ -129,7 +129,7 @@ mod tests {
|
|||
#[test]
|
||||
// this test point locks down table query
|
||||
fn test_flag_query() {
|
||||
let flag_table = create_test_flag_table().as_bytes();
|
||||
let flag_table = create_test_flag_table().into_bytes();
|
||||
let baseline = vec![
|
||||
(0, "enabled_ro", 1u16),
|
||||
(0, "enabled_rw", 2u16),
|
||||
|
@ -150,7 +150,7 @@ mod tests {
|
|||
#[test]
|
||||
// this test point locks down table query of a non exist flag
|
||||
fn test_not_existed_flag_query() {
|
||||
let flag_table = create_test_flag_table().as_bytes();
|
||||
let flag_table = create_test_flag_table().into_bytes();
|
||||
let flag_offset = find_flag_offset(&flag_table[..], 1, "disabled_fixed_ro").unwrap();
|
||||
assert_eq!(flag_offset, None);
|
||||
let flag_offset = find_flag_offset(&flag_table[..], 2, "disabled_rw").unwrap();
|
||||
|
@ -162,7 +162,7 @@ mod tests {
|
|||
fn test_higher_version_storage_file() {
|
||||
let mut table = create_test_flag_table();
|
||||
table.header.version = crate::FILE_VERSION + 1;
|
||||
let flag_table = table.as_bytes();
|
||||
let flag_table = table.into_bytes();
|
||||
let error = find_flag_offset(&flag_table[..], 0, "enabled_ro").unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
|
|
|
@ -66,7 +66,7 @@ mod tests {
|
|||
#[test]
|
||||
// this test point locks down flag value query
|
||||
fn test_flag_value_query() {
|
||||
let flag_value_list = create_test_flag_value_list().as_bytes();
|
||||
let flag_value_list = create_test_flag_value_list().into_bytes();
|
||||
let baseline: Vec<bool> = vec![false, true, false, false, true, true, false, true];
|
||||
for (offset, expected_value) in baseline.into_iter().enumerate() {
|
||||
let flag_value = find_boolean_flag_value(&flag_value_list[..], offset as u32).unwrap();
|
||||
|
@ -77,7 +77,7 @@ mod tests {
|
|||
#[test]
|
||||
// this test point locks down query beyond the end of boolean section
|
||||
fn test_boolean_out_of_range() {
|
||||
let flag_value_list = create_test_flag_value_list().as_bytes();
|
||||
let flag_value_list = create_test_flag_value_list().into_bytes();
|
||||
let error = find_boolean_flag_value(&flag_value_list[..], 8).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
|
@ -90,7 +90,7 @@ mod tests {
|
|||
fn test_higher_version_storage_file() {
|
||||
let mut value_list = create_test_flag_value_list();
|
||||
value_list.header.version = crate::FILE_VERSION + 1;
|
||||
let flag_value = value_list.as_bytes();
|
||||
let flag_value = value_list.into_bytes();
|
||||
let error = find_boolean_flag_value(&flag_value[..], 4).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
|
|
|
@ -110,7 +110,7 @@ mod tests {
|
|||
#[test]
|
||||
// this test point locks down table query
|
||||
fn test_package_query() {
|
||||
let package_table = create_test_package_table().as_bytes();
|
||||
let package_table = create_test_package_table().into_bytes();
|
||||
let package_offset =
|
||||
find_package_offset(&package_table[..], "com.android.aconfig.storage.test_1")
|
||||
.unwrap()
|
||||
|
@ -135,7 +135,7 @@ mod tests {
|
|||
// this test point locks down table query of a non exist package
|
||||
fn test_not_existed_package_query() {
|
||||
// this will land at an empty bucket
|
||||
let package_table = create_test_package_table().as_bytes();
|
||||
let package_table = create_test_package_table().into_bytes();
|
||||
let package_offset =
|
||||
find_package_offset(&package_table[..], "com.android.aconfig.storage.test_3").unwrap();
|
||||
assert_eq!(package_offset, None);
|
||||
|
@ -150,7 +150,7 @@ mod tests {
|
|||
fn test_higher_version_storage_file() {
|
||||
let mut table = create_test_package_table();
|
||||
table.header.version = crate::FILE_VERSION + 1;
|
||||
let package_table = table.as_bytes();
|
||||
let package_table = table.into_bytes();
|
||||
let error = find_package_offset(&package_table[..], "com.android.aconfig.storage.test_1")
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
|
|
|
@ -71,7 +71,7 @@ mod tests {
|
|||
fn test_boolean_flag_value_update() {
|
||||
let flag_value_list = create_test_flag_value_list();
|
||||
let value_offset = flag_value_list.header.boolean_value_offset;
|
||||
let mut content = flag_value_list.as_bytes();
|
||||
let mut content = flag_value_list.into_bytes();
|
||||
let true_byte = u8::from(true).to_le_bytes()[0];
|
||||
let false_byte = u8::from(false).to_le_bytes()[0];
|
||||
|
||||
|
@ -87,7 +87,7 @@ mod tests {
|
|||
#[test]
|
||||
// this test point locks down update beyond the end of boolean section
|
||||
fn test_boolean_out_of_range() {
|
||||
let mut flag_value_list = create_test_flag_value_list().as_bytes();
|
||||
let mut flag_value_list = create_test_flag_value_list().into_bytes();
|
||||
let error = update_boolean_flag_value(&mut flag_value_list[..], 8, true).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
|
@ -100,7 +100,7 @@ mod tests {
|
|||
fn test_higher_version_storage_file() {
|
||||
let mut value_list = create_test_flag_value_list();
|
||||
value_list.header.version = FILE_VERSION + 1;
|
||||
let mut flag_value = value_list.as_bytes();
|
||||
let mut flag_value = value_list.into_bytes();
|
||||
let error = update_boolean_flag_value(&mut flag_value[..], 4, true).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
|
|
Loading…
Reference in a new issue