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