(path: &Path, level: i32)
| 70 | } |
| 71 | |
| 72 | fn measure(path: &Path, level: i32) -> Result<Row> { |
| 73 | let mut input = BufReader::new(fs::File::open(path)?); |
| 74 | let mut reader = ChangeReader::open(&mut input)?; |
| 75 | let schema = reader.file_header().version; |
| 76 | let mut semantic = None; |
| 77 | let mut content = Vec::new(); |
| 78 | let mut sizes = Sizes { |
| 79 | objects: 1, |
| 80 | original_object_bytes: fs::metadata(path)?.len().try_into()?, |
| 81 | ..Sizes::default() |
| 82 | }; |
| 83 | let mut next_chunk = 0; |
| 84 | while let Some(section) = reader.next_section()? { |
| 85 | match section.section_type { |
| 86 | SectionType::Semantic => { |
| 87 | ensure!( |
| 88 | semantic.is_none(), |
| 89 | "experiment expects one aggregate semantic section" |
| 90 | ); |
| 91 | sizes.original_semantic_bytes += section.compressed_size as usize; |
| 92 | semantic = Some(section.payload); |
| 93 | } |
| 94 | SectionType::Content => { |
| 95 | let info = section |
| 96 | .content_chunk_info |
| 97 | .context("missing chunk metadata")?; |
| 98 | ensure!( |
| 99 | info.chunk_index == next_chunk, |
| 100 | "nonsequential content chunks" |
| 101 | ); |
| 102 | ensure!( |
| 103 | section.payload.len() == info.uncompressed_len as usize, |
| 104 | "chunk length mismatch" |
| 105 | ); |
| 106 | ensure!( |
| 107 | *blake3::hash(§ion.payload).as_bytes() == info.chunk_hash, |
| 108 | "chunk hash mismatch" |
| 109 | ); |
| 110 | next_chunk += 1; |
| 111 | sizes.compressed_content_bytes += section.compressed_size as usize; |
| 112 | content.extend(section.payload); |
| 113 | } |
| 114 | _ => {} |
| 115 | } |
| 116 | } |
| 117 | let hash = reader.verify()?; |
| 118 | ensure!( |
| 119 | input.read(&mut [0])? == 0, |
| 120 | "trailing bytes after change trailer" |
| 121 | ); |
| 122 | sizes.authored_content_bytes = content.len(); |
| 123 | let mut encode_ms = 0.0; |
| 124 | let mut decode_ms = 0.0; |
| 125 | if let Some(raw) = semantic { |
| 126 | let (ops, rest): (Vec<FileOps>, _) = postcard::take_from_bytes(&raw)?; |
| 127 | ensure!(rest.is_empty(), "trailing semantic bytes"); |
| 128 | sizes.files = ops.len(); |
| 129 | sizes.lines = ops.iter().map(FileOps::line_count).sum(); |
no test coverage detected