kafka_client_engine/admin/list_offsets/
model.rs1use kafka_client_core::{
4 AdminListOffsetSpec, AdminListOffsetTarget, AdminListOffsetsPlan, AdminListOffsetsPlanError,
5};
6
7use crate::config::ConsumerReadIsolation;
8
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub enum AdminListOffsetsRequestSpec {
12 Earliest,
14 Latest,
16 MaxTimestamp,
18 EarliestLocal,
20 LatestTiered,
22 EarliestPendingUpload,
24 Timestamp(i64),
26}
27
28#[derive(Clone, Debug, Eq, PartialEq)]
30pub struct AdminListOffsetsRequestTarget {
31 topic: String,
32 partition: i32,
33 spec: AdminListOffsetsRequestSpec,
34 current_leader_epoch: Option<i32>,
35}
36
37impl AdminListOffsetsRequestTarget {
38 pub const fn new(topic: String, partition: i32, spec: AdminListOffsetsRequestSpec) -> Self {
40 Self {
41 topic,
42 partition,
43 spec,
44 current_leader_epoch: None,
45 }
46 }
47
48 pub const fn current_leader_epoch(mut self, current_leader_epoch: i32) -> Self {
50 self.current_leader_epoch = Some(current_leader_epoch);
51 self
52 }
53
54 fn canonicalize(mut self) -> Self {
55 self.topic = self.topic.into_boxed_str().into_string();
56 self
57 }
58
59 fn into_core(self) -> AdminListOffsetTarget {
60 let spec = match self.spec {
61 AdminListOffsetsRequestSpec::Earliest => AdminListOffsetSpec::Earliest,
62 AdminListOffsetsRequestSpec::Latest => AdminListOffsetSpec::Latest,
63 AdminListOffsetsRequestSpec::MaxTimestamp => AdminListOffsetSpec::MaxTimestamp,
64 AdminListOffsetsRequestSpec::EarliestLocal => AdminListOffsetSpec::EarliestLocal,
65 AdminListOffsetsRequestSpec::LatestTiered => AdminListOffsetSpec::LatestTiered,
66 AdminListOffsetsRequestSpec::EarliestPendingUpload => {
67 AdminListOffsetSpec::EarliestPendingUpload
68 }
69 AdminListOffsetsRequestSpec::Timestamp(timestamp) => {
70 AdminListOffsetSpec::Timestamp(timestamp)
71 }
72 };
73 AdminListOffsetTarget::new(self.topic, self.partition, spec)
74 .with_current_leader_epoch(self.current_leader_epoch)
75 }
76}
77
78#[derive(Clone, Debug, Eq, PartialEq)]
80pub struct AdminListOffsetsRequest {
81 targets: Vec<AdminListOffsetsRequestTarget>,
82 read_isolation: ConsumerReadIsolation,
83}
84
85impl AdminListOffsetsRequest {
86 pub const fn new(targets: Vec<AdminListOffsetsRequestTarget>) -> Self {
88 Self {
89 targets,
90 read_isolation: ConsumerReadIsolation::ReadUncommitted,
91 }
92 }
93
94 pub const fn with_read_isolation(mut self, read_isolation: ConsumerReadIsolation) -> Self {
96 self.read_isolation = read_isolation;
97 self
98 }
99
100 pub(crate) fn canonicalize(mut self) -> Self {
101 self.targets = self
102 .targets
103 .into_iter()
104 .map(AdminListOffsetsRequestTarget::canonicalize)
105 .collect();
106 self.targets.shrink_to_fit();
107 self
108 }
109
110 pub(crate) fn into_plan(self) -> Result<AdminListOffsetsPlan, AdminListOffsetsPlanError> {
111 AdminListOffsetsPlan::with_read_isolation(
112 self.targets
113 .into_iter()
114 .map(AdminListOffsetsRequestTarget::into_core)
115 .collect(),
116 self.read_isolation.core(),
117 )
118 }
119}