rocketmq_remoting/protocol/body/topic_info_wrapper/
topic_config_wrapper.rs1use std::collections::HashMap;
18
19use cheetah_string::CheetahString;
20use dashmap::DashMap;
21use rocketmq_common::common::config::TopicConfig;
22use rocketmq_rust::ArcMut;
23use serde::Deserialize;
24use serde::Serialize;
25
26use crate::protocol::static_topic::topic_queue_info::TopicQueueMappingInfo;
27use crate::protocol::static_topic::topic_queue_mapping_detail::TopicQueueMappingDetail;
28use crate::protocol::DataVersion;
29
30#[derive(Debug, Clone, Serialize, Deserialize, Default)]
31pub struct TopicConfigAndMappingSerializeWrapper {
32 #[serde(rename = "topicQueueMappingInfoMap")]
33 pub topic_queue_mapping_info_map:
34 DashMap<CheetahString , ArcMut<TopicQueueMappingInfo>>,
35
36 #[serde(rename = "topicQueueMappingDetailMap")]
37 pub topic_queue_mapping_detail_map:
38 DashMap<CheetahString , ArcMut<TopicQueueMappingDetail>>,
39
40 #[serde(rename = "mappingDataVersion")]
41 pub mapping_data_version: DataVersion,
42
43 #[serde(flatten)]
44 pub topic_config_serialize_wrapper: TopicConfigSerializeWrapper,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
48pub struct TopicConfigSerializeWrapper {
49 #[serde(rename = "topicConfigTable")]
50 pub topic_config_table: HashMap<CheetahString, TopicConfig>,
51 #[serde(rename = "dataVersion")]
52 pub data_version: DataVersion,
53}
54
55impl TopicConfigAndMappingSerializeWrapper {
56 pub fn topic_queue_mapping_info_map(
57 &self,
58 ) -> &DashMap<CheetahString, ArcMut<TopicQueueMappingInfo>> {
59 &self.topic_queue_mapping_info_map
60 }
61
62 pub fn topic_queue_mapping_detail_map(
63 &self,
64 ) -> &DashMap<CheetahString , ArcMut<TopicQueueMappingDetail>> {
65 &self.topic_queue_mapping_detail_map
66 }
67
68 pub fn mapping_data_version(&self) -> &DataVersion {
69 &self.mapping_data_version
70 }
71 pub fn topic_config_serialize_wrapper(&self) -> &TopicConfigSerializeWrapper {
72 &self.topic_config_serialize_wrapper
73 }
74}
75
76impl TopicConfigSerializeWrapper {
77 pub fn topic_config_table(&self) -> &HashMap<CheetahString, TopicConfig> {
78 &self.topic_config_table
79 }
80
81 pub fn data_version(&self) -> &DataVersion {
82 &self.data_version
83 }
84}
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89
90 #[test]
91 fn topic_config_and_mapping_serialize_wrapper_default() {
92 let wrapper = TopicConfigAndMappingSerializeWrapper::default();
93 assert!(wrapper.topic_queue_mapping_info_map.is_empty());
94 assert!(wrapper.topic_queue_mapping_detail_map.is_empty());
95 assert!(wrapper
97 .topic_config_serialize_wrapper()
98 .topic_config_table()
99 .is_empty());
100 }
105
106 #[test]
107 fn topic_config_and_mapping_serialize_wrapper_getters() {
108 let mut wrapper = TopicConfigAndMappingSerializeWrapper::default();
109 let _topic_config = TopicConfig::default();
110 let topic_queue_mapping_info = ArcMut::new(TopicQueueMappingInfo::default());
111 let topic_queue_mapping_detail = ArcMut::<TopicQueueMappingDetail>::default();
112 let topic_config_serialize_wrapper = TopicConfigSerializeWrapper::default();
115 wrapper.topic_config_serialize_wrapper = topic_config_serialize_wrapper.clone();
116 wrapper
117 .topic_queue_mapping_info_map
118 .insert("test".into(), topic_queue_mapping_info.clone());
119 wrapper
120 .topic_queue_mapping_detail_map
121 .insert("test".into(), topic_queue_mapping_detail.clone());
122
123 assert_eq!(
125 wrapper.topic_config_serialize_wrapper(),
126 &topic_config_serialize_wrapper
127 );
128 }
129}