More informative demo output
This commit is contained in:
+19
-2
@@ -9,6 +9,23 @@ fn main() {
|
||||
let header = &rply.header;
|
||||
println!("{header:?}");
|
||||
let mut frame = Frame::default();
|
||||
rply.read_frame(&mut frame).unwrap();
|
||||
println!("{frame:?}");
|
||||
while let Ok(()) = rply
|
||||
.read_frame(&mut frame)
|
||||
.inspect_err(|e| println!("Err: {e}"))
|
||||
{
|
||||
println!(
|
||||
" {}{:08} {}",
|
||||
if frame.checkpoint_bytes.is_empty() {
|
||||
" "
|
||||
} else {
|
||||
"*"
|
||||
},
|
||||
rply.frame_number,
|
||||
frame.inputs(),
|
||||
);
|
||||
if Some(rply.frame_number) == rply.header.frame_count() {
|
||||
println!("Done!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-2
@@ -137,7 +137,7 @@ pub struct ReplayDecoder<'a, R: std::io::BufRead> {
|
||||
rply: &'a mut R,
|
||||
pub header: Header,
|
||||
pub initial_state: Vec<u8>,
|
||||
pub frame_number: usize,
|
||||
pub frame_number: u64,
|
||||
ss_state: statestream::Ctx,
|
||||
}
|
||||
|
||||
@@ -291,6 +291,7 @@ impl<R: std::io::BufRead> ReplayDecoder<'_, R> {
|
||||
self.decode_checkpoint(&mut frame.checkpoint_bytes)?;
|
||||
}
|
||||
}
|
||||
self.frame_number += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -388,6 +389,13 @@ impl Header {
|
||||
Header::V2(header_v2) => header_v2.base.version,
|
||||
}
|
||||
}
|
||||
#[must_use]
|
||||
pub fn frame_count(&self) -> Option<u64> {
|
||||
match self {
|
||||
Header::V0V1(_) => None,
|
||||
Header::V2(header_v2) => Some(u64::from(header_v2.frame_count)),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Default)]
|
||||
pub struct KeyData {
|
||||
@@ -409,11 +417,27 @@ pub struct InputData {
|
||||
pub struct Frame {
|
||||
pub key_events: Vec<KeyData>,
|
||||
pub input_events: Vec<InputData>,
|
||||
checkpoint_bytes: Vec<u8>,
|
||||
pub checkpoint_bytes: Vec<u8>,
|
||||
pub checkpoint_compression: Compression,
|
||||
pub checkpoint_encoding: Encoding,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
#[must_use]
|
||||
pub fn inputs(&self) -> String {
|
||||
use std::fmt::Write;
|
||||
let mut output = String::new();
|
||||
for i in 0..self.input_events.len() {
|
||||
let evt = &self.input_events[i];
|
||||
write!(output, "{:03}:{:016b}", evt.id, evt.val).unwrap();
|
||||
if i + 1 < self.input_events.len() {
|
||||
write!(output, "--").unwrap();
|
||||
}
|
||||
}
|
||||
output
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Frame {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
||||
+5
-2
@@ -170,11 +170,12 @@ impl<R: std::io::Read> std::io::Read for Decoder<'_, '_, R> {
|
||||
r::read_array_len(self.reader).map_err(std::io::Error::other)? as usize;
|
||||
let block_byte_size = self.ctx.block_size as usize;
|
||||
let superblock_byte_size = self.ctx.superblock_size as usize * block_byte_size;
|
||||
let mut superseq = vec![0; arr_len];
|
||||
self.ctx.last_state.resize(self.state_size, 0);
|
||||
for superblock_i in 0..arr_len {
|
||||
for (superblock_i, superseq_sblk) in superseq.iter_mut().enumerate() {
|
||||
let superblock_idx =
|
||||
r::read_int(self.reader).map_err(std::io::Error::other)?;
|
||||
self.ctx.last_superseq[superblock_i] = superblock_idx;
|
||||
*superseq_sblk = superblock_idx;
|
||||
let superblock_data = self.ctx.superblock_index.get(superblock_idx);
|
||||
for (block_i, block_id) in superblock_data.iter().copied().enumerate() {
|
||||
let block_start = (superblock_i * superblock_byte_size
|
||||
@@ -190,7 +191,9 @@ impl<R: std::io::Read> std::io::Read for Decoder<'_, '_, R> {
|
||||
.copy_from_slice(&block_bytes[0..(block_end - block_start)]);
|
||||
}
|
||||
}
|
||||
self.ctx.last_superseq = superseq;
|
||||
state = State::Finished;
|
||||
self.finished = true;
|
||||
break;
|
||||
}
|
||||
(s, tok) => return Err(std::io::Error::other(SSError::ParseError(s, tok))),
|
||||
|
||||
Reference in New Issue
Block a user