Skip to main content

rocketmq_protocol/protocol/header/
get_broker_config_response_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::RequestHeaderCodec;
17use serde::Deserialize;
18use serde::Serialize;
19
20/// Generation bound to the exact Broker configuration response body.
21#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, RequestHeaderCodec)]
22#[serde(rename_all = "camelCase")]
23#[header(
24    type_id = "rocketmq_protocol::protocol::header::get_broker_config_response_header::GetBrokerConfigResponseHeader",
25    java_class = "org.apache.rocketmq.remoting.protocol.header.GetBrokerConfigResponseHeader"
26)]
27pub struct GetBrokerConfigResponseHeader {
28    pub version: Option<CheetahString>,
29    #[header(default, default_semantic = "literal:0", range = "i64")]
30    pub config_generation: u64,
31}
32
33#[cfg(test)]
34mod tests {
35    use cheetah_string::CheetahString;
36
37    use super::GetBrokerConfigResponseHeader;
38    use crate::protocol::command_custom_header::CommandCustomHeader;
39    use crate::protocol::command_custom_header::FromMap;
40
41    #[test]
42    fn config_generation_round_trips_through_wire_map() {
43        let header = GetBrokerConfigResponseHeader {
44            version: Some("{\"stateVersion\":0,\"timestamp\":42,\"counter\":43}".into()),
45            config_generation: 43,
46        };
47        let map = header.to_map().expect("header should encode");
48        assert_eq!(map.get("configGeneration").map(CheetahString::as_str), Some("43"));
49        assert_eq!(
50            map.get("version").map(CheetahString::as_str),
51            Some("{\"stateVersion\":0,\"timestamp\":42,\"counter\":43}")
52        );
53
54        let decoded = <GetBrokerConfigResponseHeader as FromMap>::from(&map).expect("header should decode");
55        assert_eq!(decoded, header);
56    }
57}