From: Jason Ish Date: Tue, 8 Feb 2022 21:45:05 +0000 (-0600) Subject: frames (rust): method to create StreamSlice from slice X-Git-Tag: suricata-7.0.0-beta1~646 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c74ea3840d90c513224c2d8c3dc5652435dfdb55;p=thirdparty%2Fsuricata.git frames (rust): method to create StreamSlice from slice Useful in unit test for function that require a StreamSlice. --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index e0df43298f..a7193472e0 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -39,6 +39,17 @@ pub struct StreamSlice { } impl StreamSlice { + + /// Create a StreamSlice from a Rust slice. Useful in unit tests. + pub fn from_slice(slice: &[u8], flags: u8, offset: u64) -> Self { + Self { + input: slice.as_ptr() as *const u8, + input_len: slice.len() as u32, + flags, + offset + } + } + pub fn is_gap(&self) -> bool { self.input.is_null() && self.input_len > 0 }