Skip to main content

rocketmq_remoting/protocol/header/
add_broker_request_header.rs

1// Copyright 2026 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(Clone, Debug, Default, Serialize, Deserialize, RequestHeaderCodecV2)]
21#[serde(rename_all = "camelCase")]
22pub struct AddBrokerRequestHeader {
23    pub config_path: Option<CheetahString>,
24}
25
26#[cfg(test)]
27mod tests {
28    use std::collections::HashMap;
29
30    use super::*;
31    use crate::protocol::command_custom_header::CommandCustomHeader;
32    use crate::protocol::command_custom_header::FromMap;
33
34    #[test]
35    fn add_broker_request_header_serializes_config_path() {
36        let header = AddBrokerRequestHeader {
37            config_path: Some(CheetahString::from_static_str("/tmp/broker.conf")),
38        };
39
40        let map = header.to_map().expect("header should encode");
41        assert_eq!(
42            map.get(&CheetahString::from_static_str("configPath")),
43            Some(&CheetahString::from_static_str("/tmp/broker.conf"))
44        );
45    }
46
47    #[test]
48    fn add_broker_request_header_deserializes_config_path() {
49        let mut map = HashMap::new();
50        map.insert(
51            CheetahString::from_static_str("configPath"),
52            CheetahString::from_static_str("/tmp/broker.conf"),
53        );
54
55        let header = <AddBrokerRequestHeader as FromMap>::from(&map).expect("header should decode");
56        assert_eq!(
57            header.config_path,
58            Some(CheetahString::from_static_str("/tmp/broker.conf"))
59        );
60    }
61}