photon_backend/
descriptor.rs1use serde_json::Value;
4
5use crate::delivery_mode::{DeliveryMode, ShardConfig};
6
7#[derive(Debug, Clone)]
11pub struct TopicDescriptor {
12 pub topic_name: &'static str,
14 pub keyed_by: Option<&'static str>,
16 pub schema_json: &'static str,
21 pub delivery: DeliveryMode,
23 pub shard_config: Option<ShardConfig>,
25}
26
27impl TopicDescriptor {
28 #[must_use]
30 pub const fn new(
31 topic_name: &'static str,
32 keyed_by: Option<&'static str>,
33 schema_json: &'static str,
34 ) -> Self {
35 Self {
36 topic_name,
37 keyed_by,
38 schema_json,
39 delivery: DeliveryMode::Broadcast,
40 shard_config: None,
41 }
42 }
43
44 #[must_use]
46 pub const fn group(
47 topic_name: &'static str,
48 shard_count: u32,
49 shard_by: Option<&'static str>,
50 schema_json: &'static str,
51 ) -> Self {
52 Self {
53 topic_name,
54 keyed_by: None,
55 schema_json,
56 delivery: DeliveryMode::ConsumerGroup,
57 shard_config: Some(ShardConfig::new(shard_count, shard_by)),
58 }
59 }
60
61 #[must_use]
63 pub fn is_consumer_group(&self) -> bool {
64 self.delivery == DeliveryMode::ConsumerGroup
65 }
66
67 #[must_use]
69 pub fn schema_value(&self) -> Option<Value> {
70 serde_json::from_str(self.schema_json).ok()
71 }
72}
73
74crate::inventory::collect!(TopicDescriptor);
76
77impl quark::Registrable for TopicDescriptor {
78 fn registry_key(&self) -> &str {
79 self.topic_name
80 }
81}