Skip to main content

rocketmq_protocol/protocol/body/topic/
topic_list.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 serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Serialize, Deserialize, Default)]
20#[serde(rename_all = "camelCase")]
21pub struct TopicList {
22    pub topic_list: Vec<CheetahString>,
23    pub broker_addr: Option<CheetahString>,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn serde_contract_uses_java_field_names() {
32        let body = TopicList {
33            topic_list: vec!["topic-a".into(), "topic-b".into()],
34            broker_addr: Some("127.0.0.1:10911".into()),
35        };
36
37        let value = serde_json::to_value(&body).expect("serialize topic list");
38        assert_eq!(
39            value,
40            serde_json::json!({
41                "topicList": ["topic-a", "topic-b"],
42                "brokerAddr": "127.0.0.1:10911"
43            })
44        );
45
46        let decoded: TopicList = serde_json::from_value(value).expect("deserialize topic list");
47        assert_eq!(decoded.topic_list, body.topic_list);
48        assert_eq!(decoded.broker_addr, body.broker_addr);
49    }
50}