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