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 #[doc(hidden)]
71 pub fn rand() -> Self {
72 use rand::Rng;
73
74 let mut rng = rand::thread_rng();
75 let wire_expr = WireExpr::rand();
76 let payload = PushBody::rand();
77 let ext_qos = ext::QoSType::rand();
78 let ext_tstamp = rng.gen_bool(0.5).then(ext::TimestampType::rand);
79 let ext_nodeid = ext::NodeIdType::rand();
80
81 Self {
82 wire_expr,
83 payload,
84 ext_tstamp,
85 ext_qos,
86 ext_nodeid,
87 }
88 }
89}
90
91impl From<PushBody> for Push {
92 fn from(value: PushBody) -> Self {
93 Self {
94 wire_expr: WireExpr::empty(),
95 ext_qos: ext::QoSType::DEFAULT,
96 ext_tstamp: None,
97 ext_nodeid: ext::NodeIdType::DEFAULT,
98 payload: value,
99 }
100 }
101}
102
103#[cfg(feature = "test")]
104impl From<Put> for Push {
105 fn from(value: Put) -> Self {
106 PushBody::from(value).into()
107 }
108}
109
110#[cfg(feature = "test")]
111impl From<Vec<u8>> for Push {
112 fn from(value: Vec<u8>) -> Self {
113 Self::from(Put {
114 payload: value.into(),
115 ..Put::default()
116 })
117 }
118}