use zenoh_buffers::ZSlice;
use crate::{
core::{Resolution, WhatAmI, ZenohIdProto},
transport::BatchSize,
};
pub mod flag {
pub const A: u8 = 1 << 5; pub const S: u8 = 1 << 6; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitSyn {
pub version: u8,
pub whatami: WhatAmI,
pub zid: ZenohIdProto,
pub resolution: Resolution,
pub batch_size: BatchSize,
pub ext_qos: Option<ext::QoS>,
pub ext_qos_link: Option<ext::QoSLink>,
#[cfg(feature = "shared-memory")]
pub ext_shm: Option<ext::Shm>,
pub ext_auth: Option<ext::Auth>,
pub ext_mlink: Option<ext::MultiLink>,
pub ext_lowlatency: Option<ext::LowLatency>,
pub ext_compression: Option<ext::Compression>,
pub ext_patch: ext::PatchType,
pub ext_region_name: Option<ext::RegionName>,
}
pub mod ext {
use crate::{zextunit, zextz64, zextzbuf};
pub type QoS = zextunit!(0x1, false);
pub type QoSLink = zextz64!(0x1, false);
#[cfg(feature = "shared-memory")]
pub type Shm = zextzbuf!(0x2, false);
pub type Auth = zextzbuf!(0x3, false);
pub type MultiLink = zextzbuf!(0x4, false);
pub type LowLatency = zextunit!(0x5, false);
pub type Compression = zextunit!(0x6, false);
pub type Patch = zextz64!(0x7, false);
pub type PatchType = crate::transport::ext::PatchType<{ Patch::ID }>;
pub type RegionName = zextzbuf!(0x8, false);
}
impl InitSyn {
#[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 version: u8 = rng.gen();
let whatami = WhatAmI::rand();
let zid = ZenohIdProto::default();
let resolution = Resolution::rand();
let batch_size: BatchSize = rng.gen();
let ext_qos = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_qos_link = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
#[cfg(feature = "shared-memory")]
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZBuf::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_patch = ext::PatchType::rand();
let ext_region_name = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
Self {
version,
whatami,
zid,
resolution,
batch_size,
ext_qos,
ext_qos_link,
#[cfg(feature = "shared-memory")]
ext_shm,
ext_auth,
ext_mlink,
ext_lowlatency,
ext_compression,
ext_patch,
ext_region_name,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitAck {
pub version: u8,
pub whatami: WhatAmI,
pub zid: ZenohIdProto,
pub resolution: Resolution,
pub batch_size: BatchSize,
pub cookie: ZSlice,
pub ext_qos: Option<ext::QoS>,
pub ext_qos_link: Option<ext::QoSLink>,
#[cfg(feature = "shared-memory")]
pub ext_shm: Option<ext::Shm>,
pub ext_auth: Option<ext::Auth>,
pub ext_mlink: Option<ext::MultiLink>,
pub ext_lowlatency: Option<ext::LowLatency>,
pub ext_compression: Option<ext::Compression>,
pub ext_patch: ext::PatchType,
pub ext_region_name: Option<ext::RegionName>,
}
impl InitAck {
#[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 version: u8 = rng.gen();
let whatami = WhatAmI::rand();
let zid = ZenohIdProto::default();
let resolution = if rng.gen_bool(0.5) {
Resolution::default()
} else {
Resolution::rand()
};
let batch_size: BatchSize = rng.gen();
let cookie = ZSlice::rand(64);
let ext_qos = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_qos_link = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
#[cfg(feature = "shared-memory")]
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZBuf::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_patch = ext::PatchType::rand();
let ext_region_name = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
Self {
version,
whatami,
zid,
resolution,
batch_size,
cookie,
ext_qos,
ext_qos_link,
#[cfg(feature = "shared-memory")]
ext_shm,
ext_auth,
ext_mlink,
ext_lowlatency,
ext_compression,
ext_patch,
ext_region_name,
}
}
}