Skip to content

Instantly share code, notes, and snippets.

@tpmccallum
Created November 19, 2020 07:56
Show Gist options
  • Select an option

  • Save tpmccallum/b67977434a88ceb3c8c62ed4c72467f3 to your computer and use it in GitHub Desktop.

Select an option

Save tpmccallum/b67977434a88ceb3c8c62ed4c72467f3 to your computer and use it in GitHub Desktop.
pub fn search_bytes_single_input(byte_array: &[u8]) -> String {
let mut number_of_bytes_str = "".to_string();
for i in 0..10 {
number_of_bytes_str.push_str(&byte_array[i].to_string());
}
let number_of_bytes_usize: usize = number_of_bytes_str.parse().unwrap();
let needle: &[u8] = &byte_array.get(10..10 + number_of_bytes_usize).unwrap();
let haystack: &[u8] = &byte_array.get(10 + number_of_bytes_usize..).unwrap();
match haystack.windows(needle.len()).position(|window| window == needle){
Some(_) => "Present".to_string(),
None => "Absent".to_string()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment