syslog_parse/protocol/
mod.rs

1use nom::branch::alt;
2use nom::IResult;
3
4mod rfc3164;
5mod rfc5424;
6
7#[derive(Debug, Eq, PartialEq)]
8pub struct Msg<'a> {
9    pub header: String,
10    pub msg: &'a str,
11}
12
13pub fn single_parse(input: &str) -> IResult<&str, Msg> {
14    alt((rfc5424::parse, rfc3164::parse))(input)
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn test_1() {
23        let msg =  "<11>1 2023-09-07T09:45:08.899092Z localhost <90>myprogram5424 42 1545121 - tcp 传输 syslog";
24        let value = single_parse(msg).unwrap();
25        let exptecd_msg = "tcp 传输 syslog";
26        assert_eq!(value, ("", Msg{
27            header: "<11>1 2023-09-07T09:45:08.899092Z localhost <90>myprogram5424 42 1545121 - ".to_string(),
28            msg: exptecd_msg,
29        }));
30    }
31}