Skip to main content

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