use alloc::borrow::Cow;
pub use common::*;
pub use keyexpr::*;
pub use queryable::*;
pub use subscriber::*;
pub use token::*;
use crate::{
core::{ExprId, WireExpr},
network::Mapping,
zextz64, zextzbuf,
};
pub mod flag {
pub const I: u8 = 1 << 5; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Declare {
pub interest_id: Option<super::interest::InterestId>,
pub ext_qos: ext::QoSType,
pub ext_tstamp: Option<ext::TimestampType>,
pub ext_nodeid: ext::NodeIdType,
pub body: DeclareBody,
}
pub mod ext {
use crate::{zextz64, zextzbuf};
pub type QoS = zextz64!(0x1, false);
pub type QoSType = crate::network::ext::QoSType<{ QoS::ID }>;
pub type Timestamp = zextzbuf!(0x2, false);
pub type TimestampType = crate::network::ext::TimestampType<{ Timestamp::ID }>;
pub type NodeId = zextz64!(0x3, true);
pub type NodeIdType = crate::network::ext::NodeIdType<{ NodeId::ID }>;
}
pub mod id {
pub const D_KEYEXPR: u8 = 0x00;
pub const U_KEYEXPR: u8 = 0x01;
pub const D_SUBSCRIBER: u8 = 0x02;
pub const U_SUBSCRIBER: u8 = 0x03;
pub const D_QUERYABLE: u8 = 0x04;
pub const U_QUERYABLE: u8 = 0x05;
pub const D_TOKEN: u8 = 0x06;
pub const U_TOKEN: u8 = 0x07;
pub const D_FINAL: u8 = 0x1A;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DeclareBody {
DeclareKeyExpr(DeclareKeyExpr),
UndeclareKeyExpr(UndeclareKeyExpr),
DeclareSubscriber(DeclareSubscriber),
UndeclareSubscriber(UndeclareSubscriber),
DeclareQueryable(DeclareQueryable),
UndeclareQueryable(UndeclareQueryable),
DeclareToken(DeclareToken),
UndeclareToken(UndeclareToken),
DeclareFinal(DeclareFinal),
}
impl DeclareBody {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
match rng.gen_range(0..9) {
0 => DeclareBody::DeclareKeyExpr(DeclareKeyExpr::rand()),
1 => DeclareBody::UndeclareKeyExpr(UndeclareKeyExpr::rand()),
2 => DeclareBody::DeclareSubscriber(DeclareSubscriber::rand()),
3 => DeclareBody::UndeclareSubscriber(UndeclareSubscriber::rand()),
4 => DeclareBody::DeclareQueryable(DeclareQueryable::rand()),
5 => DeclareBody::UndeclareQueryable(UndeclareQueryable::rand()),
6 => DeclareBody::DeclareToken(DeclareToken::rand()),
7 => DeclareBody::UndeclareToken(UndeclareToken::rand()),
8 => DeclareBody::DeclareFinal(DeclareFinal::rand()),
_ => unreachable!(),
}
}
}
impl Declare {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let interest_id = rng
.gen_bool(0.5)
.then_some(rng.gen::<super::interest::InterestId>());
let ext_qos = ext::QoSType::rand();
let ext_tstamp = rng.gen_bool(0.5).then(ext::TimestampType::rand);
let ext_nodeid = ext::NodeIdType::rand();
let body = DeclareBody::rand();
Self {
interest_id,
ext_qos,
ext_tstamp,
ext_nodeid,
body,
}
}
}
pub mod common {
use super::*;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeclareFinal;
impl DeclareFinal {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
Self
}
}
pub mod ext {
use super::*;
pub type WireExprExt = zextzbuf!(0x0f, true);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WireExprType {
pub wire_expr: WireExpr<'static>,
}
impl WireExprType {
pub fn null() -> Self {
Self {
wire_expr: WireExpr {
scope: ExprId::MIN,
suffix: Cow::from(""),
mapping: Mapping::Receiver,
},
}
}
pub fn is_null(&self) -> bool {
self.wire_expr.is_empty()
}
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
Self {
wire_expr: WireExpr::rand(),
}
}
}
}
}
pub mod keyexpr {
use super::*;
pub mod flag {
pub const N: u8 = 1 << 5; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeclareKeyExpr {
pub id: ExprId,
pub wire_expr: WireExpr<'static>,
}
impl DeclareKeyExpr {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: ExprId = rng.gen();
let wire_expr = WireExpr::rand();
Self { id, wire_expr }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UndeclareKeyExpr {
pub id: ExprId,
}
impl UndeclareKeyExpr {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: ExprId = rng.gen();
Self { id }
}
}
}
pub mod subscriber {
use super::*;
use crate::core::EntityId;
pub type SubscriberId = EntityId;
pub mod flag {
pub const N: u8 = 1 << 5; pub const M: u8 = 1 << 6; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeclareSubscriber {
pub id: SubscriberId,
pub wire_expr: WireExpr<'static>,
}
impl DeclareSubscriber {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: SubscriberId = rng.gen();
let wire_expr = WireExpr::rand();
Self { id, wire_expr }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UndeclareSubscriber {
pub id: SubscriberId,
pub ext_wire_expr: common::ext::WireExprType,
}
impl UndeclareSubscriber {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: SubscriberId = rng.gen();
let ext_wire_expr = common::ext::WireExprType::rand();
Self { id, ext_wire_expr }
}
}
}
pub mod queryable {
use super::*;
use crate::core::EntityId;
pub type QueryableId = EntityId;
pub mod flag {
pub const N: u8 = 1 << 5; pub const M: u8 = 1 << 6; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeclareQueryable {
pub id: QueryableId,
pub wire_expr: WireExpr<'static>,
pub ext_info: ext::QueryableInfoType,
}
pub mod ext {
use super::*;
pub type QueryableInfo = zextz64!(0x01, false);
pub mod flag {
pub const C: u8 = 1; }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct QueryableInfoType {
pub complete: bool, pub distance: u16, }
impl QueryableInfoType {
pub const DEFAULT: Self = Self {
complete: false,
distance: 0,
};
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let complete: bool = rng.gen_bool(0.5);
let distance: u16 = rng.gen();
Self { complete, distance }
}
}
impl Default for QueryableInfoType {
fn default() -> Self {
Self::DEFAULT
}
}
}
impl DeclareQueryable {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: QueryableId = rng.gen();
let wire_expr = WireExpr::rand();
let ext_info = ext::QueryableInfoType::rand();
Self {
id,
wire_expr,
ext_info,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UndeclareQueryable {
pub id: QueryableId,
pub ext_wire_expr: common::ext::WireExprType,
}
impl UndeclareQueryable {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: QueryableId = rng.gen();
let ext_wire_expr = common::ext::WireExprType::rand();
Self { id, ext_wire_expr }
}
}
}
pub mod token {
use super::*;
pub type TokenId = u32;
pub mod flag {
pub const N: u8 = 1 << 5; pub const M: u8 = 1 << 6; pub const Z: u8 = 1 << 7; }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeclareToken {
pub id: TokenId,
pub wire_expr: WireExpr<'static>,
}
impl DeclareToken {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: TokenId = rng.gen();
let wire_expr = WireExpr::rand();
Self { id, wire_expr }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UndeclareToken {
pub id: TokenId,
pub ext_wire_expr: common::ext::WireExprType,
}
impl UndeclareToken {
#[cfg(feature = "test")]
#[doc(hidden)]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
let id: TokenId = rng.gen();
let ext_wire_expr = common::ext::WireExprType::rand();
Self { id, ext_wire_expr }
}
}
}