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, Default, 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 #[doc(hidden)]
67 pub fn rand() -> Self {
68 use rand::Rng;
69
70 use crate::{common::iext, core::ZenohIdProto};
71 let mut rng = rand::thread_rng();
72
73 let timestamp = rng.gen_bool(0.5).then_some({
74 let time = uhlc::NTP64(rng.gen());
75 let id = uhlc::ID::try_from(ZenohIdProto::rand().to_le_bytes()).unwrap();
76 Timestamp::new(time, id)
77 });
78 let ext_sinfo = rng.gen_bool(0.5).then_some(ext::SourceInfoType::rand());
79 let ext_attachment = rng.gen_bool(0.5).then_some(ext::AttachmentType::rand());
80 let mut ext_unknown = Vec::new();
81 for _ in 0..rng.gen_range(0..4) {
82 ext_unknown.push(ZExtUnknown::rand2(
83 iext::mid(ext::Attachment::ID) + 1,
84 false,
85 ));
86 }
87
88 Self {
89 timestamp,
90 ext_sinfo,
91 ext_attachment,
92 ext_unknown,
93 }
94 }
95}