kf_protocol_message/kf_code_gen/
fetch.rs

1/// WARNING: CODE GENERATED FILE
2/// * This file is generated by kfspec2code.
3/// * Any changes applied to this file will be lost when a new spec is generated.
4use std::fmt::Debug;
5use std::marker::PhantomData;
6
7use kf_protocol::Decoder;
8use kf_protocol::Encoder;
9
10use serde::{Deserialize, Serialize};
11
12use kf_protocol_api::ErrorCode;
13use kf_protocol_api::Isolation;
14use kf_protocol_api::Request;
15
16use kf_protocol_derive::Decode;
17use kf_protocol_derive::Encode;
18use kf_protocol_derive::KfDefault;
19
20// -----------------------------------
21// KfFetchRequest<R>
22// -----------------------------------
23
24#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
25pub struct KfFetchRequest<R>
26where
27    R: Encoder + Decoder + Default + Debug,
28{
29    /// The broker ID of the follower, of -1 if this request is from a consumer.
30    pub replica_id: i32,
31
32    /// The maximum time in milliseconds to wait for the response.
33    pub max_wait: i32,
34
35    /// The minimum bytes to accumulate in the response.
36    pub min_bytes: i32,
37
38    /// The maximum bytes to fetch.  See KIP-74 for cases where this limit may not be honored.
39    #[fluvio_kf(min_version = 3, ignorable)]
40    pub max_bytes: i32,
41
42    /// This setting controls the visibility of transactional records. Using READ_UNCOMMITTED
43    /// (isolation_level = 0) makes all records visible. With READ_COMMITTED (isolation_level = 1),
44    /// non-transactional and COMMITTED transactional records are visible. To be more concrete,
45    /// READ_COMMITTED returns all data from offsets smaller than the current LSO (last stable
46    /// offset), and enables the inclusion of the list of aborted transactions in the result, which
47    /// allows consumers to discard ABORTED transactional records
48    #[fluvio_kf(min_version = 4)]
49    pub isolation_level: Isolation,
50
51    /// The fetch session ID.
52    #[fluvio_kf(min_version = 7)]
53    pub session_id: i32,
54
55    /// The fetch session ID.
56    #[fluvio_kf(min_version = 7)]
57    pub epoch: i32,
58
59    /// The topics to fetch.
60    pub topics: Vec<FetchableTopic>,
61
62    /// In an incremental fetch request, the partitions to remove.
63    #[fluvio_kf(min_version = 7)]
64    pub forgotten: Vec<ForgottenTopic>,
65
66    pub data: PhantomData<R>,
67}
68
69#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
70pub struct FetchableTopic {
71    /// The name of the topic to fetch.
72    pub name: String,
73
74    /// The partitions to fetch.
75    pub fetch_partitions: Vec<FetchPartition>,
76}
77
78#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
79pub struct ForgottenTopic {
80    /// The partition name.
81    #[fluvio_kf(min_version = 7)]
82    pub name: String,
83
84    /// The partitions indexes to forget.
85    #[fluvio_kf(min_version = 7)]
86    pub forgotten_partition_indexes: Vec<i32>,
87}
88
89#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
90pub struct FetchPartition {
91    /// The partition index.
92    pub partition_index: i32,
93
94    /// The current leader epoch of the partition.
95    #[fluvio_kf(min_version = 9, ignorable)]
96    pub current_leader_epoch: i32,
97
98    /// The message offset.
99    pub fetch_offset: i64,
100
101    /// The earliest available offset of the follower replica.  The field is only used when the
102    /// request is sent by the follower.
103    #[fluvio_kf(min_version = 5)]
104    pub log_start_offset: i64,
105
106    /// The maximum bytes to fetch from this partition.  See KIP-74 for cases where this limit may
107    /// not be honored.
108    pub max_bytes: i32,
109}
110
111// -----------------------------------
112// KfFetchResponse<R>
113// -----------------------------------
114
115#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
116pub struct KfFetchResponse<R>
117where
118    R: Encoder + Decoder + Default + Debug,
119{
120    /// The duration in milliseconds for which the request was throttled due to a quota violation,
121    /// or zero if the request did not violate any quota.
122    #[fluvio_kf(min_version = 1, ignorable)]
123    pub throttle_time_ms: i32,
124
125    /// The top level response error code.
126    #[fluvio_kf(min_version = 7)]
127    pub error_code: ErrorCode,
128
129    /// The fetch session ID, or 0 if this is not part of a fetch session.
130    #[fluvio_kf(min_version = 7)]
131    pub session_id: i32,
132
133    /// The response topics.
134    pub topics: Vec<FetchableTopicResponse<R>>
135}
136
137impl <R>KfFetchResponse<R> 
138    where R: Encoder + Decoder + Default + Debug {
139
140    pub fn find_partition(self,topic: &str,partition: i32) -> Option<FetchablePartitionResponse<R>> {
141
142        for topic_res in self.topics {
143            if topic_res.name == topic {
144                for partition_res in topic_res.partitions {
145                    if partition_res.partition_index == partition {
146                        return Some(partition_res);
147                    }
148                }
149            }
150        }
151    
152        None
153    
154    }
155        
156
157}
158
159
160#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
161pub struct FetchableTopicResponse<R>
162where
163    R: Encoder + Decoder + Default + Debug,
164{
165    /// The topic name.
166    pub name: String,
167
168    /// The topic partitions.
169    pub partitions: Vec<FetchablePartitionResponse<R>>,
170    pub data: PhantomData<R>,
171}
172
173#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
174pub struct FetchablePartitionResponse<R>
175    where
176        R: Encoder + Decoder + Default + Debug,
177{
178    /// The partiiton index.
179    pub partition_index: i32,
180
181    /// The error code, or 0 if there was no fetch error.
182    pub error_code: ErrorCode,
183
184    /// The current high water mark.
185    pub high_watermark: i64,
186
187    /// The last stable offset (or LSO) of the partition. This is the last offset such that the
188    /// state of all transactional records prior to this offset have been decided (ABORTED or
189    /// COMMITTED)
190    #[fluvio_kf(min_version = 4, ignorable)]
191    pub last_stable_offset: i64,
192
193    /// The current log start offset.
194    #[fluvio_kf(min_version = 5, ignorable)]
195    pub log_start_offset: i64,
196
197    /// The aborted transactions.
198    #[fluvio_kf(min_version = 4)]
199    pub aborted: Option<Vec<AbortedTransaction>>,
200
201    /// The record data.
202    pub records: R,
203}
204
205#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
206pub struct AbortedTransaction {
207    /// The producer id associated with the aborted transaction.
208    #[fluvio_kf(min_version = 4)]
209    pub producer_id: i64,
210
211    /// The first offset in the aborted transaction.
212    #[fluvio_kf(min_version = 4)]
213    pub first_offset: i64,
214}
215
216// -----------------------------------
217// Implementation - KfFetchRequest<R>
218// -----------------------------------
219
220impl<R> Request for KfFetchRequest<R>
221    where R: Debug + Decoder + Encoder
222{
223    const API_KEY: u16 = 1;
224
225    const MIN_API_VERSION: i16 = 0;
226    const MAX_API_VERSION: i16 = 10;
227    const DEFAULT_API_VERSION: i16 = 10;
228
229    type Response = KfFetchResponse<R>;
230}