Skip to main content

rocketmq_protocol/protocol/header/
change_invisible_time_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(Serialize, Deserialize, Debug, Default, RequestHeaderCodec)]
20#[serde(rename_all = "camelCase")]
21#[header(
22    type_id = "rocketmq_protocol::protocol::header::change_invisible_time_response_header::ChangeInvisibleTimeResponseHeader",
23    java_class = "org.apache.rocketmq.remoting.protocol.header.ChangeInvisibleTimeResponseHeader"
24)]
25pub struct ChangeInvisibleTimeResponseHeader {
26    #[header(required, range = "i64")]
27    pub pop_time: u64,
28
29    #[header(required)]
30    pub revive_qid: i32,
31
32    #[header(required)]
33    pub invisible_time: i64,
34}
35
36#[cfg(test)]
37mod tests {
38    use serde_json;
39
40    use super::*;
41
42    #[test]
43    fn change_invisible_time_response_header_serialize() {
44        let header = ChangeInvisibleTimeResponseHeader {
45            pop_time: 123456789,
46            revive_qid: 1,
47            invisible_time: 987654321,
48        };
49        let serialized = serde_json::to_string(&header).unwrap();
50        assert_eq!(
51            serialized,
52            r#"{"popTime":123456789,"reviveQid":1,"invisibleTime":987654321}"#
53        );
54    }
55
56    #[test]
57    fn change_invisible_time_response_header_deserialize() {
58        let json = r#"{"popTime":123456789,"reviveQid":1,"invisibleTime":987654321}"#;
59        let header: ChangeInvisibleTimeResponseHeader = serde_json::from_str(json).unwrap();
60        assert_eq!(header.pop_time, 123456789);
61        assert_eq!(header.revive_qid, 1);
62        assert_eq!(header.invisible_time, 987654321);
63    }
64}