oura/filters/
mod.rs

1use gasket::runtime::Tether;
2use serde::Deserialize;
3
4use crate::framework::*;
5
6pub mod into_json;
7pub mod legacy_v1;
8pub mod noop;
9pub mod parse_cbor;
10pub mod rollback_buffer;
11pub mod select;
12pub mod split_block;
13
14#[cfg(feature = "wasm")]
15pub mod wasm_plugin;
16
17#[allow(clippy::large_enum_variant)]
18pub enum Bootstrapper {
19    Noop(noop::Stage),
20    SplitBlock(split_block::Stage),
21    IntoJson(into_json::Stage),
22    LegacyV1(legacy_v1::Stage),
23    ParseCbor(parse_cbor::Stage),
24    Select(select::Stage),
25    RollbackBuffer(rollback_buffer::Stage),
26
27    #[cfg(feature = "wasm")]
28    WasmPlugin(wasm_plugin::Stage),
29}
30
31impl Bootstrapper {
32    pub fn borrow_input(&mut self) -> &mut FilterInputPort {
33        match self {
34            Bootstrapper::Noop(p) => &mut p.input,
35            Bootstrapper::SplitBlock(p) => &mut p.input,
36            Bootstrapper::IntoJson(p) => &mut p.input,
37            Bootstrapper::LegacyV1(p) => &mut p.input,
38            Bootstrapper::ParseCbor(p) => &mut p.input,
39            Bootstrapper::Select(p) => &mut p.input,
40            Bootstrapper::RollbackBuffer(p) => &mut p.input,
41
42            #[cfg(feature = "wasm")]
43            Bootstrapper::WasmPlugin(p) => &mut p.input,
44        }
45    }
46
47    pub fn borrow_output(&mut self) -> &mut FilterOutputPort {
48        match self {
49            Bootstrapper::Noop(p) => &mut p.output,
50            Bootstrapper::SplitBlock(p) => &mut p.output,
51            Bootstrapper::IntoJson(p) => &mut p.output,
52            Bootstrapper::LegacyV1(p) => &mut p.output,
53            Bootstrapper::ParseCbor(p) => &mut p.output,
54            Bootstrapper::Select(p) => &mut p.output,
55            Bootstrapper::RollbackBuffer(p) => &mut p.output,
56
57            #[cfg(feature = "wasm")]
58            Bootstrapper::WasmPlugin(p) => &mut p.output,
59        }
60    }
61
62    pub fn spawn(self, policy: gasket::runtime::Policy) -> Tether {
63        match self {
64            Bootstrapper::Noop(x) => gasket::runtime::spawn_stage(x, policy),
65            Bootstrapper::SplitBlock(x) => gasket::runtime::spawn_stage(x, policy),
66            Bootstrapper::IntoJson(x) => gasket::runtime::spawn_stage(x, policy),
67            Bootstrapper::LegacyV1(x) => gasket::runtime::spawn_stage(x, policy),
68            Bootstrapper::ParseCbor(x) => gasket::runtime::spawn_stage(x, policy),
69            Bootstrapper::Select(x) => gasket::runtime::spawn_stage(x, policy),
70            Bootstrapper::RollbackBuffer(x) => gasket::runtime::spawn_stage(x, policy),
71
72            #[cfg(feature = "wasm")]
73            Bootstrapper::WasmPlugin(x) => gasket::runtime::spawn_stage(x, policy),
74        }
75    }
76}
77
78#[derive(Deserialize)]
79#[serde(tag = "type")]
80pub enum Config {
81    Noop(noop::Config),
82    SplitBlock(split_block::Config),
83    IntoJson(into_json::Config),
84    LegacyV1(legacy_v1::Config),
85    ParseCbor(parse_cbor::Config),
86    Select(select::Config),
87    RollbackBuffer(rollback_buffer::Config),
88
89    #[cfg(feature = "wasm")]
90    WasmPlugin(wasm_plugin::Config),
91}
92
93impl Config {
94    pub fn bootstrapper(self, ctx: &Context) -> Result<Bootstrapper, Error> {
95        match self {
96            Config::Noop(c) => Ok(Bootstrapper::Noop(c.bootstrapper(ctx)?)),
97            Config::SplitBlock(c) => Ok(Bootstrapper::SplitBlock(c.bootstrapper(ctx)?)),
98            Config::IntoJson(c) => Ok(Bootstrapper::IntoJson(c.bootstrapper(ctx)?)),
99            Config::LegacyV1(c) => Ok(Bootstrapper::LegacyV1(c.bootstrapper(ctx)?)),
100            Config::ParseCbor(c) => Ok(Bootstrapper::ParseCbor(c.bootstrapper(ctx)?)),
101            Config::Select(c) => Ok(Bootstrapper::Select(c.bootstrapper(ctx)?)),
102            Config::RollbackBuffer(c) => Ok(Bootstrapper::RollbackBuffer(c.bootstrapper(ctx)?)),
103
104            #[cfg(feature = "wasm")]
105            Config::WasmPlugin(c) => Ok(Bootstrapper::WasmPlugin(c.bootstrapper(ctx)?)),
106        }
107    }
108}
109
110impl Default for Config {
111    fn default() -> Self {
112        Config::LegacyV1(Default::default())
113    }
114}