From 87fc7cecd25de253e8e70c513b079c752a5a3103 Mon Sep 17 00:00:00 2001 From: Dennis Shen Date: Mon, 1 Apr 2024 13:55:19 +0000 Subject: [PATCH] aconfig: syntax update, as_bytes to into_bytes to be more appropriate Bug: b/321077378 Test: atest aconfig_storage_file.test; atest aconfig.test Change-Id: I124387db54cd322bcce557a27c27e1b6a8c0f465 --- .../aconfig/aconfig/src/storage/flag_table.rs | 6 ++--- .../aconfig/aconfig/src/storage/flag_value.rs | 2 +- tools/aconfig/aconfig/src/storage/mod.rs | 6 ++--- .../aconfig/src/storage/package_table.rs | 6 ++--- .../aconfig_storage_file/src/flag_info.rs | 24 +++++++++---------- .../aconfig_storage_file/src/flag_table.rs | 24 +++++++++---------- .../aconfig_storage_file/src/flag_value.rs | 16 ++++++------- tools/aconfig/aconfig_storage_file/src/lib.rs | 6 ++--- .../aconfig_storage_file/src/package_table.rs | 24 +++++++++---------- .../src/flag_table_query.rs | 6 ++--- .../src/flag_value_query.rs | 6 ++--- .../src/package_table_query.rs | 6 ++--- .../src/flag_value_update.rs | 6 ++--- 13 files changed, 69 insertions(+), 69 deletions(-) diff --git a/tools/aconfig/aconfig/src/storage/flag_table.rs b/tools/aconfig/aconfig/src/storage/flag_table.rs index d4f4bc2c80..401379b582 100644 --- a/tools/aconfig/aconfig/src/storage/flag_table.rs +++ b/tools/aconfig/aconfig/src/storage/flag_table.rs @@ -95,10 +95,10 @@ pub fn create_flag_table(container: &str, packages: &[FlagPackage]) -> Result() as u32; + + node_wrappers.iter().map(|x| x.node.into_bytes().len()).sum::() 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 Result { 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")), } diff --git a/tools/aconfig/aconfig/src/storage/package_table.rs b/tools/aconfig/aconfig/src/storage/package_table.rs index ca0dec3088..4e3d987713 100644 --- a/tools/aconfig/aconfig/src/storage/package_table.rs +++ b/tools/aconfig/aconfig/src/storage/package_table.rs @@ -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::() as u32; + + node_wrappers.iter().map(|x| x.node.into_bytes().len()).sum::() 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 { diff --git a/tools/aconfig/aconfig_storage_file/src/flag_info.rs b/tools/aconfig/aconfig_storage_file/src/flag_info.rs index 6ece543766..c67e70e5c1 100644 --- a/tools/aconfig/aconfig_storage_file/src/flag_info.rs +++ b/tools/aconfig/aconfig_storage_file/src/flag_info.rs @@ -55,7 +55,7 @@ impl fmt::Debug for FlagInfoHeader { impl FlagInfoHeader { /// Serialize to bytes - pub fn as_bytes(&self) -> Vec { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { [ - self.header.as_bytes(), - self.nodes.iter().map(|v| v.as_bytes()).collect::>().concat(), + self.header.into_bytes(), + self.nodes.iter().map(|v| v.into_bytes()).collect::>().concat(), ] .concat() } @@ -166,11 +166,11 @@ impl FlagInfoList { pub fn from_bytes(bytes: &[u8]) -> Result { 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::, 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 = &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)") diff --git a/tools/aconfig/aconfig_storage_file/src/flag_table.rs b/tools/aconfig/aconfig_storage_file/src/flag_table.rs index f9b3158eef..2e2b85701e 100644 --- a/tools/aconfig/aconfig_storage_file/src/flag_table.rs +++ b/tools/aconfig/aconfig_storage_file/src/flag_table.rs @@ -59,7 +59,7 @@ impl fmt::Debug for FlagTableHeader { impl FlagTableHeader { /// Serialize to bytes - pub fn as_bytes(&self) -> Vec { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { [ - self.header.as_bytes(), + self.header.into_bytes(), self.buckets.iter().map(|v| v.unwrap_or(0).to_le_bytes()).collect::>().concat(), - self.nodes.iter().map(|v| v.as_bytes()).collect::>().concat(), + self.nodes.iter().map(|v| v.into_bytes()).collect::>().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::, 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 = &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)") diff --git a/tools/aconfig/aconfig_storage_file/src/flag_value.rs b/tools/aconfig/aconfig_storage_file/src/flag_value.rs index c9d09a1c17..40ccb34922 100644 --- a/tools/aconfig/aconfig_storage_file/src/flag_value.rs +++ b/tools/aconfig/aconfig_storage_file/src/flag_value.rs @@ -55,7 +55,7 @@ impl fmt::Debug for FlagValueHeader { impl FlagValueHeader { /// Serialize to bytes - pub fn as_bytes(&self) -> Vec { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { [ - self.header.as_bytes(), + self.header.into_bytes(), self.booleans.iter().map(|&v| u8::from(v).to_le_bytes()).collect::>().concat(), ] .concat() @@ -120,7 +120,7 @@ impl FlagValueList { pub fn from_bytes(bytes: &[u8]) -> Result { 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)") diff --git a/tools/aconfig/aconfig_storage_file/src/lib.rs b/tools/aconfig/aconfig_storage_file/src/lib.rs index 3bd34afede..c817570fd6 100644 --- a/tools/aconfig/aconfig_storage_file/src/lib.rs +++ b/tools/aconfig/aconfig_storage_file/src/lib.rs @@ -259,10 +259,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(); diff --git a/tools/aconfig/aconfig_storage_file/src/package_table.rs b/tools/aconfig/aconfig_storage_file/src/package_table.rs index 7cb60eb6c1..e37711555b 100644 --- a/tools/aconfig/aconfig_storage_file/src/package_table.rs +++ b/tools/aconfig/aconfig_storage_file/src/package_table.rs @@ -56,7 +56,7 @@ impl fmt::Debug for PackageTableHeader { impl PackageTableHeader { /// Serialize to bytes - pub fn as_bytes(&self) -> Vec { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { 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 { + pub fn into_bytes(&self) -> Vec { [ - self.header.as_bytes(), + self.header.into_bytes(), self.buckets.iter().map(|v| v.unwrap_or(0).to_le_bytes()).collect::>().concat(), - self.nodes.iter().map(|v| v.as_bytes()).collect::>().concat(), + self.nodes.iter().map(|v| v.into_bytes()).collect::>().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::, 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 = &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)") diff --git a/tools/aconfig/aconfig_storage_read_api/src/flag_table_query.rs b/tools/aconfig/aconfig_storage_read_api/src/flag_table_query.rs index 43977ee267..4c19646531 100644 --- a/tools/aconfig/aconfig_storage_read_api/src/flag_table_query.rs +++ b/tools/aconfig/aconfig_storage_read_api/src/flag_table_query.rs @@ -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), diff --git a/tools/aconfig/aconfig_storage_read_api/src/flag_value_query.rs b/tools/aconfig/aconfig_storage_read_api/src/flag_value_query.rs index 88d2397545..964cd69159 100644 --- a/tools/aconfig/aconfig_storage_read_api/src/flag_value_query.rs +++ b/tools/aconfig/aconfig_storage_read_api/src/flag_value_query.rs @@ -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 = 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), diff --git a/tools/aconfig/aconfig_storage_read_api/src/package_table_query.rs b/tools/aconfig/aconfig_storage_read_api/src/package_table_query.rs index 3587e10dd6..190de99ecc 100644 --- a/tools/aconfig/aconfig_storage_read_api/src/package_table_query.rs +++ b/tools/aconfig/aconfig_storage_read_api/src/package_table_query.rs @@ -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!( diff --git a/tools/aconfig/aconfig_storage_write_api/src/flag_value_update.rs b/tools/aconfig/aconfig_storage_write_api/src/flag_value_update.rs index c2375dd4e4..4cb79394fc 100644 --- a/tools/aconfig/aconfig_storage_write_api/src/flag_value_update.rs +++ b/tools/aconfig/aconfig_storage_write_api/src/flag_value_update.rs @@ -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),