rocketmq_client_rust/consumer/
pull_result.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18use rocketmq_common::common::message::message_ext::MessageExt;
19use rocketmq_rust::ArcMut;
20
21use crate::consumer::pull_status::PullStatus;
22
23pub struct PullResult {
24    pub(crate) pull_status: PullStatus,
25    pub(crate) next_begin_offset: u64,
26    pub(crate) min_offset: u64,
27    pub(crate) max_offset: u64,
28    pub(crate) msg_found_list: Option<Vec<ArcMut<MessageExt>>>,
29}
30
31impl PullResult {
32    pub fn new(
33        pull_status: PullStatus,
34        next_begin_offset: u64,
35        min_offset: u64,
36        max_offset: u64,
37        msg_found_list: Option<Vec<ArcMut<MessageExt>>>,
38    ) -> Self {
39        Self {
40            pull_status,
41            next_begin_offset,
42            min_offset,
43            max_offset,
44            msg_found_list,
45        }
46    }
47
48    #[inline]
49    pub fn pull_status(&self) -> &PullStatus {
50        &self.pull_status
51    }
52
53    #[inline]
54    pub fn next_begin_offset(&self) -> u64 {
55        self.next_begin_offset
56    }
57
58    #[inline]
59    pub fn min_offset(&self) -> u64 {
60        self.min_offset
61    }
62
63    #[inline]
64    pub fn max_offset(&self) -> u64 {
65        self.max_offset
66    }
67
68    #[inline]
69    pub fn msg_found_list(&self) -> &Option<Vec<ArcMut<MessageExt>>> {
70        &self.msg_found_list
71    }
72
73    #[inline]
74    pub fn set_msg_found_list(&mut self, msg_found_list: Option<Vec<ArcMut<MessageExt>>>) {
75        self.msg_found_list = msg_found_list;
76    }
77}
78
79impl std::fmt::Display for PullResult {
80    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81        write!(
82            f,
83            "PullResult [pull_status: {:?}, next_begin_offset: {}, min_offset: {}, max_offset: \
84             {}, msg_found_list: {}]",
85            self.pull_status,
86            self.next_begin_offset,
87            self.min_offset,
88            self.max_offset,
89            self.msg_found_list.as_ref().map_or(0, |v| v.len()),
90        )
91    }
92}