Skip to main content

rocketmq_protocol/protocol/header/
get_max_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::RequestHeaderCodec;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodec)]
20#[header(
21    type_id = "rocketmq_protocol::protocol::header::get_max_offset_response_header::GetMaxOffsetResponseHeader",
22    java_class = "org.apache.rocketmq.remoting.protocol.header.GetMaxOffsetResponseHeader"
23)]
24pub struct GetMaxOffsetResponseHeader {
25    #[header(required)]
26    pub offset: i64,
27}
28
29#[cfg(test)]
30mod tests {
31    use std::collections::HashMap;
32
33    use cheetah_string::CheetahString;
34
35    use super::*;
36    use crate::protocol::command_custom_header::FromMap;
37
38    #[test]
39    fn get_max_offset_response_header_serialization() {
40        let header = GetMaxOffsetResponseHeader { offset: 12345 };
41        let json = serde_json::to_string(&header).unwrap();
42        assert_eq!(json, r#"{"offset":12345}"#);
43    }
44
45    #[test]
46    fn get_max_offset_response_header_deserialization() {
47        let json = r#"{"offset":12345}"#;
48        let header: GetMaxOffsetResponseHeader = serde_json::from_str(json).unwrap();
49        assert_eq!(header.offset, 12345);
50    }
51
52    #[test]
53    fn get_max_offset_response_header_from_map() {
54        let mut map = HashMap::new();
55        map.insert(CheetahString::from("offset"), CheetahString::from("12345"));
56        let header = <GetMaxOffsetResponseHeader as FromMap>::from(&map).unwrap();
57        assert_eq!(header.offset, 12345);
58    }
59}