1use crate::{Diagnostic, Event, MAX_SAMPLE_SECONDS};
4use alloc::vec::Vec;
5use serde::{Deserialize, Serialize};
6
7pub const MAX_RECORDING_STEPS: usize = 4096;
9pub const MAX_EVENTS_PER_STEP: usize = 256;
11
12#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
13#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
14#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
15#[serde(deny_unknown_fields)]
16pub struct Recording {
21 pub version: u16,
23 pub steps: Vec<RecordedStep>,
25}
26
27#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
28#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
29#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
30#[serde(deny_unknown_fields)]
31pub struct RecordedStep {
33 pub time_seconds: f64,
35 pub events: Vec<Event>,
37}
38
39impl Recording {
40 pub fn validate(&self) -> Result<(), Diagnostic> {
47 if self.version != 1 || self.steps.len() > MAX_RECORDING_STEPS {
48 return Err(Diagnostic::plain("unsupported or oversized recording"));
49 }
50 for step in &self.steps {
51 if !step.time_seconds.is_finite()
52 || !(0.0..=MAX_SAMPLE_SECONDS).contains(&step.time_seconds)
53 || step.events.len() > MAX_EVENTS_PER_STEP
54 {
55 return Err(Diagnostic::plain(
56 "recording time exceeds scene time bounds or step exceeds event limit",
57 ));
58 }
59 }
60 Ok(())
61 }
62}