crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupDescribeResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
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 = 77;
15pub const MIN_VERSION: i16 = 1;
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 ShareGroupDescribeResponse {
26 pub throttle_time_ms: i32,
27 pub groups: Vec<DescribedGroup>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for ShareGroupDescribeResponse {
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 ShareGroupDescribeResponse {
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(DescribedGroup::decode(buf, version)?);
96 }
97 v
98 };
99 }
100 if flex {
101 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
102 }
103 Ok(out)
104 }
105}
106#[cfg(test)]
107impl ShareGroupDescribeResponse {
108 #[must_use]
109 pub fn populated(version: i16) -> Self {
110 let mut m = Self::default();
111 if version >= 0 {
112 m.throttle_time_ms = 1i32;
113 }
114 if version >= 0 {
115 m.groups = vec![DescribedGroup::populated(version)];
116 }
117 m
118 }
119}
120#[derive(Debug, Clone, PartialEq, Eq)]
121pub struct DescribedGroup {
122 pub error_code: i16,
123 pub error_message: Option<String>,
124 pub group_id: String,
125 pub group_state: String,
126 pub group_epoch: i32,
127 pub assignment_epoch: i32,
128 pub assignor_name: String,
129 pub members: Vec<Member>,
130 pub authorized_operations: i32,
131 pub unknown_tagged_fields: UnknownTaggedFields,
132}
133impl Default for DescribedGroup {
134 fn default() -> Self {
135 Self {
136 error_code: 0i16,
137 error_message: None,
138 group_id: String::new(),
139 group_state: String::new(),
140 group_epoch: 0i32,
141 assignment_epoch: 0i32,
142 assignor_name: String::new(),
143 members: Vec::new(),
144 authorized_operations: -2_147_483_648i32,
145 unknown_tagged_fields: Default::default(),
146 }
147 }
148}
149impl Encode for DescribedGroup {
150 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
151 let flex = version >= 0;
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 version >= 0 {
163 if flex {
164 put_compact_string(buf, &self.group_id);
165 } else {
166 put_string(buf, &self.group_id);
167 }
168 }
169 if version >= 0 {
170 if flex {
171 put_compact_string(buf, &self.group_state);
172 } else {
173 put_string(buf, &self.group_state);
174 }
175 }
176 if version >= 0 {
177 put_i32(buf, self.group_epoch);
178 }
179 if version >= 0 {
180 put_i32(buf, self.assignment_epoch);
181 }
182 if version >= 0 {
183 if flex {
184 put_compact_string(buf, &self.assignor_name);
185 } else {
186 put_string(buf, &self.assignor_name);
187 }
188 }
189 if version >= 0 {
190 {
191 crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
192 for it in &self.members {
193 it.encode(buf, version)?;
194 }
195 }
196 }
197 if version >= 0 {
198 put_i32(buf, self.authorized_operations);
199 }
200 if flex {
201 let tagged = WriteTaggedFields::new();
202 tagged.write(buf, &self.unknown_tagged_fields);
203 }
204 Ok(())
205 }
206 fn encoded_len(&self, version: i16) -> usize {
207 let flex = version >= 0;
208 let mut n: usize = 0;
209 if version >= 0 {
210 n += 2;
211 }
212 if version >= 0 {
213 n += if flex {
214 compact_nullable_string_len(self.error_message.as_deref())
215 } else {
216 nullable_string_len(self.error_message.as_deref())
217 };
218 }
219 if version >= 0 {
220 n += if flex {
221 compact_string_len(&self.group_id)
222 } else {
223 string_len(&self.group_id)
224 };
225 }
226 if version >= 0 {
227 n += if flex {
228 compact_string_len(&self.group_state)
229 } else {
230 string_len(&self.group_state)
231 };
232 }
233 if version >= 0 {
234 n += 4;
235 }
236 if version >= 0 {
237 n += 4;
238 }
239 if version >= 0 {
240 n += if flex {
241 compact_string_len(&self.assignor_name)
242 } else {
243 string_len(&self.assignor_name)
244 };
245 }
246 if version >= 0 {
247 n += {
248 let prefix =
249 crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
250 let body: usize = (self.members)
251 .iter()
252 .map(|it| it.encoded_len(version))
253 .sum();
254 prefix + body
255 };
256 }
257 if version >= 0 {
258 n += 4;
259 }
260 if flex {
261 let known_pairs: Vec<(u32, usize)> = Vec::new();
262 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
263 }
264 n
265 }
266}
267impl Decode<'_> for DescribedGroup {
268 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
269 let flex = version >= 0;
270 let mut out = Self::default();
271 if version >= 0 {
272 out.error_code = get_i16(buf)?;
273 }
274 if version >= 0 {
275 out.error_message = if flex {
276 get_compact_nullable_string_owned(buf)?
277 } else {
278 get_nullable_string_owned(buf)?
279 };
280 }
281 if version >= 0 {
282 out.group_id = if flex {
283 get_compact_string_owned(buf)?
284 } else {
285 get_string_owned(buf)?
286 };
287 }
288 if version >= 0 {
289 out.group_state = if flex {
290 get_compact_string_owned(buf)?
291 } else {
292 get_string_owned(buf)?
293 };
294 }
295 if version >= 0 {
296 out.group_epoch = get_i32(buf)?;
297 }
298 if version >= 0 {
299 out.assignment_epoch = get_i32(buf)?;
300 }
301 if version >= 0 {
302 out.assignor_name = if flex {
303 get_compact_string_owned(buf)?
304 } else {
305 get_string_owned(buf)?
306 };
307 }
308 if version >= 0 {
309 out.members = {
310 let n = crate::primitives::array::get_array_len(buf, flex)?;
311 let mut v = Vec::with_capacity(n);
312 for _ in 0..n {
313 v.push(Member::decode(buf, version)?);
314 }
315 v
316 };
317 }
318 if version >= 0 {
319 out.authorized_operations = get_i32(buf)?;
320 }
321 if flex {
322 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
323 }
324 Ok(out)
325 }
326}
327#[cfg(test)]
328impl DescribedGroup {
329 #[must_use]
330 pub fn populated(version: i16) -> Self {
331 let mut m = Self::default();
332 if version >= 0 {
333 m.error_code = 1i16;
334 }
335 if version >= 0 {
336 m.error_message = Some("x".to_string());
337 }
338 if version >= 0 {
339 m.group_id = "x".to_string();
340 }
341 if version >= 0 {
342 m.group_state = "x".to_string();
343 }
344 if version >= 0 {
345 m.group_epoch = 1i32;
346 }
347 if version >= 0 {
348 m.assignment_epoch = 1i32;
349 }
350 if version >= 0 {
351 m.assignor_name = "x".to_string();
352 }
353 if version >= 0 {
354 m.members = vec![Member::populated(version)];
355 }
356 if version >= 0 {
357 m.authorized_operations = 1i32;
358 }
359 m
360 }
361}
362#[derive(Debug, Clone, PartialEq, Eq, Default)]
363pub struct Member {
364 pub member_id: String,
365 pub rack_id: Option<String>,
366 pub member_epoch: i32,
367 pub client_id: String,
368 pub client_host: String,
369 pub subscribed_topic_names: Vec<String>,
370 pub assignment: super::common::share_group_describe_response::assignment::Assignment,
371 pub unknown_tagged_fields: UnknownTaggedFields,
372}
373impl Encode for Member {
374 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
375 let flex = version >= 0;
376 if version >= 0 {
377 if flex {
378 put_compact_string(buf, &self.member_id);
379 } else {
380 put_string(buf, &self.member_id);
381 }
382 }
383 if version >= 0 {
384 if flex {
385 put_compact_nullable_string(buf, self.rack_id.as_deref());
386 } else {
387 put_nullable_string(buf, self.rack_id.as_deref());
388 }
389 }
390 if version >= 0 {
391 put_i32(buf, self.member_epoch);
392 }
393 if version >= 0 {
394 if flex {
395 put_compact_string(buf, &self.client_id);
396 } else {
397 put_string(buf, &self.client_id);
398 }
399 }
400 if version >= 0 {
401 if flex {
402 put_compact_string(buf, &self.client_host);
403 } else {
404 put_string(buf, &self.client_host);
405 }
406 }
407 if version >= 0 {
408 {
409 crate::primitives::array::put_array_len(
410 buf,
411 (self.subscribed_topic_names).len(),
412 flex,
413 );
414 for it in &self.subscribed_topic_names {
415 if flex {
416 put_compact_string(buf, it);
417 } else {
418 put_string(buf, it);
419 }
420 }
421 }
422 }
423 if version >= 0 {
424 self.assignment.encode(buf, version)?;
425 }
426 if flex {
427 let tagged = WriteTaggedFields::new();
428 tagged.write(buf, &self.unknown_tagged_fields);
429 }
430 Ok(())
431 }
432 fn encoded_len(&self, version: i16) -> usize {
433 let flex = version >= 0;
434 let mut n: usize = 0;
435 if version >= 0 {
436 n += if flex {
437 compact_string_len(&self.member_id)
438 } else {
439 string_len(&self.member_id)
440 };
441 }
442 if version >= 0 {
443 n += if flex {
444 compact_nullable_string_len(self.rack_id.as_deref())
445 } else {
446 nullable_string_len(self.rack_id.as_deref())
447 };
448 }
449 if version >= 0 {
450 n += 4;
451 }
452 if version >= 0 {
453 n += if flex {
454 compact_string_len(&self.client_id)
455 } else {
456 string_len(&self.client_id)
457 };
458 }
459 if version >= 0 {
460 n += if flex {
461 compact_string_len(&self.client_host)
462 } else {
463 string_len(&self.client_host)
464 };
465 }
466 if version >= 0 {
467 n += {
468 let prefix = crate::primitives::array::array_len_prefix_len(
469 (self.subscribed_topic_names).len(),
470 flex,
471 );
472 let body: usize = (self.subscribed_topic_names)
473 .iter()
474 .map(|it| {
475 if flex {
476 compact_string_len(it)
477 } else {
478 string_len(it)
479 }
480 })
481 .sum();
482 prefix + body
483 };
484 }
485 if version >= 0 {
486 n += self.assignment.encoded_len(version);
487 }
488 if flex {
489 let known_pairs: Vec<(u32, usize)> = Vec::new();
490 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
491 }
492 n
493 }
494}
495impl Decode<'_> for Member {
496 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
497 let flex = version >= 0;
498 let mut out = Self::default();
499 if version >= 0 {
500 out.member_id = if flex {
501 get_compact_string_owned(buf)?
502 } else {
503 get_string_owned(buf)?
504 };
505 }
506 if version >= 0 {
507 out.rack_id = if flex {
508 get_compact_nullable_string_owned(buf)?
509 } else {
510 get_nullable_string_owned(buf)?
511 };
512 }
513 if version >= 0 {
514 out.member_epoch = get_i32(buf)?;
515 }
516 if version >= 0 {
517 out.client_id = if flex {
518 get_compact_string_owned(buf)?
519 } else {
520 get_string_owned(buf)?
521 };
522 }
523 if version >= 0 {
524 out.client_host = if flex {
525 get_compact_string_owned(buf)?
526 } else {
527 get_string_owned(buf)?
528 };
529 }
530 if version >= 0 {
531 out.subscribed_topic_names = {
532 let n = crate::primitives::array::get_array_len(buf, flex)?;
533 let mut v = Vec::with_capacity(n);
534 for _ in 0..n {
535 v.push(if flex {
536 get_compact_string_owned(buf)?
537 } else {
538 get_string_owned(buf)?
539 });
540 }
541 v
542 };
543 }
544 if version >= 0 {
545 out.assignment =
546 super::common::share_group_describe_response::assignment::Assignment::decode(
547 buf, version,
548 )?;
549 }
550 if flex {
551 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
552 }
553 Ok(out)
554 }
555}
556#[cfg(test)]
557impl Member {
558 #[must_use]
559 pub fn populated(version: i16) -> Self {
560 let mut m = Self::default();
561 if version >= 0 {
562 m.member_id = "x".to_string();
563 }
564 if version >= 0 {
565 m.rack_id = Some("x".to_string());
566 }
567 if version >= 0 {
568 m.member_epoch = 1i32;
569 }
570 if version >= 0 {
571 m.client_id = "x".to_string();
572 }
573 if version >= 0 {
574 m.client_host = "x".to_string();
575 }
576 if version >= 0 {
577 m.subscribed_topic_names = vec!["x".to_string()];
578 }
579 if version >= 0 {
580 m.assignment =
581 super::common::share_group_describe_response::assignment::Assignment::populated(
582 version,
583 );
584 }
585 m
586 }
587}
588
589#[must_use]
592#[allow(unused_comparisons)]
593pub fn default_json(version: i16) -> ::serde_json::Value {
594 let mut obj = ::serde_json::Map::new();
595 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
596 obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
597 ::serde_json::Value::Object(obj)
598}