use super::{sig, InputGenerator};
use crate::spec::types::OpSignature;
pub struct BoundaryLengths;
impl InputGenerator for BoundaryLengths {
fn name(&self) -> &'static str {
"boundary_lengths"
}
fn handles(&self, signature: &OpSignature) -> bool {
sig::is_byte_input(signature)
}
fn generate(&self, signature: &OpSignature, _seed: u64) -> Vec<(String, Vec<u8>)> {
if sig::is_byte_input(signature) {
lengths()
.iter()
.map(|len| (format!("boundary:len{len}"), bytes(*len)))
.collect()
} else {
Vec::new()
}
}
}
fn lengths() -> &'static [usize] {
&[
0, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 127, 128, 255, 256, 512, 1024, 4096,
]
}
fn bytes(len: usize) -> Vec<u8> {
(0..len).map(|idx| (idx as u8).wrapping_mul(31)).collect()
}