zenoh_protocol/zenoh/
del.rs1use alloc::vec::Vec;
15
16use uhlc::Timestamp;
17
18use crate::common::ZExtUnknown;
19
20pub mod flag {
38 pub const T: u8 = 1 << 5; pub const Z: u8 = 1 << 7; }
42
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct Del {
45 pub timestamp: Option<Timestamp>,
46 pub ext_sinfo: Option<ext::SourceInfoType>,
47 pub ext_attachment: Option<ext::AttachmentType>,
48 pub ext_unknown: Vec<ZExtUnknown>,
49}
50
51pub mod ext {
52 use crate::{common::ZExtZBuf, zextzbuf};
53
54 pub type SourceInfo = zextzbuf!(0x1, false);
57 pub type SourceInfoType = crate::zenoh::ext::SourceInfoType<{ SourceInfo::ID }>;
58
59 pub type Attachment = zextzbuf!(0x2, false);
61 pub type AttachmentType = crate::zenoh::ext::AttachmentType<{ Attachment::ID }>;
62}
63
64impl Del {
65 #[cfg(feature = "test")]
66 pub fn rand() -> Self {
67 use rand::Rng;
68
69 use crate::{common::iext, core::ZenohIdProto};
70 let mut rng = rand::thread_rng();
71
72 let timestamp = rng.gen_bool(0.5).then_some({
73 let time = uhlc::NTP64(rng.gen());
74 let id = uhlc::ID::try_from(ZenohIdProto::rand().to_le_bytes()).unwrap();
75 Timestamp::new(time, id)
76 });
77 let ext_sinfo = rng.gen_bool(0.5).then_some(ext::SourceInfoType::rand());
78 let ext_attachment = rng.gen_bool(0.5).then_some(ext::AttachmentType::rand());
79 let mut ext_unknown = Vec::new();
80 for _ in 0..rng.gen_range(0..4) {
81 ext_unknown.push(ZExtUnknown::rand2(
82 iext::mid(ext::Attachment::ID) + 1,
83 false,
84 ));
85 }
86
87 Self {
88 timestamp,
89 ext_sinfo,
90 ext_attachment,
91 ext_unknown,
92 }
93 }
94}