Skip to main content

rocketmq_protocol/protocol/header/
update_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 rocketmq_macros::RequestHeaderCodec;
16use serde::Deserialize;
17use serde::Serialize;
18
19/// Generation observed after a broker configuration update attempt.
20///
21/// On success this is the newly committed generation. On a compare-and-set
22/// conflict it is the current generation that rejected the stale request.
23#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize, RequestHeaderCodec)]
24#[header(
25    type_id = "rocketmq_protocol::protocol::header::update_broker_config_response_header::UpdateBrokerConfigResponseHeader"
26)]
27#[serde(rename_all = "camelCase")]
28pub struct UpdateBrokerConfigResponseHeader {
29    #[header(default, default_semantic = "literal:0")]
30    pub config_generation: u64,
31}
32
33#[cfg(test)]
34mod tests {
35    use cheetah_string::CheetahString;
36
37    use super::UpdateBrokerConfigResponseHeader;
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 = UpdateBrokerConfigResponseHeader { config_generation: 43 };
44        let map = header.to_map().expect("header should encode");
45        assert_eq!(map.get("configGeneration").map(CheetahString::as_str), Some("43"));
46
47        let decoded = <UpdateBrokerConfigResponseHeader as FromMap>::from(&map).expect("header should decode");
48        assert_eq!(decoded, header);
49    }
50}