rocketmq_remoting/protocol/header/
exchange_ha_info_response_header.rs

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