Skip to main content

rocketmq_remoting/protocol/header/
reset_master_flush_offset_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 rocketmq_macros::RequestHeaderCodecV2;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Clone, Debug, Serialize, Deserialize, RequestHeaderCodecV2)]
20#[serde(rename_all = "camelCase")]
21pub struct ResetMasterFlushOffsetHeader {
22    pub master_flush_offset: Option<i64>,
23}
24
25#[cfg(test)]
26mod tests {
27    use crate::protocol::header::reset_master_flush_offset_header::ResetMasterFlushOffsetHeader;
28
29    #[test]
30    fn reset_master_flush_offset_header_serializes_correctly() {
31        let header = ResetMasterFlushOffsetHeader {
32            master_flush_offset: Some(4231),
33        };
34
35        let serialized = serde_json::to_string(&header).unwrap();
36        let expected = r#"{"masterFlushOffset":4231}"#;
37        assert_eq!(serialized, expected);
38    }
39
40    #[test]
41    fn reset_master_flush_offset_header_deserializes_correctly() {
42        let data = r#"{"masterFlushOffset":9527}"#;
43        let header: ResetMasterFlushOffsetHeader = serde_json::from_str(data).unwrap();
44        assert_eq!(header.master_flush_offset, Some(9527));
45    }
46}