crabka_protocol/opt/rustwide/workdir/generated/
TxnOffsetCommitRequest.borrowed.rs1use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
3use crate::primitives::string_bytes::{
4 compact_nullable_string_len, compact_string_len, nullable_string_len,
5 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
6};
7use crate::primitives::string_bytes_borrowed::{
8 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
9 get_nullable_string_borrowed, get_string_borrowed,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
13use bytes::BufMut;
14pub const API_KEY: i16 = 28;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 5;
17pub const FLEXIBLE_MIN: i16 = 3;
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct TxnOffsetCommitRequest<'a> {
24 pub transactional_id: &'a str,
25 pub group_id: &'a str,
26 pub producer_id: i64,
27 pub producer_epoch: i16,
28 pub generation_id: i32,
29 pub member_id: &'a str,
30 pub group_instance_id: Option<&'a str>,
31 pub topics: Vec<TxnOffsetCommitRequestTopic<'a>>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for TxnOffsetCommitRequest<'_> {
35 fn default() -> Self {
36 Self {
37 transactional_id: "",
38 group_id: "",
39 producer_id: 0i64,
40 producer_epoch: 0i16,
41 generation_id: -1i32,
42 member_id: "",
43 group_instance_id: None,
44 topics: Vec::new(),
45 unknown_tagged_fields: Default::default(),
46 }
47 }
48}
49impl TxnOffsetCommitRequest<'_> {
50 pub fn to_owned(&self) -> crate::owned::txn_offset_commit_request::TxnOffsetCommitRequest {
51 crate::owned::txn_offset_commit_request::TxnOffsetCommitRequest {
52 transactional_id: (self.transactional_id).to_string(),
53 group_id: (self.group_id).to_string(),
54 producer_id: (self.producer_id),
55 producer_epoch: (self.producer_epoch),
56 generation_id: (self.generation_id),
57 member_id: (self.member_id).to_string(),
58 group_instance_id: (self.group_instance_id).map(std::string::ToString::to_string),
59 topics: (self.topics)
60 .iter()
61 .map(TxnOffsetCommitRequestTopic::to_owned)
62 .collect(),
63 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
64 }
65 }
66}
67impl Encode for TxnOffsetCommitRequest<'_> {
68 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
69 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
70 return Err(ProtocolError::UnsupportedVersion {
71 api_key: API_KEY,
72 version,
73 });
74 }
75 let flex = is_flexible(version);
76 if version >= 0 {
77 if flex {
78 put_compact_string(buf, self.transactional_id);
79 } else {
80 put_string(buf, self.transactional_id);
81 }
82 }
83 if version >= 0 {
84 if flex {
85 put_compact_string(buf, self.group_id);
86 } else {
87 put_string(buf, self.group_id);
88 }
89 }
90 if version >= 0 {
91 put_i64(buf, self.producer_id);
92 }
93 if version >= 0 {
94 put_i16(buf, self.producer_epoch);
95 }
96 if version >= 3 {
97 put_i32(buf, self.generation_id);
98 }
99 if version >= 3 {
100 if flex {
101 put_compact_string(buf, self.member_id);
102 } else {
103 put_string(buf, self.member_id);
104 }
105 }
106 if version >= 3 {
107 if flex {
108 put_compact_nullable_string(buf, self.group_instance_id);
109 } else {
110 put_nullable_string(buf, self.group_instance_id);
111 }
112 }
113 if version >= 0 {
114 {
115 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
116 for it in &self.topics {
117 it.encode(buf, version)?;
118 }
119 }
120 }
121 if flex {
122 let tagged = WriteTaggedFields::new();
123 tagged.write(buf, &self.unknown_tagged_fields);
124 }
125 Ok(())
126 }
127 fn encoded_len(&self, version: i16) -> usize {
128 let flex = is_flexible(version);
129 let mut n: usize = 0;
130 if version >= 0 {
131 n += if flex {
132 compact_string_len(self.transactional_id)
133 } else {
134 string_len(self.transactional_id)
135 };
136 }
137 if version >= 0 {
138 n += if flex {
139 compact_string_len(self.group_id)
140 } else {
141 string_len(self.group_id)
142 };
143 }
144 if version >= 0 {
145 n += 8;
146 }
147 if version >= 0 {
148 n += 2;
149 }
150 if version >= 3 {
151 n += 4;
152 }
153 if version >= 3 {
154 n += if flex {
155 compact_string_len(self.member_id)
156 } else {
157 string_len(self.member_id)
158 };
159 }
160 if version >= 3 {
161 n += if flex {
162 compact_nullable_string_len(self.group_instance_id)
163 } else {
164 nullable_string_len(self.group_instance_id)
165 };
166 }
167 if version >= 0 {
168 n += {
169 let prefix =
170 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
171 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
172 prefix + body
173 };
174 }
175 if flex {
176 let known_pairs: Vec<(u32, usize)> = Vec::new();
177 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
178 }
179 n
180 }
181}
182impl<'de> DecodeBorrow<'de> for TxnOffsetCommitRequest<'de> {
183 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
184 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
185 return Err(ProtocolError::UnsupportedVersion {
186 api_key: API_KEY,
187 version,
188 });
189 }
190 let flex = is_flexible(version);
191 let mut out = Self::default();
192 if version >= 0 {
193 out.transactional_id = if flex {
194 get_compact_string_borrowed(buf)?
195 } else {
196 get_string_borrowed(buf)?
197 };
198 }
199 if version >= 0 {
200 out.group_id = if flex {
201 get_compact_string_borrowed(buf)?
202 } else {
203 get_string_borrowed(buf)?
204 };
205 }
206 if version >= 0 {
207 out.producer_id = get_i64(buf)?;
208 }
209 if version >= 0 {
210 out.producer_epoch = get_i16(buf)?;
211 }
212 if version >= 3 {
213 out.generation_id = get_i32(buf)?;
214 }
215 if version >= 3 {
216 out.member_id = if flex {
217 get_compact_string_borrowed(buf)?
218 } else {
219 get_string_borrowed(buf)?
220 };
221 }
222 if version >= 3 {
223 out.group_instance_id = if flex {
224 get_compact_nullable_string_borrowed(buf)?
225 } else {
226 get_nullable_string_borrowed(buf)?
227 };
228 }
229 if version >= 0 {
230 out.topics = {
231 let n = crate::primitives::array::get_array_len(buf, flex)?;
232 let mut v = Vec::with_capacity(n);
233 for _ in 0..n {
234 v.push(TxnOffsetCommitRequestTopic::decode_borrow(buf, version)?);
235 }
236 v
237 };
238 }
239 if flex {
240 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
241 }
242 Ok(out)
243 }
244}
245#[cfg(test)]
246impl TxnOffsetCommitRequest<'_> {
247 #[must_use]
248 pub fn populated(version: i16) -> Self {
249 let mut m = Self::default();
250 if version >= 0 {
251 m.transactional_id = "x";
252 }
253 if version >= 0 {
254 m.group_id = "x";
255 }
256 if version >= 0 {
257 m.producer_id = 1i64;
258 }
259 if version >= 0 {
260 m.producer_epoch = 1i16;
261 }
262 if version >= 3 {
263 m.generation_id = 1i32;
264 }
265 if version >= 3 {
266 m.member_id = "x";
267 }
268 if version >= 3 {
269 m.group_instance_id = Some("x");
270 }
271 if version >= 0 {
272 m.topics = vec![TxnOffsetCommitRequestTopic::populated(version)];
273 }
274 m
275 }
276}
277#[derive(Debug, Clone, PartialEq, Eq, Default)]
278pub struct TxnOffsetCommitRequestTopic<'a> {
279 pub name: &'a str,
280 pub partitions: Vec<TxnOffsetCommitRequestPartition<'a>>,
281 pub unknown_tagged_fields: UnknownTaggedFields,
282}
283impl TxnOffsetCommitRequestTopic<'_> {
284 pub fn to_owned(&self) -> crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestTopic {
285 crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestTopic {
286 name: (self.name).to_string(),
287 partitions: (self.partitions)
288 .iter()
289 .map(TxnOffsetCommitRequestPartition::to_owned)
290 .collect(),
291 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
292 }
293 }
294}
295impl Encode for TxnOffsetCommitRequestTopic<'_> {
296 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
297 let flex = version >= 3;
298 if version >= 0 {
299 if flex {
300 put_compact_string(buf, self.name);
301 } else {
302 put_string(buf, self.name);
303 }
304 }
305 if version >= 0 {
306 {
307 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
308 for it in &self.partitions {
309 it.encode(buf, version)?;
310 }
311 }
312 }
313 if flex {
314 let tagged = WriteTaggedFields::new();
315 tagged.write(buf, &self.unknown_tagged_fields);
316 }
317 Ok(())
318 }
319 fn encoded_len(&self, version: i16) -> usize {
320 let flex = version >= 3;
321 let mut n: usize = 0;
322 if version >= 0 {
323 n += if flex {
324 compact_string_len(self.name)
325 } else {
326 string_len(self.name)
327 };
328 }
329 if version >= 0 {
330 n += {
331 let prefix =
332 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
333 let body: usize = (self.partitions)
334 .iter()
335 .map(|it| it.encoded_len(version))
336 .sum();
337 prefix + body
338 };
339 }
340 if flex {
341 let known_pairs: Vec<(u32, usize)> = Vec::new();
342 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
343 }
344 n
345 }
346}
347impl<'de> DecodeBorrow<'de> for TxnOffsetCommitRequestTopic<'de> {
348 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
349 let flex = version >= 3;
350 let mut out = Self::default();
351 if version >= 0 {
352 out.name = if flex {
353 get_compact_string_borrowed(buf)?
354 } else {
355 get_string_borrowed(buf)?
356 };
357 }
358 if version >= 0 {
359 out.partitions = {
360 let n = crate::primitives::array::get_array_len(buf, flex)?;
361 let mut v = Vec::with_capacity(n);
362 for _ in 0..n {
363 v.push(TxnOffsetCommitRequestPartition::decode_borrow(
364 buf, version,
365 )?);
366 }
367 v
368 };
369 }
370 if flex {
371 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
372 }
373 Ok(out)
374 }
375}
376#[cfg(test)]
377impl TxnOffsetCommitRequestTopic<'_> {
378 #[must_use]
379 pub fn populated(version: i16) -> Self {
380 let mut m = Self::default();
381 if version >= 0 {
382 m.name = "x";
383 }
384 if version >= 0 {
385 m.partitions = vec![TxnOffsetCommitRequestPartition::populated(version)];
386 }
387 m
388 }
389}
390#[derive(Debug, Clone, PartialEq, Eq)]
391pub struct TxnOffsetCommitRequestPartition<'a> {
392 pub partition_index: i32,
393 pub committed_offset: i64,
394 pub committed_leader_epoch: i32,
395 pub committed_metadata: Option<&'a str>,
396 pub unknown_tagged_fields: UnknownTaggedFields,
397}
398impl Default for TxnOffsetCommitRequestPartition<'_> {
399 fn default() -> Self {
400 Self {
401 partition_index: 0i32,
402 committed_offset: 0i64,
403 committed_leader_epoch: -1i32,
404 committed_metadata: None,
405 unknown_tagged_fields: Default::default(),
406 }
407 }
408}
409impl TxnOffsetCommitRequestPartition<'_> {
410 pub fn to_owned(
411 &self,
412 ) -> crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestPartition {
413 crate::owned::txn_offset_commit_request::TxnOffsetCommitRequestPartition {
414 partition_index: (self.partition_index),
415 committed_offset: (self.committed_offset),
416 committed_leader_epoch: (self.committed_leader_epoch),
417 committed_metadata: (self.committed_metadata).map(std::string::ToString::to_string),
418 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
419 }
420 }
421}
422impl Encode for TxnOffsetCommitRequestPartition<'_> {
423 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
424 let flex = version >= 3;
425 if version >= 0 {
426 put_i32(buf, self.partition_index);
427 }
428 if version >= 0 {
429 put_i64(buf, self.committed_offset);
430 }
431 if version >= 2 {
432 put_i32(buf, self.committed_leader_epoch);
433 }
434 if version >= 0 {
435 if flex {
436 put_compact_nullable_string(buf, self.committed_metadata);
437 } else {
438 put_nullable_string(buf, self.committed_metadata);
439 }
440 }
441 if flex {
442 let tagged = WriteTaggedFields::new();
443 tagged.write(buf, &self.unknown_tagged_fields);
444 }
445 Ok(())
446 }
447 fn encoded_len(&self, version: i16) -> usize {
448 let flex = version >= 3;
449 let mut n: usize = 0;
450 if version >= 0 {
451 n += 4;
452 }
453 if version >= 0 {
454 n += 8;
455 }
456 if version >= 2 {
457 n += 4;
458 }
459 if version >= 0 {
460 n += if flex {
461 compact_nullable_string_len(self.committed_metadata)
462 } else {
463 nullable_string_len(self.committed_metadata)
464 };
465 }
466 if flex {
467 let known_pairs: Vec<(u32, usize)> = Vec::new();
468 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
469 }
470 n
471 }
472}
473impl<'de> DecodeBorrow<'de> for TxnOffsetCommitRequestPartition<'de> {
474 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
475 let flex = version >= 3;
476 let mut out = Self::default();
477 if version >= 0 {
478 out.partition_index = get_i32(buf)?;
479 }
480 if version >= 0 {
481 out.committed_offset = get_i64(buf)?;
482 }
483 if version >= 2 {
484 out.committed_leader_epoch = get_i32(buf)?;
485 }
486 if version >= 0 {
487 out.committed_metadata = if flex {
488 get_compact_nullable_string_borrowed(buf)?
489 } else {
490 get_nullable_string_borrowed(buf)?
491 };
492 }
493 if flex {
494 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
495 }
496 Ok(out)
497 }
498}
499#[cfg(test)]
500impl TxnOffsetCommitRequestPartition<'_> {
501 #[must_use]
502 pub fn populated(version: i16) -> Self {
503 let mut m = Self::default();
504 if version >= 0 {
505 m.partition_index = 1i32;
506 }
507 if version >= 0 {
508 m.committed_offset = 1i64;
509 }
510 if version >= 2 {
511 m.committed_leader_epoch = 1i32;
512 }
513 if version >= 0 {
514 m.committed_metadata = Some("x");
515 }
516 m
517 }
518}