use alloc::vec::Vec;
pub const MAX_STACK_SIZE: usize = 255;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TsStackType<const ID: u8> {
pub ts_stack: TimestampStack,
}
impl<const ID: u8> TsStackType<{ ID }> {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let conf_flags: u8 = rng.gen_range(1..=7);
let n: usize = rng.gen_range(0..=3);
let mut stack = Vec::with_capacity(n);
let points = [
interception_point::SEND,
interception_point::ROUTE,
interception_point::RECEIVE,
];
for _ in 0..n {
let point = points[rng.gen_range(0..points.len())];
let is_custom = rng.gen_bool(0.5);
let flags = point
| if is_custom {
interception_point::IS_CUSTOM_TS
} else {
0
};
let ts_len: usize = rng.gen_range(0..=16);
let timestamp: Vec<u8> = (0..ts_len).map(|_| rng.gen()).collect();
stack.push(Interception { flags, timestamp });
}
Self {
ts_stack: TimestampStack { conf_flags, stack },
}
}
}
pub mod interception_point {
pub const SEND: u8 = 0b0000_0001;
pub const ROUTE: u8 = 0b0000_0010;
pub const RECEIVE: u8 = 0b0000_0100;
pub const IS_CUSTOM_TS: u8 = 0b1000_0000;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Interception {
pub flags: u8,
pub timestamp: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimestampStack {
pub conf_flags: u8,
pub stack: Vec<Interception>,
}