Skip to main content

rocketmq_remoting/protocol/header/
clone_group_offset_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 cheetah_string::CheetahString;
16use rocketmq_macros::RequestHeaderCodecV2;
17use serde::Deserialize;
18use serde::Serialize;
19
20use crate::rpc::rpc_request_header::RpcRequestHeader;
21
22#[derive(Clone, Debug, Default, Serialize, Deserialize, RequestHeaderCodecV2)]
23#[serde(rename_all = "camelCase")]
24pub struct CloneGroupOffsetRequestHeader {
25    #[required]
26    pub src_group: CheetahString,
27
28    #[required]
29    pub dest_group: CheetahString,
30
31    pub topic: Option<CheetahString>,
32
33    pub offline: bool,
34
35    #[serde(flatten)]
36    pub rpc_request_header: Option<RpcRequestHeader>,
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn clone_group_offset_request_header_round_trips() {
45        let header = CloneGroupOffsetRequestHeader {
46            src_group: CheetahString::from_static_str("src"),
47            dest_group: CheetahString::from_static_str("dest"),
48            topic: Some(CheetahString::from_static_str("topic-a")),
49            offline: true,
50            rpc_request_header: None,
51        };
52
53        let serialized = serde_json::to_string(&header).expect("serialize clone group offset header");
54        assert_eq!(
55            serialized,
56            r#"{"srcGroup":"src","destGroup":"dest","topic":"topic-a","offline":true}"#
57        );
58
59        let decoded: CloneGroupOffsetRequestHeader =
60            serde_json::from_str(&serialized).expect("deserialize clone group offset header");
61        assert_eq!(decoded.src_group, "src");
62        assert_eq!(decoded.dest_group, "dest");
63        assert_eq!(decoded.topic, Some(CheetahString::from_static_str("topic-a")));
64        assert!(decoded.offline);
65    }
66}