rillrate_protocol/base/frame_flow/
state.rs

1use crate::base::new_tf;
2use rill_protocol::flow::core::{DataFraction, Flow, TimedEvent};
3use rill_protocol::io::provider::StreamType;
4use rill_protocol::timed_frame::TimedFrame;
5use serde::{Deserialize, Serialize};
6
7pub trait FrameFlowSpec: DataFraction {
8    type Frame: DataFraction;
9
10    fn retain_secs(&self) -> u32;
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct FrameFlowState<T: FrameFlowSpec> {
15    #[serde(bound = "")]
16    pub spec: T,
17    pub frame: TimedFrame<T::Frame>,
18}
19
20#[allow(clippy::new_without_default)]
21impl<T: FrameFlowSpec> FrameFlowState<T> {
22    pub fn new(spec: T) -> Self {
23        let frame = new_tf(spec.retain_secs() as i64 + 1);
24        Self { spec, frame }
25    }
26}
27
28impl<T: FrameFlowSpec> Flow for FrameFlowState<T> {
29    type Action = FrameFlowAction;
30    type Event = FrameFlowEvent<T>;
31
32    fn stream_type() -> StreamType {
33        StreamType::from(module_path!())
34    }
35
36    fn apply(&mut self, event: Self::Event) {
37        match event {
38            FrameFlowEvent::AddFrame { event } => {
39                self.frame.insert_pop(event);
40            }
41        }
42    }
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub enum FrameFlowAction {}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub enum FrameFlowEvent<T: FrameFlowSpec> {
50    // TODO: Maybe:
51    // UpdateInfo { spec }
52    AddFrame { event: TimedEvent<T::Frame> },
53}