zenoh_protocol/network/
push.rs1#[cfg(feature = "test")]
15use crate::zenoh::Put;
16use crate::{core::WireExpr, zenoh::PushBody};
17
18pub mod flag {
19 pub const N: u8 = 1 << 5; pub const M: u8 = 1 << 6; pub const Z: u8 = 1 << 7; }
23
24#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct Push {
45 pub wire_expr: WireExpr<'static>,
46 pub ext_qos: ext::QoSType,
47 pub ext_tstamp: Option<ext::TimestampType>,
48 pub ext_nodeid: ext::NodeIdType,
49 pub payload: PushBody,
50}
51
52pub mod ext {
53 use crate::{
54 common::{ZExtZ64, ZExtZBuf},
55 zextz64, zextzbuf,
56 };
57
58 pub type QoS = zextz64!(0x1, false);
59 pub type QoSType = crate::network::ext::QoSType<{ QoS::ID }>;
60
61 pub type Timestamp = zextzbuf!(0x2, false);
62 pub type TimestampType = crate::network::ext::TimestampType<{ Timestamp::ID }>;
63
64 pub type NodeId = zextz64!(0x3, true);
65 pub type NodeIdType = crate::network::ext::NodeIdType<{ NodeId::ID }>;
66}
67
68impl Push {
69 #[cfg(feature = "test")]
70 pub fn rand() -> Self {
71 use rand::Rng;
72
73 let mut rng = rand::thread_rng();
74 let wire_expr = WireExpr::rand();
75 let payload = PushBody::rand();
76 let ext_qos = ext::QoSType::rand();
77 let ext_tstamp = rng.gen_bool(0.5).then(ext::TimestampType::rand);
78 let ext_nodeid = ext::NodeIdType::rand();
79
80 Self {
81 wire_expr,
82 payload,
83 ext_tstamp,
84 ext_qos,
85 ext_nodeid,
86 }
87 }
88}
89
90impl From<PushBody> for Push {
91 fn from(value: PushBody) -> Self {
92 Self {
93 wire_expr: WireExpr::empty(),
94 ext_qos: ext::QoSType::DEFAULT,
95 ext_tstamp: None,
96 ext_nodeid: ext::NodeIdType::DEFAULT,
97 payload: value,
98 }
99 }
100}
101
102#[cfg(feature = "test")]
103impl From<Put> for Push {
104 fn from(value: Put) -> Self {
105 PushBody::from(value).into()
106 }
107}
108
109#[cfg(feature = "test")]
110impl From<Vec<u8>> for Push {
111 fn from(value: Vec<u8>) -> Self {
112 Self::from(Put {
113 payload: value.into(),
114 ..Put::default()
115 })
116 }
117}