use std::{collections::BTreeMap, sync::Arc};
use crate::{Schema, channel::ChannelId};
#[derive(Clone)]
pub struct ChannelDescriptor(Arc<Inner>);
struct Inner {
id: ChannelId,
topic: String,
message_encoding: String,
metadata: BTreeMap<String, String>,
schema: Option<Schema>,
}
impl ChannelDescriptor {
pub(crate) fn new(
id: ChannelId,
topic: String,
message_encoding: String,
metadata: BTreeMap<String, String>,
schema: Option<Schema>,
) -> Self {
Self(Arc::new(Inner {
id,
topic,
message_encoding,
metadata,
schema,
}))
}
pub fn id(&self) -> ChannelId {
self.0.id
}
pub fn topic(&self) -> &str {
&self.0.topic
}
pub fn message_encoding(&self) -> &str {
&self.0.message_encoding
}
pub fn metadata(&self) -> &BTreeMap<String, String> {
&self.0.metadata
}
pub fn schema(&self) -> Option<&Schema> {
self.0.schema.as_ref()
}
pub(crate) fn matches(&self, other: &Self) -> bool {
self.0.topic == other.0.topic
&& self.0.message_encoding == other.0.message_encoding
&& self.0.metadata == other.0.metadata
&& self.0.schema == other.0.schema
}
}