Skip to main content

rocketmq_remoting/protocol/header/
get_all_topic_config_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
20#[derive(Clone, Debug, Serialize, Deserialize, Default, RequestHeaderCodecV2)]
21#[serde(rename_all = "camelCase")]
22pub struct GetAllTopicConfigRequestHeader {
23    #[required]
24    pub topic_seq: i32,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub data_version: Option<CheetahString>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub max_topic_num: Option<i32>,
29}
30
31#[cfg(test)]
32mod tests {
33    use std::collections::HashMap;
34
35    use super::*;
36    use crate::protocol::command_custom_header::CommandCustomHeader;
37    use crate::protocol::command_custom_header::FromMap;
38
39    #[test]
40    fn get_all_topic_config_request_header_maps_java_fields() {
41        let header = GetAllTopicConfigRequestHeader {
42            topic_seq: 11,
43            data_version: Some(CheetahString::from_static_str("dv-topic")),
44            max_topic_num: Some(64),
45        };
46
47        let map = header.to_map().expect("header should encode");
48        assert_eq!(map.get("topicSeq").map(|value| value.as_str()), Some("11"));
49        assert_eq!(map.get("dataVersion").map(|value| value.as_str()), Some("dv-topic"));
50        assert_eq!(map.get("maxTopicNum").map(|value| value.as_str()), Some("64"));
51
52        let decoded = <GetAllTopicConfigRequestHeader as FromMap>::from(&map).expect("header should decode");
53        assert_eq!(decoded.topic_seq, 11);
54        assert_eq!(decoded.data_version.as_deref(), Some("dv-topic"));
55        assert_eq!(decoded.max_topic_num, Some(64));
56    }
57
58    #[test]
59    fn get_all_topic_config_request_header_requires_topic_seq_like_java_header() {
60        let result = <GetAllTopicConfigRequestHeader as FromMap>::from(&HashMap::new());
61
62        assert!(result.is_err());
63    }
64}