2024-01-16 03:09:34 +00:00
|
|
|
//file format "sniff"
|
|
|
|
|
|
|
|
pub enum Error{
|
|
|
|
InvalidMagic,
|
|
|
|
InvalidVersion,
|
2024-01-16 03:30:26 +00:00
|
|
|
UnexpectedEOF,
|
2024-01-16 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
*/
|
2024-01-19 00:39:58 +00:00
|
|
|
#[derive(Clone,Copy)]
|
|
|
|
pub(crate) enum FourCC{
|
|
|
|
Map,
|
|
|
|
Bot,
|
|
|
|
Demo,
|
2024-01-16 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 00:39:58 +00:00
|
|
|
struct Header{
|
2024-01-16 03:09:34 +00:00
|
|
|
/// Type of file
|
2024-01-19 00:39:58 +00:00
|
|
|
fourcc:FourCC,
|
2024-01-16 03:09:34 +00:00
|
|
|
/// 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,
|
|
|
|
}
|
|
|
|
|
2024-01-19 00:39:58 +00:00
|
|
|
pub(crate) struct BlockLayout{
|
2024-01-16 03:09:34 +00:00
|
|
|
count:u64,
|
|
|
|
location:Vec<u64>,
|
|
|
|
}
|
2024-01-17 04:07:11 +00:00
|
|
|
|
2024-01-19 00:39:58 +00:00
|
|
|
pub(crate) struct File{
|
|
|
|
header:Header,
|
|
|
|
block_layout:BlockLayout,
|
|
|
|
//reference to the data
|
|
|
|
}
|
|
|
|
|
|
|
|
impl File{
|
|
|
|
pub(crate) fn new<R:std::io::Read+std::io::Seek>(input:R)->Result<Self,Error>{
|
|
|
|
Self{
|
|
|
|
header:input.read_le()?,
|
|
|
|
block_layout:input.read_le()?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub(crate) fn read_block(&mut self,block_id:u64)->Result<Vec<u8>,Error>{
|
|
|
|
Err(Error::UnexpectedEOF)
|
|
|
|
}
|
|
|
|
pub(crate) fn fourcc(&self)->FourCC{
|
|
|
|
self.header.fourcc
|
|
|
|
}
|
2024-01-17 04:07:11 +00:00
|
|
|
}
|