use alloc::vec::Vec;
use uhlc::Timestamp;
use crate::common::ZExtUnknown;
pub mod flag {
pub const T: u8 = 1 << 5; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Del {
pub timestamp: Option<Timestamp>,
pub ext_sinfo: Option<ext::SourceInfoType>,
pub ext_attachment: Option<ext::AttachmentType>,
pub ext_unknown: Vec<ZExtUnknown>,
}
pub mod ext {
use crate::zextzbuf;
pub type SourceInfo = zextzbuf!(0x1, false);
pub type SourceInfoType = crate::zenoh::ext::SourceInfoType<{ SourceInfo::ID }>;
pub type Attachment = zextzbuf!(0x2, false);
pub type AttachmentType = crate::zenoh::ext::AttachmentType<{ Attachment::ID }>;
}
impl Del {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
use crate::{common::iext, core::ZenohIdProto};
let mut rng = rand::thread_rng();
let timestamp = rng.gen_bool(0.5).then_some({
let time = uhlc::NTP64(rng.gen());
let id = uhlc::ID::try_from(ZenohIdProto::rand().to_le_bytes()).unwrap();
Timestamp::new(time, id)
});
let ext_sinfo = rng.gen_bool(0.5).then_some(ext::SourceInfoType::rand());
let ext_attachment = rng.gen_bool(0.5).then_some(ext::AttachmentType::rand());
let mut ext_unknown = Vec::new();
for _ in 0..rng.gen_range(0..4) {
ext_unknown.push(ZExtUnknown::rand2(
iext::mid(ext::Attachment::ID) + 1,
false,
));
}
Self {
timestamp,
ext_sinfo,
ext_attachment,
ext_unknown,
}
}
}