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