Skip to main content

rocketmq_protocol/protocol/body/
batch_ack_message_request_body.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 cheetah_string::CheetahString;
16use serde::Deserialize;
17use serde::Serialize;
18
19use crate::protocol::body::batch_ack::BatchAck;
20
21#[derive(Debug, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23pub struct BatchAckMessageRequestBody {
24    pub broker_name: CheetahString,
25    pub acks: Vec<BatchAck>,
26}
27
28#[cfg(test)]
29mod tests {
30    use bitvec::prelude::*;
31    use cheetah_string::CheetahString;
32
33    use super::*;
34    use crate::protocol::body::batch_ack::SerializableBitVec;
35
36    #[test]
37    fn serde_round_trip_preserves_the_batch_ack_request() {
38        let body = BatchAckMessageRequestBody {
39            broker_name: CheetahString::from_static_str("broker1"),
40            acks: vec![BatchAck {
41                consumer_group: CheetahString::from_static_str("group1"),
42                topic: CheetahString::from_static_str("topic1"),
43                retry: CheetahString::from_static_str("1"),
44                start_offset: 100,
45                queue_id: 1,
46                revive_queue_id: 2,
47                pop_time: 123456789,
48                invisible_time: 987654321,
49                bit_set: SerializableBitVec(BitVec::from_element(8)),
50            }],
51        };
52
53        let encoded = serde_json::to_vec(&body).expect("serialize batch ACK request");
54        let decoded: BatchAckMessageRequestBody =
55            serde_json::from_slice(&encoded).expect("deserialize batch ACK request");
56        assert_eq!(decoded.broker_name, "broker1");
57        assert_eq!(decoded.acks.len(), 1);
58        assert_eq!(decoded.acks[0].consumer_group, "group1");
59    }
60}