Skip to main content

rocketmq_remoting/protocol/header/
exchange_ha_info_response_header.rs

1use cheetah_string::CheetahString;
2use rocketmq_macros::RequestHeaderCodecV2;
3// Copyright 2023 The RocketMQ Rust Authors
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Serialize, Deserialize, RequestHeaderCodecV2)]
20#[serde(rename_all = "camelCase")]
21pub struct ExchangeHaInfoResponseHeader {
22    pub master_ha_address: Option<CheetahString>,
23    pub master_flush_offset: Option<i64>,
24    pub master_address: Option<CheetahString>,
25}
26
27#[cfg(test)]
28mod tests {
29    use cheetah_string::CheetahString;
30
31    use super::*;
32
33    fn create_cheetah_string(value: &str) -> Option<CheetahString> {
34        Some(CheetahString::from(value))
35    }
36
37    #[test]
38    fn serialize_with_all_fields_set() {
39        let header = ExchangeHaInfoResponseHeader {
40            master_ha_address: create_cheetah_string("127.0.0.1:10911"),
41            master_flush_offset: Some(1024),
42            master_address: create_cheetah_string("127.0.0.1"),
43        };
44
45        let serialized = serde_json::to_string(&header).unwrap();
46        assert!(serialized.contains("\"masterHaAddress\":\"127.0.0.1:10911\""));
47        assert!(serialized.contains("\"masterFlushOffset\":1024"));
48        assert!(serialized.contains("\"masterAddress\":\"127.0.0.1\""));
49    }
50}