diff --git a/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs b/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs index cf8f08c..eb32edc 100644 --- a/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs +++ b/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs @@ -61,9 +61,12 @@ pub trait FromBytes { impl FromBytes for i8 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I8_LEN { + info!("conversion is possible for `i8`, value {:?}", bytes); let mut array_bytes: [u8; I8_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i8::from_be_bytes(array_bytes)); + let result = i8::from_be_bytes(array_bytes); + info!("conversion result `i8`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -80,9 +83,12 @@ impl FromBytes for i8 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I8_LEN { + info!("conversion is possible for `i8`, value {:?}", bytes); let mut array_bytes: [u8; I8_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i8::from_le_bytes(array_bytes)); + let result = i8::from_le_bytes(array_bytes); + info!("conversion result `i8`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -101,9 +107,12 @@ impl FromBytes for i8 { impl FromBytes for i16 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I16_LEN { + info!("conversion is possible for `i16`, value {:?}", bytes); let mut array_bytes: [u8; I16_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i16::from_be_bytes(array_bytes)); + let result = i16::from_be_bytes(array_bytes); + info!("conversion result `i16`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -120,9 +129,12 @@ impl FromBytes for i16 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I16_LEN { + info!("conversion is possible for `i16`, value {:?}", bytes); let mut array_bytes: [u8; I16_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i16::from_le_bytes(array_bytes)); + let result = i16::from_le_bytes(array_bytes); + info!("conversion result `i16`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -141,9 +153,12 @@ impl FromBytes for i16 { impl FromBytes for i32 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I32_LEN { + info!("conversion is possible for `i32`, value {:?}", bytes); let mut array_bytes: [u8; I32_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i32::from_be_bytes(array_bytes)); + let result = i32::from_be_bytes(array_bytes); + info!("conversion result `i32`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -160,9 +175,12 @@ impl FromBytes for i32 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I32_LEN { + info!("conversion is possible for `i32`, value {:?}", bytes); let mut array_bytes: [u8; I32_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i32::from_le_bytes(array_bytes)); + let result = i32::from_le_bytes(array_bytes); + info!("conversion result `i32`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -181,9 +199,12 @@ impl FromBytes for i32 { impl FromBytes for i64 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I64_LEN { + info!("conversion is possible for `i64`, value {:?}", bytes); let mut array_bytes: [u8; I64_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i64::from_be_bytes(array_bytes)); + let result = i64::from_be_bytes(array_bytes); + info!("conversion result `i64`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -200,9 +221,12 @@ impl FromBytes for i64 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I64_LEN { + info!("conversion is possible for `i64`, value {:?}", bytes); let mut array_bytes: [u8; I64_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i64::from_le_bytes(array_bytes)); + let result = i64::from_le_bytes(array_bytes); + info!("conversion result `i64`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -221,9 +245,12 @@ impl FromBytes for i64 { impl FromBytes for i128 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I128_LEN { + info!("conversion is possible for `i128`, value {:?}", bytes); let mut array_bytes: [u8; I128_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i128::from_be_bytes(array_bytes)); + let result = i128::from_be_bytes(array_bytes); + info!("conversion result `i128`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -240,9 +267,12 @@ impl FromBytes for i128 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I128_LEN { + info!("conversion is possible for `i128`, value {:?}", bytes); let mut array_bytes: [u8; I128_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(i128::from_le_bytes(array_bytes)); + let result = i128::from_le_bytes(array_bytes); + info!("conversion result `i128`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -261,9 +291,12 @@ impl FromBytes for i128 { impl FromBytes for f32 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F32_LEN { + info!("conversion is possible for `f32`, value {:?}", bytes); let mut array_bytes: [u8; F32_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(f32::from_be_bytes(array_bytes)); + let result = f32::from_be_bytes(array_bytes); + info!("conversion result `f32`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -280,9 +313,12 @@ impl FromBytes for f32 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F32_LEN { + info!("conversion is possible for `f32`, value {:?}", bytes); let mut array_bytes: [u8; F32_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(f32::from_le_bytes(array_bytes)); + let result = f32::from_le_bytes(array_bytes); + info!("conversion result `f32`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -301,9 +337,12 @@ impl FromBytes for f32 { impl FromBytes for f64 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F64_LEN { + info!("conversion is possible for `f64`, value {:?}", bytes); let mut array_bytes: [u8; F64_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(f64::from_be_bytes(array_bytes)); + let result = f64::from_be_bytes(array_bytes); + info!("conversion result `f64`, value {:?}", result); + return Some(result); } else { warn!( "{}", @@ -320,9 +359,12 @@ impl FromBytes for f64 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F64_LEN { + info!("conversion is possible for `f64`, value {:?}", bytes); let mut array_bytes: [u8; F64_LEN] = Default::default(); array_bytes.copy_from_slice(bytes); - return Some(f64::from_le_bytes(array_bytes)); + let result = f64::from_le_bytes(array_bytes); + info!("conversion result `f64`, value {:?}", result); + return Some(result); } else { warn!( "{}", diff --git a/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs b/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs index af1fe0f..d83d0e4 100644 --- a/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs +++ b/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs @@ -4,6 +4,8 @@ use std::{ str::FromStr, }; +use log::info; + use super::rules::{next::NextStep, traits::IntoSpecificCaptureType}; use super::{convert::FromBytes, *}; @@ -26,12 +28,32 @@ fn single_range_bytes_check< .filter(|&num| { let num = match read_mode { ReadMode::FromBeBytes => { + info!( + "(range mode {}) mode {} for data {:?}", + "`any`".yellow(), + "`be bytes`".yellow(), + num + ); T::from_be_bytes_non_const(num.as_bytes().unwrap()) } ReadMode::FromLeBytes => { + info!( + "(range mode {}) mode {} for data {:?}", + "`any`".yellow(), + "`le bytes`".yellow(), + num + ); T::from_le_bytes_non_const(num.as_bytes().unwrap()) } - ReadMode::FromUtf8 => T::from_utf8(num.as_bytes().unwrap()), + ReadMode::FromUtf8 => { + info!( + "(range mode {}) mode {} for data {:?}", + "`any`".yellow(), + "`utf8`".yellow(), + num + ); + T::from_utf8(num.as_bytes().unwrap()) + } }; num.map(|num| range.contains(&num)).unwrap_or(false) }) @@ -45,12 +67,32 @@ fn single_range_bytes_check< .filter(|&num| { let num = match read_mode { ReadMode::FromBeBytes => { + info!( + "(range mode {}) mode {} for data {:?}", + "`all`".yellow(), + "`be bytes`".yellow(), + num + ); T::from_be_bytes_non_const(num.as_bytes().unwrap()) } ReadMode::FromLeBytes => { + info!( + "(range mode {}) mode {} for data {:?}", + "`all`".yellow(), + "`le bytes`".yellow(), + num + ); T::from_le_bytes_non_const(num.as_bytes().unwrap()) } - ReadMode::FromUtf8 => T::from_utf8(num.as_bytes().unwrap()), + ReadMode::FromUtf8 => { + info!( + "(range mode {}) mode {} for data {:?}", + "`all`".yellow(), + "`utf8`".yellow(), + num + ); + T::from_utf8(num.as_bytes().unwrap()) + } }; num.map(|num| range.contains(&num)).unwrap_or(false) }) @@ -65,12 +107,32 @@ fn single_range_bytes_check< .filter(|&num| { let num = match read_mode { ReadMode::FromBeBytes => { + info!( + "(range mode {}) mode {} for data {:?}", + "`exactly`".yellow(), + "`be bytes`".yellow(), + num + ); T::from_be_bytes_non_const(num.as_bytes().unwrap()) } ReadMode::FromLeBytes => { + info!( + "(range mode {}) mode {} for data {:?}", + "`exactly`".yellow(), + "`le bytes`".yellow(), + num + ); T::from_le_bytes_non_const(num.as_bytes().unwrap()) } - ReadMode::FromUtf8 => T::from_utf8(num.as_bytes().unwrap()), + ReadMode::FromUtf8 => { + info!( + "(range mode {}) mode {} for data {:?}", + "`exactly`".yellow(), + "`utf8`".yellow(), + num + ); + T::from_utf8(num.as_bytes().unwrap()) + } }; num.map(|num| range.contains(&num)).unwrap_or(false) }) diff --git a/flexible_inspect_rs/src/rules/rule_str/runner_range.rs b/flexible_inspect_rs/src/rules/rule_str/runner_range.rs index c4e5008..018e94d 100644 --- a/flexible_inspect_rs/src/rules/rule_str/runner_range.rs +++ b/flexible_inspect_rs/src/rules/rule_str/runner_range.rs @@ -1,3 +1,5 @@ +use log::info; + use super::rules::{next::NextStep, traits::IntoSpecificCaptureType}; use super::{convert::convert_and_filter, *}; use std::{ @@ -17,6 +19,11 @@ fn single_range_str_check< ) -> bool { match range_mode { RangeMode::Any => { + info!( + "(range mode {}) for data {:?}", + "`any`".yellow(), + captures.text_for_capture + ); captures .text_for_capture .iter() @@ -29,6 +36,11 @@ fn single_range_str_check< > 0 } RangeMode::All => { + info!( + "(range mode {}) for data {:?}", + "`all`".yellow(), + captures.text_for_capture + ); captures .text_for_capture .iter() @@ -41,6 +53,11 @@ fn single_range_str_check< == captures.text_for_capture.len() } RangeMode::Exactly(target_count) => { + info!( + "(range mode {}) for data {:?}", + "`exactly`".yellow(), + captures.text_for_capture + ); let required_count = target_count.min(captures.text_for_capture.len()); captures .text_for_capture