From c74ea3840d90c513224c2d8c3dc5652435dfdb55 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 8 Feb 2022 15:45:05 -0600 Subject: [PATCH] frames (rust): method to create StreamSlice from slice Useful in unit test for function that require a StreamSlice. --- rust/src/applayer.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 }