fix 1-indexed block positions

This commit is contained in:
Quaternions 2024-12-31 19:07:00 -08:00
parent 942e5ee1d8
commit 5b58efe052

View File

@ -329,6 +329,10 @@ impl std::error::Error for Error{}
#[brw(little)] #[brw(little)]
#[derive(Debug,Clone,Copy)] #[derive(Debug,Clone,Copy)]
pub struct BlockId(#[br(map=|i:u32|i-1)]u32); pub struct BlockId(#[br(map=|i:u32|i-1)]u32);
#[binrw]
#[brw(little)]
#[derive(Debug,Clone,Copy)]
pub struct BlockPosition(#[br(map=|i:u32|i-1)]u32);
#[binrw] #[binrw]
#[brw(little)] #[brw(little)]
@ -358,7 +362,7 @@ pub struct FileHeader{
pub num_offline_events:u32, pub num_offline_events:u32,
pub num_realtime_events:u32, pub num_realtime_events:u32,
#[br(count=num_offline_events+num_realtime_events+1)] #[br(count=num_offline_events+num_realtime_events+1)]
pub block_positions:Vec<u32>, pub block_positions:Vec<BlockPosition>,
#[br(count=num_offline_events)] #[br(count=num_offline_events)]
pub offline_blocks_timeline:Vec<TimedBlockId>, pub offline_blocks_timeline:Vec<TimedBlockId>,
#[br(count=num_realtime_events)] #[br(count=num_realtime_events)]
@ -373,8 +377,8 @@ impl FileHeader{
if self.block_positions.len() as u32<=block_id.0{ if self.block_positions.len() as u32<=block_id.0{
return Err(Error::InvalidBlockId(block_id)); return Err(Error::InvalidBlockId(block_id));
} }
let start=self.block_positions[block_id.0 as usize]; let start=self.block_positions[block_id.0 as usize].0;
let end=self.block_positions[block_id.0 as usize+1]; let end=self.block_positions[block_id.0 as usize+1].0;
Ok(BlockInfo{start,length:end-start}) Ok(BlockInfo{start,length:end-start})
} }
} }