kacrab_protocol/generated/
txn_offset_commit_request.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 TxnOffsetCommitRequestData {
17 pub transactional_id: KafkaString,
19 pub group_id: KafkaString,
21 pub producer_id: i64,
23 pub producer_epoch: i16,
25 pub generation_id: i32,
27 pub member_id: KafkaString,
29 pub group_instance_id: Option<KafkaString>,
31 pub topics: Vec<TxnOffsetCommitRequestTopic>,
33 pub _unknown_tagged_fields: Vec<RawTaggedField>,
34}
35impl Default for TxnOffsetCommitRequestData {
36 fn default() -> Self {
37 Self {
38 transactional_id: KafkaString::default(),
39 group_id: KafkaString::default(),
40 producer_id: 0_i64,
41 producer_epoch: 0_i16,
42 generation_id: -1i32,
43 member_id: KafkaString::default(),
44 group_instance_id: None,
45 topics: Vec::new(),
46 _unknown_tagged_fields: Vec::new(),
47 }
48 }
49}
50impl TxnOffsetCommitRequestData {
51 pub fn with_transactional_id(mut self, value: KafkaString) -> Self {
52 self.transactional_id = value;
53 self
54 }
55 pub fn with_group_id(mut self, value: KafkaString) -> Self {
56 self.group_id = value;
57 self
58 }
59 pub fn with_producer_id(mut self, value: i64) -> Self {
60 self.producer_id = value;
61 self
62 }
63 pub fn with_producer_epoch(mut self, value: i16) -> Self {
64 self.producer_epoch = value;
65 self
66 }
67 pub fn with_generation_id(mut self, value: i32) -> Self {
68 self.generation_id = value;
69 self
70 }
71 pub fn with_member_id(mut self, value: KafkaString) -> Self {
72 self.member_id = value;
73 self
74 }
75 pub fn with_group_instance_id(mut self, value: Option<KafkaString>) -> Self {
76 self.group_instance_id = value;
77 self
78 }
79 pub fn with_topics(mut self, value: Vec<TxnOffsetCommitRequestTopic>) -> Self {
80 self.topics = value;
81 self
82 }
83 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
84 if version < 0 || version > 5 {
85 return Err(UnsupportedVersion::new(28, version).into());
86 }
87 let transactional_id;
88 let group_id;
89 let producer_id;
90 let producer_epoch;
91 let mut generation_id = -1i32;
92 let mut member_id = KafkaString::default();
93 let mut group_instance_id = None;
94 let topics;
95 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
96 if version >= 3 {
97 transactional_id = read_compact_string(buf)?;
98 } else {
99 transactional_id = read_string(buf)?;
100 }
101 if version >= 3 {
102 group_id = read_compact_string(buf)?;
103 } else {
104 group_id = read_string(buf)?;
105 }
106 producer_id = read_i64(buf)?;
107 producer_epoch = read_i16(buf)?;
108 if version >= 3 {
109 generation_id = read_i32(buf)?;
110 }
111 if version >= 3 {
112 member_id = read_compact_string(buf)?;
113 }
114 if version >= 3 {
115 group_instance_id = read_compact_nullable_string(buf)?;
116 }
117 if version >= 3 {
118 topics = {
119 let len = read_compact_array_length(buf)?;
120 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
121 for _ in 0..len {
122 arr.push(TxnOffsetCommitRequestTopic::read(buf, version)?);
123 }
124 arr
125 };
126 } else {
127 topics = {
128 let len = read_array_length(buf)?;
129 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
130 for _ in 0..len {
131 arr.push(TxnOffsetCommitRequestTopic::read(buf, version)?);
132 }
133 arr
134 };
135 }
136 if version >= 3 {
137 let tagged_fields = read_tagged_fields(buf)?;
138 for field in &tagged_fields {
139 match field.tag {
140 _ => {
141 _unknown_tagged_fields.push(field.clone());
142 },
143 }
144 }
145 }
146 Ok(Self {
147 transactional_id,
148 group_id,
149 producer_id,
150 producer_epoch,
151 generation_id,
152 member_id,
153 group_instance_id,
154 topics,
155 _unknown_tagged_fields,
156 })
157 }
158 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
159 if version < 0 || version > 5 {
160 return Err(UnsupportedVersion::new(28, version).into());
161 }
162 if version >= 3 {
163 write_compact_string(buf, &self.transactional_id)?;
164 } else {
165 write_string(buf, &self.transactional_id)?;
166 }
167 if version >= 3 {
168 write_compact_string(buf, &self.group_id)?;
169 } else {
170 write_string(buf, &self.group_id)?;
171 }
172 write_i64(buf, self.producer_id);
173 write_i16(buf, self.producer_epoch);
174 if version >= 3 {
175 write_i32(buf, self.generation_id);
176 } else if self.generation_id != -1i32 {
177 return Err(UnsupportedFieldVersion::new(28, "generation_id", version).into());
178 }
179 if version >= 3 {
180 write_compact_string(buf, &self.member_id)?;
181 } else if self.member_id != KafkaString::default() {
182 return Err(UnsupportedFieldVersion::new(28, "member_id", version).into());
183 }
184 if version >= 3 {
185 write_compact_nullable_string(buf, self.group_instance_id.as_ref())?;
186 } else if self.group_instance_id != None {
187 return Err(UnsupportedFieldVersion::new(28, "group_instance_id", version).into());
188 }
189 if version >= 3 {
190 write_compact_array_length(buf, self.topics.len() as i32);
191 for el in &self.topics {
192 el.write(buf, version)?;
193 }
194 } else {
195 write_array_length(buf, self.topics.len() as i32);
196 for el in &self.topics {
197 el.write(buf, version)?;
198 }
199 }
200 if version >= 3 {
201 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
202 all_tags.sort_by_key(|f| f.tag);
203 write_tagged_fields(buf, &all_tags)?;
204 }
205 Ok(())
206 }
207 pub fn encoded_len(&self, version: i16) -> Result<usize> {
208 if version < 0 || version > 5 {
209 return Err(UnsupportedVersion::new(28, version).into());
210 }
211 let mut len: usize = 0;
212 if version >= 3 {
213 len += compact_string_len(&self.transactional_id)?;
214 } else {
215 len += string_len(&self.transactional_id)?;
216 }
217 if version >= 3 {
218 len += compact_string_len(&self.group_id)?;
219 } else {
220 len += string_len(&self.group_id)?;
221 }
222 len += 8;
223 len += 2;
224 if version >= 3 {
225 len += 4;
226 } else if self.generation_id != -1i32 {
227 return Err(UnsupportedFieldVersion::new(28, "generation_id", version).into());
228 }
229 if version >= 3 {
230 len += compact_string_len(&self.member_id)?;
231 } else if self.member_id != KafkaString::default() {
232 return Err(UnsupportedFieldVersion::new(28, "member_id", version).into());
233 }
234 if version >= 3 {
235 len += compact_nullable_string_len(self.group_instance_id.as_ref())?;
236 } else if self.group_instance_id != None {
237 return Err(UnsupportedFieldVersion::new(28, "group_instance_id", version).into());
238 }
239 if version >= 3 {
240 len += compact_array_length_len(self.topics.len() as i32);
241 for el in &self.topics {
242 len += el.encoded_len(version)?;
243 }
244 } else {
245 len += array_length_len();
246 for el in &self.topics {
247 len += el.encoded_len(version)?;
248 }
249 }
250 if version >= 3 {
251 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
252 all_tags.sort_by_key(|f| f.tag);
253 len += tagged_fields_len(&all_tags)?;
254 }
255 Ok(len)
256 }
257}
258#[derive(Debug, Clone, PartialEq)]
259pub struct TxnOffsetCommitRequestTopic {
260 pub name: KafkaString,
262 pub partitions: Vec<TxnOffsetCommitRequestPartition>,
264 pub _unknown_tagged_fields: Vec<RawTaggedField>,
265}
266impl Default for TxnOffsetCommitRequestTopic {
267 fn default() -> Self {
268 Self {
269 name: KafkaString::default(),
270 partitions: Vec::new(),
271 _unknown_tagged_fields: Vec::new(),
272 }
273 }
274}
275impl TxnOffsetCommitRequestTopic {
276 pub fn with_name(mut self, value: KafkaString) -> Self {
277 self.name = value;
278 self
279 }
280 pub fn with_partitions(mut self, value: Vec<TxnOffsetCommitRequestPartition>) -> Self {
281 self.partitions = value;
282 self
283 }
284 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
285 let name;
286 let partitions;
287 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
288 if version >= 3 {
289 name = read_compact_string(buf)?;
290 } else {
291 name = read_string(buf)?;
292 }
293 if version >= 3 {
294 partitions = {
295 let len = read_compact_array_length(buf)?;
296 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
297 for _ in 0..len {
298 arr.push(TxnOffsetCommitRequestPartition::read(buf, version)?);
299 }
300 arr
301 };
302 } else {
303 partitions = {
304 let len = read_array_length(buf)?;
305 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
306 for _ in 0..len {
307 arr.push(TxnOffsetCommitRequestPartition::read(buf, version)?);
308 }
309 arr
310 };
311 }
312 if version >= 3 {
313 let tagged_fields = read_tagged_fields(buf)?;
314 for field in &tagged_fields {
315 match field.tag {
316 _ => {
317 _unknown_tagged_fields.push(field.clone());
318 },
319 }
320 }
321 }
322 Ok(Self {
323 name,
324 partitions,
325 _unknown_tagged_fields,
326 })
327 }
328 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
329 if version >= 3 {
330 write_compact_string(buf, &self.name)?;
331 } else {
332 write_string(buf, &self.name)?;
333 }
334 if version >= 3 {
335 write_compact_array_length(buf, self.partitions.len() as i32);
336 for el in &self.partitions {
337 el.write(buf, version)?;
338 }
339 } else {
340 write_array_length(buf, self.partitions.len() as i32);
341 for el in &self.partitions {
342 el.write(buf, version)?;
343 }
344 }
345 if version >= 3 {
346 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
347 all_tags.sort_by_key(|f| f.tag);
348 write_tagged_fields(buf, &all_tags)?;
349 }
350 Ok(())
351 }
352 pub fn encoded_len(&self, version: i16) -> Result<usize> {
353 let mut len: usize = 0;
354 if version >= 3 {
355 len += compact_string_len(&self.name)?;
356 } else {
357 len += string_len(&self.name)?;
358 }
359 if version >= 3 {
360 len += compact_array_length_len(self.partitions.len() as i32);
361 for el in &self.partitions {
362 len += el.encoded_len(version)?;
363 }
364 } else {
365 len += array_length_len();
366 for el in &self.partitions {
367 len += el.encoded_len(version)?;
368 }
369 }
370 if version >= 3 {
371 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
372 all_tags.sort_by_key(|f| f.tag);
373 len += tagged_fields_len(&all_tags)?;
374 }
375 Ok(len)
376 }
377}
378#[derive(Debug, Clone, PartialEq)]
379pub struct TxnOffsetCommitRequestPartition {
380 pub partition_index: i32,
382 pub committed_offset: i64,
384 pub committed_leader_epoch: i32,
386 pub committed_metadata: Option<KafkaString>,
388 pub _unknown_tagged_fields: Vec<RawTaggedField>,
389}
390impl Default for TxnOffsetCommitRequestPartition {
391 fn default() -> Self {
392 Self {
393 partition_index: 0_i32,
394 committed_offset: 0_i64,
395 committed_leader_epoch: -1i32,
396 committed_metadata: None,
397 _unknown_tagged_fields: Vec::new(),
398 }
399 }
400}
401impl TxnOffsetCommitRequestPartition {
402 pub fn with_partition_index(mut self, value: i32) -> Self {
403 self.partition_index = value;
404 self
405 }
406 pub fn with_committed_offset(mut self, value: i64) -> Self {
407 self.committed_offset = value;
408 self
409 }
410 pub fn with_committed_leader_epoch(mut self, value: i32) -> Self {
411 self.committed_leader_epoch = value;
412 self
413 }
414 pub fn with_committed_metadata(mut self, value: Option<KafkaString>) -> Self {
415 self.committed_metadata = value;
416 self
417 }
418 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
419 let partition_index;
420 let committed_offset;
421 let mut committed_leader_epoch = -1i32;
422 let committed_metadata;
423 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
424 partition_index = read_i32(buf)?;
425 committed_offset = read_i64(buf)?;
426 if version >= 2 {
427 committed_leader_epoch = read_i32(buf)?;
428 }
429 if version >= 3 {
430 committed_metadata = read_compact_nullable_string(buf)?;
431 } else {
432 committed_metadata = read_nullable_string(buf)?;
433 }
434 if version >= 3 {
435 let tagged_fields = read_tagged_fields(buf)?;
436 for field in &tagged_fields {
437 match field.tag {
438 _ => {
439 _unknown_tagged_fields.push(field.clone());
440 },
441 }
442 }
443 }
444 Ok(Self {
445 partition_index,
446 committed_offset,
447 committed_leader_epoch,
448 committed_metadata,
449 _unknown_tagged_fields,
450 })
451 }
452 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
453 write_i32(buf, self.partition_index);
454 write_i64(buf, self.committed_offset);
455 if version >= 2 {
456 write_i32(buf, self.committed_leader_epoch);
457 } else if self.committed_leader_epoch != -1i32 {
458 return Err(UnsupportedFieldVersion::new(28, "committed_leader_epoch", version).into());
459 }
460 if version >= 3 {
461 write_compact_nullable_string(buf, self.committed_metadata.as_ref())?;
462 } else {
463 write_nullable_string(buf, self.committed_metadata.as_ref())?;
464 }
465 if version >= 3 {
466 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
467 all_tags.sort_by_key(|f| f.tag);
468 write_tagged_fields(buf, &all_tags)?;
469 }
470 Ok(())
471 }
472 pub fn encoded_len(&self, version: i16) -> Result<usize> {
473 let mut len: usize = 0;
474 len += 4;
475 len += 8;
476 if version >= 2 {
477 len += 4;
478 } else if self.committed_leader_epoch != -1i32 {
479 return Err(UnsupportedFieldVersion::new(28, "committed_leader_epoch", version).into());
480 }
481 if version >= 3 {
482 len += compact_nullable_string_len(self.committed_metadata.as_ref())?;
483 } else {
484 len += nullable_string_len(self.committed_metadata.as_ref())?;
485 }
486 if version >= 3 {
487 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
488 all_tags.sort_by_key(|f| f.tag);
489 len += tagged_fields_len(&all_tags)?;
490 }
491 Ok(len)
492 }
493}