diff options
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/parser.rs b/src/parser.rs index 7acbbe9..45b900e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -25,10 +25,11 @@ impl Header { /// call the `add_bytes` method to add them to the internal buffer. At any /// point, you can call `next_frame` to then return the next complete frame if /// one has been read. -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] pub struct Parser { reading: std::collections::VecDeque<u8>, read_state: Option<Header>, + offset: Option<std::time::Duration>, } impl Parser { @@ -91,16 +92,22 @@ impl Parser { let time = header.time(); self.read_state = None; + if self.offset.is_none() { + self.offset = Some(time); + } Some(crate::frame::Frame { time, data }) } -} -impl Default for Parser { - fn default() -> Self { - Self { - reading: std::collections::VecDeque::new(), - read_state: None, - } + /// How much the timestamps in this file should be offset by. + /// + /// Ttyrec files are allowed to be generated by just inserting the current + /// absolute timestamp as the header. This means that during playback, we + /// need to take the timestamp of the first frame as the start time, and + /// each frame timestamp after that should be offset by that same amount. + /// + /// Returns `None` if no frames have been read yet. + pub fn offset(&self) -> Option<std::time::Duration> { + self.offset } } |