use bytes::{BufMut, BytesMut};
use rand::RngExt;
use crate::config::ShapeConfig;
pub const ID_SIZE: usize = 32;
pub fn build_frame(config: &ShapeConfig, payload: &[u8]) -> ([u8; ID_SIZE], BytesMut) {
let id: [u8; ID_SIZE] = rand::rng().random();
let mut msg = BytesMut::with_capacity(config.frame_size);
msg.extend_from_slice(&id);
msg.extend_from_slice(payload);
let pad = config.frame_size - ID_SIZE - payload.len();
if pad > 0 {
let mut rng = rand::rng();
for _ in 0..pad {
msg.put_u8(rng.random());
}
}
debug_assert_eq!(msg.len(), config.frame_size);
(id, msg)
}
pub fn random_cover(config: &ShapeConfig) -> BytesMut {
let mut msg = BytesMut::with_capacity(config.frame_size);
let id: [u8; ID_SIZE] = rand::rng().random();
msg.extend_from_slice(&id);
let mut rng = rand::rng();
for _ in 0..(config.frame_size - ID_SIZE) {
msg.put_u8(rng.random());
}
msg
}