Skip to main content

rocketmq_remoting/protocol/header/
search_offset_response_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(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
20pub struct SearchOffsetResponseHeader {
21    pub offset: i64,
22}
23
24#[cfg(test)]
25mod tests {
26    use serde_json;
27
28    use super::*;
29
30    #[test]
31    fn search_offset_response_header_display_format() {
32        let header = SearchOffsetResponseHeader { offset: 1234567890 };
33        assert_eq!(
34            format!("{:?}", header),
35            "SearchOffsetResponseHeader { offset: 1234567890 }"
36        );
37    }
38
39    #[test]
40    fn search_offset_response_header_serialize() {
41        let header = SearchOffsetResponseHeader { offset: 1234567890 };
42        let serialized = serde_json::to_string(&header).unwrap();
43        assert_eq!(serialized, r#"{"offset":1234567890}"#);
44    }
45
46    #[test]
47    fn search_offset_response_header_deserialize() {
48        let json = r#"{"offset":1234567890}"#;
49        let header: SearchOffsetResponseHeader = serde_json::from_str(json).unwrap();
50        assert_eq!(header.offset, 1234567890);
51    }
52
53    #[test]
54    fn search_offset_response_header_default() {
55        let header = SearchOffsetResponseHeader::default();
56        assert_eq!(header.offset, 0);
57    }
58}