1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-25 05:47:45 +00:00
physis/src/exh.rs

90 lines
1.6 KiB
Rust
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
use std::io::Cursor;
use binrw::BinRead;
use binrw::binrw;
2022-08-16 11:52:07 -04:00
use crate::common::Language;
use crate::ByteSpan;
2022-07-21 19:58:58 -04:00
2023-08-02 16:27:28 -04:00
#[binrw]
#[brw(magic = b"EXHF")]
#[brw(big)]
2022-09-15 16:26:31 -04:00
#[allow(dead_code)]
2022-07-21 19:58:58 -04:00
pub struct EXHHeader {
2022-08-16 11:52:07 -04:00
version: u16,
2022-07-21 19:58:58 -04:00
2023-08-02 16:27:28 -04:00
pub data_offset: u16,
2022-08-16 11:52:07 -04:00
column_count: u16,
page_count: u16,
language_count: u16,
2022-07-21 19:58:58 -04:00
#[br(pad_before = 6)]
2022-08-16 11:52:07 -04:00
#[br(pad_after = 8)]
2023-04-09 15:35:10 -04:00
pub row_count: u32,
2022-07-21 19:58:58 -04:00
}
2023-08-02 16:27:28 -04:00
#[binrw]
#[brw(repr(u16))]
2022-07-21 19:58:58 -04:00
pub enum ColumnDataType {
String = 0x0,
Bool = 0x1,
Int8 = 0x2,
UInt8 = 0x3,
Int16 = 0x4,
UInt16 = 0x5,
Int32 = 0x6,
UInt32 = 0x7,
Float32 = 0x9,
Int64 = 0xA,
UInt64 = 0xB,
PackedBool0 = 0x19,
PackedBool1 = 0x1A,
PackedBool2 = 0x1B,
PackedBool3 = 0x1C,
PackedBool4 = 0x1D,
PackedBool5 = 0x1E,
PackedBool6 = 0x1F,
PackedBool7 = 0x20,
}
2023-08-02 16:27:28 -04:00
#[binrw]
#[brw(big)]
2022-07-21 19:58:58 -04:00
pub struct ExcelColumnDefinition {
2022-08-16 11:52:07 -04:00
pub data_type: ColumnDataType,
pub offset: u16,
2022-07-21 19:58:58 -04:00
}
2023-08-02 16:27:28 -04:00
#[binrw]
#[brw(big)]
2022-09-15 16:26:31 -04:00
#[allow(dead_code)]
2022-07-21 19:58:58 -04:00
pub struct ExcelDataPagination {
2022-08-16 11:52:07 -04:00
pub start_id: u32,
2023-04-09 15:35:10 -04:00
pub row_count: u32,
2022-07-21 19:58:58 -04:00
}
2023-08-02 16:27:28 -04:00
#[binrw]
#[brw(big)]
2022-09-15 16:26:31 -04:00
#[allow(dead_code)]
2022-07-21 19:58:58 -04:00
pub struct EXH {
2022-08-16 11:52:07 -04:00
pub header: EXHHeader,
2022-07-21 19:58:58 -04:00
#[br(count = header.column_count)]
2022-08-16 11:52:07 -04:00
pub column_definitions: Vec<ExcelColumnDefinition>,
2022-07-21 19:58:58 -04:00
#[br(count = header.page_count)]
2022-08-16 11:52:07 -04:00
pub pages: Vec<ExcelDataPagination>,
2022-07-21 19:58:58 -04:00
#[br(count = header.language_count)]
2023-04-09 15:35:10 -04:00
pub languages: Vec<Language>,
2022-07-21 19:58:58 -04:00
}
impl EXH {
pub fn from_existing(buffer: ByteSpan) -> Option<EXH> {
2022-08-16 11:50:18 -04:00
EXH::read(&mut Cursor::new(&buffer)).ok()
2022-07-21 19:58:58 -04:00
}
2022-08-16 11:52:07 -04:00
}