Skip to main content

rocketmq_remoting/protocol/body/
topic_info_wrapper.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::HashMap;
16
17use cheetah_string::CheetahString;
18use rocketmq_common::common::config::TopicConfig;
19use serde::Deserialize;
20use serde::Serialize;
21
22use crate::protocol::DataVersion;
23
24pub mod topic_config_wrapper;
25pub mod topic_queue_wrapper;
26
27#[derive(Debug, Deserialize, Serialize, Default)]
28pub struct TopicConfigSerializeWrapper {
29    #[serde(rename = "topicConfigTable")]
30    topic_config_table: Option<HashMap<CheetahString, TopicConfig>>,
31
32    #[serde(rename = "dataVersion")]
33    data_version: Option<DataVersion>,
34}
35
36impl TopicConfigSerializeWrapper {
37    pub fn new(
38        topic_config_table: Option<HashMap<CheetahString, TopicConfig>>,
39        data_version: Option<DataVersion>,
40    ) -> Self {
41        Self {
42            topic_config_table,
43            data_version,
44        }
45    }
46}
47
48impl TopicConfigSerializeWrapper {
49    pub fn topic_config_table(&self) -> Option<&HashMap<CheetahString, TopicConfig>> {
50        match &self.topic_config_table {
51            None => None,
52            Some(value) => Some(value),
53        }
54    }
55
56    pub fn data_version(&self) -> Option<&DataVersion> {
57        match &self.data_version {
58            None => None,
59            Some(value) => Some(value),
60        }
61    }
62
63    pub fn set_topic_config_table(&mut self, topic_config_table: Option<HashMap<CheetahString, TopicConfig>>) {
64        self.topic_config_table = topic_config_table;
65    }
66
67    pub fn set_data_version(&mut self, data_version: Option<DataVersion>) {
68        self.data_version = data_version;
69    }
70
71    pub fn take_topic_config_table(&mut self) -> Option<HashMap<CheetahString, TopicConfig>> {
72        self.topic_config_table.take()
73    }
74
75    pub fn topic_config_table_mut(&mut self) -> Option<&mut HashMap<CheetahString, TopicConfig>> {
76        self.topic_config_table.as_mut()
77    }
78}