diff --git a/rust/src/applayertemplate/parser.rs b/rust/src/applayertemplate/parser.rs index 0fdfc9c2ef..d781e9891d 100644 --- a/rust/src/applayertemplate/parser.rs +++ b/rust/src/applayertemplate/parser.rs @@ -15,28 +15,29 @@ * 02110-1301, USA. */ +use nom7::{ + bytes::streaming::{take, take_until}, + combinator::map_res, + IResult, +}; use std; fn parse_len(input: &str) -> Result { input.parse::() } -named!(pub parse_message, - do_parse!( - len: map_res!( - map_res!(take_until!(":"), std::str::from_utf8), parse_len) >> - _sep: take!(1) >> - msg: take_str!(len) >> - ( - msg.to_string() - ) - )); +pub fn parse_message(i: &[u8]) -> IResult<&[u8], String> { + let (i, len) = map_res(map_res(take_until(":"), std::str::from_utf8), parse_len)(i)?; + let (i, _sep) = take(1_usize)(i)?; + let (i, msg) = map_res(take(len as usize), std::str::from_utf8)(i)?; + let result = msg.to_string(); + Ok((i, result)) +} #[cfg(test)] mod tests { - - use nom::*; use super::*; + use nom7::Err; /// Simple test of some valid data. #[test] diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index a0ec9a34af..3db22ea343 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -20,7 +20,7 @@ use std::collections::VecDeque; use crate::core::{ALPROTO_UNKNOWN, AppProto, Flow, IPPROTO_TCP}; use crate::applayer::{self, *}; use std::ffi::CString; -use nom; +use nom7 as nom; use super::parser; static mut ALPROTO_TEMPLATE: AppProto = ALPROTO_UNKNOWN;