Skip to main content

rocketmq_remoting/protocol/header/namesrv/
perm_broker_header.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 cheetah_string::CheetahString;
16use rocketmq_macros::RequestHeaderCodecV2;
17use serde::Deserialize;
18use serde::Serialize;
19
20#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
21#[serde(rename_all = "camelCase")]
22pub struct WipeWritePermOfBrokerRequestHeader {
23    #[required]
24    pub broker_name: CheetahString,
25}
26
27impl WipeWritePermOfBrokerRequestHeader {
28    pub fn new(broker_name: impl Into<CheetahString>) -> Self {
29        Self {
30            broker_name: broker_name.into(),
31        }
32    }
33}
34
35#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
36#[serde(rename_all = "camelCase")]
37pub struct WipeWritePermOfBrokerResponseHeader {
38    pub wipe_topic_count: i32,
39}
40
41impl WipeWritePermOfBrokerResponseHeader {
42    pub fn new(wipe_topic_count: i32) -> Self {
43        Self { wipe_topic_count }
44    }
45
46    pub fn get_wipe_topic_count(&self) -> i32 {
47        self.wipe_topic_count
48    }
49}
50
51#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
52#[serde(rename_all = "camelCase")]
53pub struct AddWritePermOfBrokerRequestHeader {
54    pub broker_name: CheetahString,
55}
56
57impl AddWritePermOfBrokerRequestHeader {
58    pub fn new(broker_name: impl Into<CheetahString>) -> Self {
59        Self {
60            broker_name: broker_name.into(),
61        }
62    }
63}
64
65#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
66#[serde(rename_all = "camelCase")]
67pub struct AddWritePermOfBrokerResponseHeader {
68    pub add_topic_count: i32,
69}
70
71impl AddWritePermOfBrokerResponseHeader {
72    pub fn new(add_topic_count: i32) -> Self {
73        Self { add_topic_count }
74    }
75
76    pub fn get_add_topic_count(&self) -> i32 {
77        self.add_topic_count
78    }
79}
80
81#[cfg(test)]
82mod tests {
83    use super::*;
84
85    #[test]
86    fn wipe_write_perm_of_broker_request_header_new() {
87        let header = WipeWritePermOfBrokerRequestHeader::new("broker1");
88        assert_eq!(header.broker_name, CheetahString::from("broker1"));
89    }
90
91    #[test]
92    fn wipe_write_perm_of_broker_response_header_new_and_getters() {
93        let header = WipeWritePermOfBrokerResponseHeader::new(10);
94        assert_eq!(header.get_wipe_topic_count(), 10);
95    }
96
97    #[test]
98    fn add_write_perm_of_broker_request_header_new() {
99        let header = AddWritePermOfBrokerRequestHeader::new("broker1");
100        assert_eq!(header.broker_name, CheetahString::from("broker1"));
101    }
102
103    #[test]
104    fn add_write_perm_of_broker_response_header_new_and_getters() {
105        let header = AddWritePermOfBrokerResponseHeader::new(20);
106        assert_eq!(header.get_add_topic_count(), 20);
107    }
108}