hff_core/write/
hff_desc.rs1use super::{ChunkArray, DataArray, TableArray};
2use crate::{Chunk, Header, Table};
3
4#[derive(Debug)]
6pub struct HffDesc<'a> {
7 tables: TableArray,
9 chunks: ChunkArray,
11 data: Option<DataArray<'a>>,
13}
14
15impl<'a> HffDesc<'a> {
16 pub fn new(tables: TableArray, chunks: ChunkArray, data: DataArray<'a>) -> Self {
18 Self {
19 tables,
20 chunks,
21 data: Some(data),
22 }
23 }
24
25 pub fn finish(self) -> (TableArray, ChunkArray, DataArray<'a>) {
27 (self.tables, self.chunks, self.data.unwrap())
28 }
29
30 pub fn update_data(
32 tables: &mut TableArray,
33 chunks: &mut ChunkArray,
34 offset: u64,
35 offset_len: &[(u64, u64)],
36 ) {
37 let mut table_index = 0;
38 let mut chunk_index = 0;
39 let mut chunk_count = 0;
40 let mut entry = 0;
41
42 loop {
43 if chunk_count > 0 {
44 *chunks[chunk_index].offset_mut() = offset_len[entry].0 + offset;
46 *chunks[chunk_index].length_mut() = offset_len[entry].1;
47
48 chunk_count -= 1;
49 entry += 1;
50 chunk_index += 1;
51 continue;
52 }
53
54 if table_index == tables.len() {
55 break;
56 }
57
58 if tables[table_index].0 {
59 *tables[table_index].1.metadata_offset_mut() = offset_len[entry].0 + offset;
61 *tables[table_index].1.metadata_length_mut() = offset_len[entry].1;
62 entry += 1;
63 }
64
65 chunk_count = tables[table_index].1.chunk_count();
66 table_index += 1;
67 }
68 }
69 pub fn arrays_size(&self) -> usize {
71 self.tables.len() * Table::SIZE + self.chunks.len() * Chunk::SIZE
72 }
73
74 pub fn offset_to_blob(&self) -> usize {
77 Header::SIZE + self.arrays_size()
78 }
79}