Send EOT event at the end of the ALiS stream

This commit is contained in:
Marcin Kulik
2026-02-13 18:05:13 +01:00
parent e53220fbf9
commit 34e4fe1c6d
2 changed files with 34 additions and 1 deletions

View File

@@ -149,6 +149,17 @@ impl EventSerializer {
msg
}
Eot(id, time) => {
let id_bytes = leb128::encode(id);
let time_bytes = leb128::encode(self.rel_time(time));
let mut msg = vec![0x04];
msg.extend_from_slice(&id_bytes);
msg.extend_from_slice(&time_bytes);
msg
}
}
}
@@ -403,6 +414,22 @@ mod tests {
assert_eq!(serializer.0.as_micros(), 5300);
}
#[test]
fn test_serialize_eot() {
let mut serializer = EventSerializer(Duration::from_micros(5000));
let event = Event::Eot(30.into(), Duration::from_micros(5300));
let bytes = serializer.serialize_event(event);
let expected = vec![
0x04, // EOT event type
0x1E, // id (30) in LEB128
0xAC, 0x02, // relative time (300) in LEB128
];
assert_eq!(bytes, expected);
assert_eq!(serializer.0.as_micros(), 5300);
}
#[test]
fn test_subsequent_event_lower_time() {
let mut serializer = EventSerializer(Duration::from_micros(1000));

View File

@@ -36,6 +36,7 @@ pub enum Event {
Resize(EventId, Duration, TtySize),
Marker(EventId, Duration, String),
Exit(EventId, Duration, i32),
Eot(EventId, Duration),
}
#[derive(Clone)]
@@ -122,7 +123,12 @@ async fn run(
}
}
None => break,
None => {
let time = stream_time + last_event_time.elapsed();
let id = last_event_id.next();
let _ = broadcast_tx.send(Event::Eot(id, time));
break;
},
}
}