pcapsql_core/stream/
registry.rs1use super::{StreamContext, StreamParser};
2
3pub struct StreamRegistry {
5 parsers: Vec<Box<dyn StreamParser>>,
6}
7
8impl StreamRegistry {
9 pub fn new() -> Self {
10 Self {
11 parsers: Vec::new(),
12 }
13 }
14
15 pub fn register<P: StreamParser + 'static>(&mut self, parser: P) {
17 self.parsers.push(Box::new(parser));
18 }
19
20 pub fn find_parser(&self, context: &StreamContext) -> Option<&dyn StreamParser> {
22 self.parsers
23 .iter()
24 .find(|p| p.can_parse_stream(context))
25 .map(|p| p.as_ref())
26 }
27
28 pub fn get_parser(&self, name: &str) -> Option<&dyn StreamParser> {
30 self.parsers
31 .iter()
32 .find(|p| p.name() == name)
33 .map(|p| p.as_ref())
34 }
35
36 pub fn parser_names(&self) -> Vec<&'static str> {
38 self.parsers.iter().map(|p| p.name()).collect()
39 }
40}
41
42impl Default for StreamRegistry {
43 fn default() -> Self {
44 Self::new()
45 }
46}