1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
    Aim: wrap generated parser fns in struct
*/
use super::smtp::grammar::{command, session};
use samotop_core::common::Result;
use samotop_core::model::io::ReadControl;
use samotop_core::model::smtp::SmtpCommand;
use samotop_core::service::parser::Parser;

static PARSER: SmtpParser = SmtpParser;

#[derive(Clone)]
pub struct SmtpParser;

impl SmtpParser {
    pub fn new() -> SmtpParser {
        PARSER.clone()
    }
}

impl Parser for SmtpParser {
    fn command(&self, input: &[u8]) -> Result<SmtpCommand> {
        Ok(command(input)?)
    }
    fn script(&self, input: &[u8]) -> Result<Vec<ReadControl>> {
        Ok(session(input)?)
    }
}