repak/src/lib.rs

70 lines
1.9 KiB
Rust
Raw Normal View History

2023-01-03 10:33:42 +00:00
#![allow(dead_code)]
mod entry;
2023-01-03 10:33:42 +00:00
mod error;
mod ext;
mod footer;
mod pak;
2023-01-03 10:33:42 +00:00
2023-01-14 18:32:06 +00:00
pub use {error::*, pak::*};
2023-01-03 10:33:42 +00:00
pub const MAGIC: u32 = 0x5A6F12E1;
#[repr(u32)]
#[derive(
2023-01-07 21:10:11 +00:00
Clone, Copy, PartialEq, Eq, PartialOrd, Debug, strum::Display, strum::FromRepr, strum::EnumIter,
2023-01-03 10:33:42 +00:00
)]
pub enum Version {
2023-01-07 21:10:11 +00:00
Unknown, // unknown (mostly just for padding)
2023-01-03 10:33:42 +00:00
Initial, // initial specification
NoTimestamps, // timestamps removed
CompressionEncryption, // compression and encryption support
IndexEncryption, // index encryption support
RelativeChunkOffsets, // offsets are relative to header
DeleteRecords, // record deletion support
EncryptionKeyGuid, // include key GUID
FNameBasedCompression, // compression names included
FrozenIndex, // frozen index byte included
}
2023-01-05 20:20:05 +00:00
// strum shouldn't need to be installed by users
2023-01-03 10:33:42 +00:00
impl Version {
pub fn iter() -> VersionIter {
<Version as strum::IntoEnumIterator>::iter()
}
pub fn size(self) -> i64 {
// (magic + version): u32 + (offset + size): u64 + hash: [u8; 20]
let mut size = 4 + 4 + 8 + 8 + 20;
if self >= Version::EncryptionKeyGuid {
// encryption uuid: u128
size += 16;
}
if self >= Version::IndexEncryption {
// encrypted: bool
size += 1;
}
if self == Version::FrozenIndex {
// frozen index: bool
size += 1;
}
if self >= Version::FNameBasedCompression {
// compression names: [[u8; 32]; 4]
size += 32 * 4;
}
if self >= Version::FrozenIndex {
// extra compression name: [u8; 32]
size += 32
}
size
}
2023-01-03 10:33:42 +00:00
}
2023-01-05 20:20:05 +00:00
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, strum::Display, strum::EnumString)]
2023-01-03 10:33:42 +00:00
pub enum Compression {
#[default]
None,
2023-01-03 10:33:42 +00:00
Zlib,
Gzip,
Oodle,
}