kacrab_protocol/generated/
offset_for_leader_epoch_response.rs1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct OffsetForLeaderEpochResponseData {
17 pub throttle_time_ms: i32,
20 pub topics: Vec<OffsetForLeaderTopicResult>,
22 pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for OffsetForLeaderEpochResponseData {
25 fn default() -> Self {
26 Self {
27 throttle_time_ms: 0_i32,
28 topics: Vec::new(),
29 _unknown_tagged_fields: Vec::new(),
30 }
31 }
32}
33impl OffsetForLeaderEpochResponseData {
34 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35 self.throttle_time_ms = value;
36 self
37 }
38 pub fn with_topics(mut self, value: Vec<OffsetForLeaderTopicResult>) -> Self {
39 self.topics = value;
40 self
41 }
42 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43 if version < 2 || version > 4 {
44 return Err(UnsupportedVersion::new(23, version).into());
45 }
46 let throttle_time_ms;
47 let topics;
48 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49 throttle_time_ms = read_i32(buf)?;
50 if version >= 4 {
51 topics = {
52 let len = read_compact_array_length(buf)?;
53 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
54 for _ in 0..len {
55 arr.push(OffsetForLeaderTopicResult::read(buf, version)?);
56 }
57 arr
58 };
59 } else {
60 topics = {
61 let len = read_array_length(buf)?;
62 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
63 for _ in 0..len {
64 arr.push(OffsetForLeaderTopicResult::read(buf, version)?);
65 }
66 arr
67 };
68 }
69 if version >= 4 {
70 let tagged_fields = read_tagged_fields(buf)?;
71 for field in &tagged_fields {
72 match field.tag {
73 _ => {
74 _unknown_tagged_fields.push(field.clone());
75 },
76 }
77 }
78 }
79 Ok(Self {
80 throttle_time_ms,
81 topics,
82 _unknown_tagged_fields,
83 })
84 }
85 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
86 if version < 2 || version > 4 {
87 return Err(UnsupportedVersion::new(23, version).into());
88 }
89 write_i32(buf, self.throttle_time_ms);
90 if version >= 4 {
91 write_compact_array_length(buf, self.topics.len() as i32);
92 for el in &self.topics {
93 el.write(buf, version)?;
94 }
95 } else {
96 write_array_length(buf, self.topics.len() as i32);
97 for el in &self.topics {
98 el.write(buf, version)?;
99 }
100 }
101 if version >= 4 {
102 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
103 all_tags.sort_by_key(|f| f.tag);
104 write_tagged_fields(buf, &all_tags)?;
105 }
106 Ok(())
107 }
108 pub fn encoded_len(&self, version: i16) -> Result<usize> {
109 if version < 2 || version > 4 {
110 return Err(UnsupportedVersion::new(23, version).into());
111 }
112 let mut len: usize = 0;
113 len += 4;
114 if version >= 4 {
115 len += compact_array_length_len(self.topics.len() as i32);
116 for el in &self.topics {
117 len += el.encoded_len(version)?;
118 }
119 } else {
120 len += array_length_len();
121 for el in &self.topics {
122 len += el.encoded_len(version)?;
123 }
124 }
125 if version >= 4 {
126 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
127 all_tags.sort_by_key(|f| f.tag);
128 len += tagged_fields_len(&all_tags)?;
129 }
130 Ok(len)
131 }
132}
133#[derive(Debug, Clone, PartialEq)]
134pub struct OffsetForLeaderTopicResult {
135 pub topic: KafkaString,
137 pub partitions: Vec<EpochEndOffset>,
139 pub _unknown_tagged_fields: Vec<RawTaggedField>,
140}
141impl Default for OffsetForLeaderTopicResult {
142 fn default() -> Self {
143 Self {
144 topic: KafkaString::default(),
145 partitions: Vec::new(),
146 _unknown_tagged_fields: Vec::new(),
147 }
148 }
149}
150impl OffsetForLeaderTopicResult {
151 pub fn with_topic(mut self, value: KafkaString) -> Self {
152 self.topic = value;
153 self
154 }
155 pub fn with_partitions(mut self, value: Vec<EpochEndOffset>) -> Self {
156 self.partitions = value;
157 self
158 }
159 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
160 let topic;
161 let partitions;
162 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
163 if version >= 4 {
164 topic = read_compact_string(buf)?;
165 } else {
166 topic = read_string(buf)?;
167 }
168 if version >= 4 {
169 partitions = {
170 let len = read_compact_array_length(buf)?;
171 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
172 for _ in 0..len {
173 arr.push(EpochEndOffset::read(buf, version)?);
174 }
175 arr
176 };
177 } else {
178 partitions = {
179 let len = read_array_length(buf)?;
180 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
181 for _ in 0..len {
182 arr.push(EpochEndOffset::read(buf, version)?);
183 }
184 arr
185 };
186 }
187 if version >= 4 {
188 let tagged_fields = read_tagged_fields(buf)?;
189 for field in &tagged_fields {
190 match field.tag {
191 _ => {
192 _unknown_tagged_fields.push(field.clone());
193 },
194 }
195 }
196 }
197 Ok(Self {
198 topic,
199 partitions,
200 _unknown_tagged_fields,
201 })
202 }
203 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
204 if version >= 4 {
205 write_compact_string(buf, &self.topic)?;
206 } else {
207 write_string(buf, &self.topic)?;
208 }
209 if version >= 4 {
210 write_compact_array_length(buf, self.partitions.len() as i32);
211 for el in &self.partitions {
212 el.write(buf, version)?;
213 }
214 } else {
215 write_array_length(buf, self.partitions.len() as i32);
216 for el in &self.partitions {
217 el.write(buf, version)?;
218 }
219 }
220 if version >= 4 {
221 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
222 all_tags.sort_by_key(|f| f.tag);
223 write_tagged_fields(buf, &all_tags)?;
224 }
225 Ok(())
226 }
227 pub fn encoded_len(&self, version: i16) -> Result<usize> {
228 let mut len: usize = 0;
229 if version >= 4 {
230 len += compact_string_len(&self.topic)?;
231 } else {
232 len += string_len(&self.topic)?;
233 }
234 if version >= 4 {
235 len += compact_array_length_len(self.partitions.len() as i32);
236 for el in &self.partitions {
237 len += el.encoded_len(version)?;
238 }
239 } else {
240 len += array_length_len();
241 for el in &self.partitions {
242 len += el.encoded_len(version)?;
243 }
244 }
245 if version >= 4 {
246 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
247 all_tags.sort_by_key(|f| f.tag);
248 len += tagged_fields_len(&all_tags)?;
249 }
250 Ok(len)
251 }
252}
253#[derive(Debug, Clone, PartialEq)]
254pub struct EpochEndOffset {
255 pub error_code: i16,
257 pub partition: i32,
259 pub leader_epoch: i32,
261 pub end_offset: i64,
263 pub _unknown_tagged_fields: Vec<RawTaggedField>,
264}
265impl Default for EpochEndOffset {
266 fn default() -> Self {
267 Self {
268 error_code: 0_i16,
269 partition: 0_i32,
270 leader_epoch: -1i32,
271 end_offset: -1i64,
272 _unknown_tagged_fields: Vec::new(),
273 }
274 }
275}
276impl EpochEndOffset {
277 pub fn with_error_code(mut self, value: i16) -> Self {
278 self.error_code = value;
279 self
280 }
281 pub fn with_partition(mut self, value: i32) -> Self {
282 self.partition = value;
283 self
284 }
285 pub fn with_leader_epoch(mut self, value: i32) -> Self {
286 self.leader_epoch = value;
287 self
288 }
289 pub fn with_end_offset(mut self, value: i64) -> Self {
290 self.end_offset = value;
291 self
292 }
293 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
294 let error_code;
295 let partition;
296 let leader_epoch;
297 let end_offset;
298 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
299 error_code = read_i16(buf)?;
300 partition = read_i32(buf)?;
301 leader_epoch = read_i32(buf)?;
302 end_offset = read_i64(buf)?;
303 if version >= 4 {
304 let tagged_fields = read_tagged_fields(buf)?;
305 for field in &tagged_fields {
306 match field.tag {
307 _ => {
308 _unknown_tagged_fields.push(field.clone());
309 },
310 }
311 }
312 }
313 Ok(Self {
314 error_code,
315 partition,
316 leader_epoch,
317 end_offset,
318 _unknown_tagged_fields,
319 })
320 }
321 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
322 write_i16(buf, self.error_code);
323 write_i32(buf, self.partition);
324 write_i32(buf, self.leader_epoch);
325 write_i64(buf, self.end_offset);
326 if version >= 4 {
327 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
328 all_tags.sort_by_key(|f| f.tag);
329 write_tagged_fields(buf, &all_tags)?;
330 }
331 Ok(())
332 }
333 pub fn encoded_len(&self, version: i16) -> Result<usize> {
334 let mut len: usize = 0;
335 len += 2;
336 len += 4;
337 len += 4;
338 len += 8;
339 if version >= 4 {
340 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
341 all_tags.sort_by_key(|f| f.tag);
342 len += tagged_fields_len(&all_tags)?;
343 }
344 Ok(len)
345 }
346}