fix encoding
This commit is contained in:
+2
-1
@@ -4,7 +4,7 @@ fn main() {
|
|||||||
let args: Vec<_> = std::env::args().collect();
|
let args: Vec<_> = std::env::args().collect();
|
||||||
let file =
|
let file =
|
||||||
std::fs::File::open(args.get(1).unwrap_or(&"examples/bobl.replay".to_string())).unwrap();
|
std::fs::File::open(args.get(1).unwrap_or(&"examples/bobl.replay".to_string())).unwrap();
|
||||||
let outfile = std::fs::File::open(
|
let outfile = std::fs::File::create(
|
||||||
args.get(2)
|
args.get(2)
|
||||||
.unwrap_or(&"examples/bobl_smallblocks.replay".to_string()),
|
.unwrap_or(&"examples/bobl_smallblocks.replay".to_string()),
|
||||||
)
|
)
|
||||||
@@ -41,4 +41,5 @@ fn main() {
|
|||||||
out.finish().unwrap();
|
out.finish().unwrap();
|
||||||
assert_eq!(out.frame_number, rply.frame_number);
|
assert_eq!(out.frame_number, rply.frame_number);
|
||||||
assert_eq!(out.header.frame_count(), rply.header.frame_count());
|
assert_eq!(out.header.frame_count(), rply.header.frame_count());
|
||||||
|
assert_eq!(out.header.frame_count(), Some(out.frame_number));
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-5
@@ -154,6 +154,8 @@ pub enum ReplayError {
|
|||||||
Encoding(InvalidDeterminant),
|
Encoding(InvalidDeterminant),
|
||||||
#[error("I/O Error")]
|
#[error("I/O Error")]
|
||||||
IO(#[from] std::io::Error),
|
IO(#[from] std::io::Error),
|
||||||
|
#[error("Too many frames to {0} fit framecount header")]
|
||||||
|
TooManyFrames(std::num::TryFromIntError),
|
||||||
#[error("Coreless frame read for version 0 not possible")]
|
#[error("Coreless frame read for version 0 not possible")]
|
||||||
NoCoreRead(),
|
NoCoreRead(),
|
||||||
#[error("Checkpoint too big {0}")]
|
#[error("Checkpoint too big {0}")]
|
||||||
@@ -421,7 +423,7 @@ pub fn decode<R: std::io::BufRead>(rply: &mut R) -> Result<ReplayDecoder<'_, R>>
|
|||||||
pub struct ReplayEncoder<'a, W: std::io::Write + std::io::Seek> {
|
pub struct ReplayEncoder<'a, W: std::io::Write + std::io::Seek> {
|
||||||
rply: &'a mut W,
|
rply: &'a mut W,
|
||||||
pub header: Header,
|
pub header: Header,
|
||||||
pub initial_state: Vec<u8>,
|
// pub initial_state: Vec<u8>,
|
||||||
pub frame_number: u64,
|
pub frame_number: u64,
|
||||||
last_pos: u64,
|
last_pos: u64,
|
||||||
ss_state: statestream::Ctx,
|
ss_state: statestream::Ctx,
|
||||||
@@ -447,7 +449,6 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> {
|
|||||||
let mut replay = ReplayEncoder {
|
let mut replay = ReplayEncoder {
|
||||||
rply,
|
rply,
|
||||||
header,
|
header,
|
||||||
initial_state: vec![],
|
|
||||||
frame_number: 0,
|
frame_number: 0,
|
||||||
last_pos: 0,
|
last_pos: 0,
|
||||||
ss_state,
|
ss_state,
|
||||||
@@ -475,6 +476,10 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> {
|
|||||||
.write_u32::<LittleEndian>(self.header.initial_state_size())?;
|
.write_u32::<LittleEndian>(self.header.initial_state_size())?;
|
||||||
self.rply
|
self.rply
|
||||||
.write_u64::<LittleEndian>(self.header.identifier())?;
|
.write_u64::<LittleEndian>(self.header.identifier())?;
|
||||||
|
self.rply.write_u32::<LittleEndian>(
|
||||||
|
u32::try_from(self.header.frame_count().unwrap())
|
||||||
|
.map_err(ReplayError::TooManyFrames)?,
|
||||||
|
)?;
|
||||||
self.rply
|
self.rply
|
||||||
.write_u32::<LittleEndian>(self.header.block_size())?;
|
.write_u32::<LittleEndian>(self.header.block_size())?;
|
||||||
self.rply
|
self.rply
|
||||||
@@ -567,15 +572,17 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn encode_initial_checkpoint(&mut self, checkpoint: &[u8]) -> Result<()> {
|
fn encode_initial_checkpoint(&mut self, checkpoint: &[u8]) -> Result<()> {
|
||||||
let initial = std::mem::take(&mut self.initial_state);
|
// let initial = std::mem::take(&mut self.initial_state);
|
||||||
let old_pos = self.rply.stream_position()?;
|
let old_pos = self.rply.stream_position()?;
|
||||||
self.rply
|
self.rply
|
||||||
.seek(std::io::SeekFrom::Start(HEADERV2_LEN_BYTES as u64))?;
|
.seek(std::io::SeekFrom::Start(HEADERV2_LEN_BYTES as u64))?;
|
||||||
self.encode_checkpoint(checkpoint, 0)?;
|
self.encode_checkpoint(checkpoint, 0)?;
|
||||||
|
let encoded_size = self.rply.stream_position()? - HEADERV2_LEN_BYTES as u64;
|
||||||
self.header.set_initial_state_size(
|
self.header.set_initial_state_size(
|
||||||
u32::try_from(initial.len()).map_err(ReplayError::CheckpointTooBig)?,
|
u32::try_from(encoded_size).map_err(ReplayError::CheckpointTooBig)?,
|
||||||
);
|
);
|
||||||
self.initial_state = initial;
|
// self.initial_state = initial;
|
||||||
|
// dbg!("initial state size", self.header.initial_state_size());
|
||||||
// Have to rewrite header to account for initial state size
|
// Have to rewrite header to account for initial state size
|
||||||
self.write_header()?;
|
self.write_header()?;
|
||||||
self.last_pos = self.rply.stream_position()?;
|
self.last_pos = self.rply.stream_position()?;
|
||||||
|
|||||||
@@ -256,6 +256,9 @@ impl<'w, 'c, W: std::io::Write> Encoder<'w, 'c, W> {
|
|||||||
let superblock_size = self.ctx.superblock_size as usize;
|
let superblock_size = self.ctx.superblock_size as usize;
|
||||||
let superblock_size_bytes = block_size * superblock_size;
|
let superblock_size_bytes = block_size * superblock_size;
|
||||||
let superblock_count = ((checkpoint.len() - 1) / superblock_size_bytes) + 1;
|
let superblock_count = ((checkpoint.len() - 1) / superblock_size_bytes) + 1;
|
||||||
|
self.ctx
|
||||||
|
.last_superseq
|
||||||
|
.resize(superblock_count.max(self.ctx.last_superseq.len()), 0);
|
||||||
let mut superblock_contents = vec![0_u32; superblock_size];
|
let mut superblock_contents = vec![0_u32; superblock_size];
|
||||||
for (superblock_i, superblock_bytes) in checkpoint.chunks(superblock_size_bytes).enumerate()
|
for (superblock_i, superblock_bytes) in checkpoint.chunks(superblock_size_bytes).enumerate()
|
||||||
{
|
{
|
||||||
@@ -306,6 +309,7 @@ impl<'w, 'c, W: std::io::Write> Encoder<'w, 'c, W> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.ctx.last_superseq.truncate(superblock_count);
|
||||||
bytes_out += rmp_size(r::write_uint(
|
bytes_out += rmp_size(r::write_uint(
|
||||||
self.writer,
|
self.writer,
|
||||||
u64::from(u8::from(SSToken::SuperblockSeq)),
|
u64::from(u8::from(SSToken::SuperblockSeq)),
|
||||||
|
|||||||
Reference in New Issue
Block a user