use core::time::Duration;
use zenoh_buffers::ZSlice;
use crate::transport::TransportSn;
pub mod flag {
pub const A: u8 = 1 << 5; pub const T: u8 = 1 << 6; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OpenSyn {
pub lease: Duration,
pub initial_sn: TransportSn,
pub cookie: ZSlice,
pub ext_qos: Option<ext::QoS>,
#[cfg(feature = "shared-memory")]
pub ext_shm: Option<ext::Shm>,
pub ext_auth: Option<ext::Auth>,
pub ext_mlink: Option<ext::MultiLinkSyn>,
pub ext_lowlatency: Option<ext::LowLatency>,
pub ext_compression: Option<ext::Compression>,
pub ext_south: Option<ext::RemoteBound>,
}
pub mod ext {
use crate::{zextunit, zextz64, zextzbuf};
pub type QoS = zextunit!(0x1, false);
#[cfg(feature = "shared-memory")]
pub type Shm = zextz64!(0x2, false);
pub type Auth = zextzbuf!(0x3, false);
pub type MultiLinkSyn = zextzbuf!(0x4, false);
pub type MultiLinkAck = zextunit!(0x4, false);
pub type LowLatency = zextunit!(0x5, false);
pub type Compression = zextunit!(0x6, false);
pub type RemoteBound = zextz64!(0x7, false);
}
impl OpenSyn {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
use crate::common::{ZExtUnit, ZExtZ64, ZExtZBuf};
const MIN: usize = 32;
const MAX: usize = 1_024;
let mut rng = rand::thread_rng();
let lease = if rng.gen_bool(0.5) {
Duration::from_secs(rng.gen())
} else {
Duration::from_millis(rng.gen())
};
let initial_sn: TransportSn = rng.gen();
let cookie = ZSlice::rand(rng.gen_range(MIN..=MAX));
let ext_qos = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
#[cfg(feature = "shared-memory")]
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
let ext_auth = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_mlink = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_lowlatency = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_compression = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_south = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
Self {
lease,
initial_sn,
cookie,
ext_qos,
#[cfg(feature = "shared-memory")]
ext_shm,
ext_auth,
ext_mlink,
ext_lowlatency,
ext_compression,
ext_south,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OpenAck {
pub lease: Duration,
pub initial_sn: TransportSn,
pub ext_qos: Option<ext::QoS>,
#[cfg(feature = "shared-memory")]
pub ext_shm: Option<ext::Shm>,
pub ext_auth: Option<ext::Auth>,
pub ext_mlink: Option<ext::MultiLinkAck>,
pub ext_lowlatency: Option<ext::LowLatency>,
pub ext_compression: Option<ext::Compression>,
pub ext_south: Option<ext::RemoteBound>,
}
impl OpenAck {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
use crate::common::{ZExtUnit, ZExtZ64, ZExtZBuf};
let mut rng = rand::thread_rng();
let lease = if rng.gen_bool(0.5) {
Duration::from_secs(rng.gen())
} else {
Duration::from_millis(rng.gen())
};
let initial_sn: TransportSn = rng.gen();
let ext_qos = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
#[cfg(feature = "shared-memory")]
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
let ext_auth = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_mlink = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_lowlatency = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_compression = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_south = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
Self {
lease,
initial_sn,
ext_qos,
#[cfg(feature = "shared-memory")]
ext_shm,
ext_auth,
ext_mlink,
ext_lowlatency,
ext_compression,
ext_south,
}
}
}