1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-05-16 15:07:45 +00:00

Improve EXD documentation

This commit is contained in:
Joshua Goins 2025-05-10 23:41:21 -04:00
parent 0313f75abb
commit 8d94c630ab

View file

@ -31,8 +31,10 @@ struct EXDHeader {
#[brw(big)] #[brw(big)]
#[derive(Debug)] #[derive(Debug)]
struct ExcelDataOffset { struct ExcelDataOffset {
/// The row ID associated with this data offset
row_id: u32, row_id: u32,
pub offset: u32, // offset to it's data section in bytes from the start of the file /// Offset to it's data section in bytes from the start of the file.
pub offset: u32,
} }
#[binrw::parser(reader)] #[binrw::parser(reader)]
@ -245,8 +247,7 @@ fn write_rows(rows: &Vec<ExcelRow>, exh: &EXH) -> BinResult<()> {
let row_header = DataSection { let row_header = DataSection {
size: (new_pos - old_pos) as u32, size: (new_pos - old_pos) as u32,
row_count: 1, // TODO: hardcoded row_count: 1, // TODO: hardcoded
data: Vec::new(), // NOTE: not used here
}; };
row_header.write(writer).unwrap(); row_header.write(writer).unwrap();
@ -265,14 +266,19 @@ fn write_rows(rows: &Vec<ExcelRow>, exh: &EXH) -> BinResult<()> {
#[brw(big)] #[brw(big)]
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Debug)] #[derive(Debug)]
pub struct DataSection { struct DataSection {
/// Size of the data section in bytes.
size: u32, size: u32,
/// The number of rows in this data section.
row_count: u16, row_count: u16,
#[br(count = size)] /// The bytes of this data section.
/// We currently don't use this in our parsing, see parse_rows.
#[br(temp, count = size)]
#[bw(ignore)] #[bw(ignore)]
data: Vec<u8>, data: Vec<u8>,
} }
/// An Excel data file. Represents a page in an Excel Sheet.
#[binrw] #[binrw]
#[brw(big)] #[brw(big)]
#[allow(dead_code)] #[allow(dead_code)]
@ -289,6 +295,7 @@ pub struct EXD {
#[bw(ignore)] // write_rows handles writing this #[bw(ignore)] // write_rows handles writing this
data: Vec<DataSection>, data: Vec<DataSection>,
/// The rows contained in this EXD.
#[br(parse_with = parse_rows, args(&exh, &data_offsets))] #[br(parse_with = parse_rows, args(&exh, &data_offsets))]
#[bw(write_with = write_rows, args(&exh))] #[bw(write_with = write_rows, args(&exh))]
pub rows: Vec<ExcelRow>, pub rows: Vec<ExcelRow>,
@ -410,17 +417,22 @@ pub enum ExcelRowKind {
SubRows(Vec<ExcelSingleRow>), SubRows(Vec<ExcelSingleRow>),
} }
/// Represents an entry in the EXD.
#[derive(Debug)] #[derive(Debug)]
pub struct ExcelRow { pub struct ExcelRow {
/// The row ID associated with this entry.
pub row_id: u32, pub row_id: u32,
/// The kind of entry.
pub kind: ExcelRowKind, pub kind: ExcelRowKind,
} }
impl EXD { impl EXD {
/// Parse an EXD from an existing file.
pub fn from_existing(exh: &EXH, buffer: ByteSpan) -> Option<EXD> { pub fn from_existing(exh: &EXH, buffer: ByteSpan) -> Option<EXD> {
EXD::read_args(&mut Cursor::new(&buffer), (exh,)).ok() EXD::read_args(&mut Cursor::new(&buffer), (exh,)).ok()
} }
/// Finds the entry with the specified ID, otherwise returns `None`.
pub fn get_row(&self, row_id: u32) -> Option<ExcelRowKind> { pub fn get_row(&self, row_id: u32) -> Option<ExcelRowKind> {
for row in &self.rows { for row in &self.rows {
if row.row_id == row_id { if row.row_id == row_id {
@ -516,7 +528,7 @@ impl EXD {
let string_offset = 0u32; // TODO, but 0 is fine for single string column data let string_offset = 0u32; // TODO, but 0 is fine for single string column data
Self::write_data_raw(cursor, &string_offset); Self::write_data_raw(cursor, &string_offset);
} }
ColumnData::Bool(val) => match column_definition.data_type { ColumnData::Bool(_) => match column_definition.data_type {
ColumnDataType::Bool => todo!(), ColumnDataType::Bool => todo!(),
// packed bools are handled in write_rows // packed bools are handled in write_rows
ColumnDataType::PackedBool0 => {} ColumnDataType::PackedBool0 => {}
@ -541,6 +553,7 @@ impl EXD {
} }
} }
/// Calculate the filename of an EXD from the `name`, `language`, and `page`.
pub fn calculate_filename( pub fn calculate_filename(
name: &str, name: &str,
language: Language, language: Language,
@ -558,6 +571,7 @@ impl EXD {
} }
} }
/// Write this EXD back to it's serialized binary form.
pub fn write_to_buffer(&self, exh: &EXH) -> Option<ByteBuffer> { pub fn write_to_buffer(&self, exh: &EXH) -> Option<ByteBuffer> {
let mut buffer = ByteBuffer::new(); let mut buffer = ByteBuffer::new();