Skip to main content

rocketmq_protocol/protocol/header/
notify_broker_role_change_request_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 rocketmq_macros::RequestHeaderCodec;
16use std::fmt::Display;
17
18use cheetah_string::CheetahString;
19use serde::Deserialize;
20use serde::Serialize;
21
22#[derive(Serialize, Deserialize, Debug, RequestHeaderCodec)]
23#[serde(rename_all = "camelCase")]
24#[header(
25    type_id = "rocketmq_protocol::protocol::header::notify_broker_role_change_request_header::NotifyBrokerRoleChangedRequestHeader",
26    java_class = "org.apache.rocketmq.remoting.protocol.header.NotifyBrokerRoleChangedRequestHeader"
27)]
28pub struct NotifyBrokerRoleChangedRequestHeader {
29    pub master_address: Option<CheetahString>,
30
31    pub master_epoch: Option<i32>,
32
33    pub sync_state_set_epoch: Option<i32>,
34
35    #[header(range = "i64")]
36    pub master_broker_id: Option<u64>,
37}
38
39impl Display for NotifyBrokerRoleChangedRequestHeader {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        write!(
42            f,
43            "(master_address={:?}, master_epoch={:?}, sync_state_set_epoch={:?}, master_broker_id={:?})",
44            self.master_address, self.master_epoch, self.sync_state_set_epoch, self.master_broker_id
45        )
46    }
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn notify_broker_role_changed_request_header_display() {
55        let header = NotifyBrokerRoleChangedRequestHeader {
56            master_address: Some(CheetahString::from("addr")),
57            master_epoch: Some(1),
58            sync_state_set_epoch: Some(2),
59            master_broker_id: Some(3),
60        };
61        let display = format!("{}", header);
62        let expected = r#"(master_address=Some("addr"), master_epoch=Some(1), sync_state_set_epoch=Some(2), master_broker_id=Some(3))"#;
63        assert_eq!(display, expected);
64    }
65}