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