strafe-client-jed/src/file.rs

79 lines
1.5 KiB
Rust
Raw Normal View History

2024-01-16 03:09:34 +00:00
//file format "sniff"
pub enum Error{
Header(HeaderError),
Map(crate::map::Error),
Bot(crate::bot::Error),
Demo(crate::demo::Error),
}
pub enum MissingData{
NeedExactly(usize),//missing exactly this many bytes
NeedAtLeast(usize),//missing at least this many bytes
}
pub enum HeaderError{
InvalidMagic,
InvalidVersion,
UnexpectedEOF{
eof:usize,
missing_data:MissingData,
},//file ends in the middle of the header
}
/* spec
//begin global header
//global metadata (32 bytes)
b"SNFB"
u32 format_version
u64 priming_bytes
//how many bytes of the file must be read to guarantee all of the expected
//format-specific metadata is available to facilitate streaming the remaining contents
//used by the database to guarantee that it serves at least the bare minimum
u128 resource_uuid
//identifies the file from anywhere for any other file
//global block layout (variable size)
u64 num_blocks
for block_id in 0..num_blocks{
u64 first_byte
}
//end global header
//begin blocks
//each block is compressed with zstd or gz or something
*/
pub enum Magic{
Map, //"SNFM"
Bot, //"SNFB"
Demo, //"SNFD"
PlaylistDemo,
}
pub struct Header{
/// Type of file
magic:Magic,
/// Type version
version:u32,
/// Minimum data required to know the location of all streamable resources for this specific file
priming:u64,
/// uuid for this file
resource:u128,
}
pub struct BlockLayout{
count:u64,
location:Vec<u64>,
}
pub enum SNF{
Map(crate::map::Map),
Bot(crate::bot::Bot),
Demo(crate::demo::Demo),
}