Skip to main content

rocketmq_client_rust/consumer/
pull_result.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_common::common::message::message_ext::MessageExt;
16use rocketmq_rust::ArcMut;
17
18use crate::consumer::pull_status::PullStatus;
19
20pub struct PullResult {
21    pub(crate) pull_status: PullStatus,
22    pub(crate) next_begin_offset: u64,
23    pub(crate) min_offset: u64,
24    pub(crate) max_offset: u64,
25    pub(crate) msg_found_list: Option<Vec<ArcMut<MessageExt>>>,
26}
27
28impl PullResult {
29    pub fn new(
30        pull_status: PullStatus,
31        next_begin_offset: u64,
32        min_offset: u64,
33        max_offset: u64,
34        msg_found_list: Option<Vec<ArcMut<MessageExt>>>,
35    ) -> Self {
36        Self {
37            pull_status,
38            next_begin_offset,
39            min_offset,
40            max_offset,
41            msg_found_list,
42        }
43    }
44
45    #[inline]
46    pub fn pull_status(&self) -> &PullStatus {
47        &self.pull_status
48    }
49
50    #[inline]
51    pub fn next_begin_offset(&self) -> u64 {
52        self.next_begin_offset
53    }
54
55    #[inline]
56    pub fn min_offset(&self) -> u64 {
57        self.min_offset
58    }
59
60    #[inline]
61    pub fn max_offset(&self) -> u64 {
62        self.max_offset
63    }
64
65    #[inline]
66    pub fn msg_found_list(&self) -> Option<&Vec<ArcMut<MessageExt>>> {
67        self.msg_found_list.as_ref()
68    }
69
70    #[inline]
71    pub fn set_msg_found_list(&mut self, msg_found_list: Option<Vec<ArcMut<MessageExt>>>) {
72        self.msg_found_list = msg_found_list;
73    }
74}
75
76impl std::fmt::Display for PullResult {
77    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78        write!(
79            f,
80            "PullResult [pull_status: {:?}, next_begin_offset: {}, min_offset: {}, max_offset: {}, msg_found_list: {}]",
81            self.pull_status,
82            self.next_begin_offset,
83            self.min_offset,
84            self.max_offset,
85            self.msg_found_list.as_ref().map_or(0, |v| v.len()),
86        )
87    }
88}