Skip to main content

rocketmq_protocol/protocol/header/
update_subscription_group_config_cas_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/// Subscription Group metadata version observed after a CAS update attempt.
20///
21/// On success this is the newly committed version. On a compare-and-set
22/// conflict it is the current version 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_subscription_group_config_cas_response_header::UpdateSubscriptionGroupConfigCasResponseHeader"
26)]
27#[serde(rename_all = "camelCase")]
28pub struct UpdateSubscriptionGroupConfigCasResponseHeader {
29    #[header(default, default_semantic = "literal:0")]
30    pub subscription_group_version: u64,
31}
32
33#[cfg(test)]
34mod tests {
35    use cheetah_string::CheetahString;
36
37    use super::UpdateSubscriptionGroupConfigCasResponseHeader;
38    use crate::protocol::command_custom_header::CommandCustomHeader;
39    use crate::protocol::command_custom_header::FromMap;
40
41    #[test]
42    fn subscription_group_version_round_trips_through_wire_map() {
43        let header = UpdateSubscriptionGroupConfigCasResponseHeader {
44            subscription_group_version: 43,
45        };
46        let map = header.to_map().expect("header should encode");
47        assert_eq!(
48            map.get("subscriptionGroupVersion").map(CheetahString::as_str),
49            Some("43")
50        );
51
52        let decoded =
53            <UpdateSubscriptionGroupConfigCasResponseHeader as FromMap>::from(&map).expect("header should decode");
54        assert_eq!(decoded, header);
55    }
56}