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