Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsResponse.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
4use crate::primitives::string_bytes::{
5    bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
6    put_compact_bytes,
7};
8use crate::primitives::string_bytes::{
9    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
10    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
11    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
12};
13use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15use bytes::{Buf, BufMut};
16pub const API_KEY: i16 = 15;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 6;
19pub const FLEXIBLE_MIN: i16 = 5;
20#[inline]
21fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct DescribeGroupsResponse {
26    pub throttle_time_ms: i32,
27    pub groups: Vec<DescribedGroup>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for DescribeGroupsResponse {
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 >= 1 {
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 >= 1 {
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 DescribeGroupsResponse {
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 >= 1 {
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 DescribeGroupsResponse {
108    #[must_use]
109    pub fn populated(version: i16) -> Self {
110        let mut m = Self::default();
111        if version >= 1 {
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 protocol_type: String,
127    pub protocol_data: String,
128    pub members: Vec<DescribedGroupMember>,
129    pub authorized_operations: i32,
130    pub unknown_tagged_fields: UnknownTaggedFields,
131}
132impl Default for DescribedGroup {
133    fn default() -> Self {
134        Self {
135            error_code: 0i16,
136            error_message: None,
137            group_id: String::new(),
138            group_state: String::new(),
139            protocol_type: String::new(),
140            protocol_data: String::new(),
141            members: Vec::new(),
142            authorized_operations: -2_147_483_648i32,
143            unknown_tagged_fields: Default::default(),
144        }
145    }
146}
147impl Encode for DescribedGroup {
148    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
149        let flex = version >= 5;
150        if version >= 0 {
151            put_i16(buf, self.error_code);
152        }
153        if version >= 6 {
154            if flex {
155                put_compact_nullable_string(buf, self.error_message.as_deref());
156            } else {
157                put_nullable_string(buf, self.error_message.as_deref());
158            }
159        }
160        if version >= 0 {
161            if flex {
162                put_compact_string(buf, &self.group_id);
163            } else {
164                put_string(buf, &self.group_id);
165            }
166        }
167        if version >= 0 {
168            if flex {
169                put_compact_string(buf, &self.group_state);
170            } else {
171                put_string(buf, &self.group_state);
172            }
173        }
174        if version >= 0 {
175            if flex {
176                put_compact_string(buf, &self.protocol_type);
177            } else {
178                put_string(buf, &self.protocol_type);
179            }
180        }
181        if version >= 0 {
182            if flex {
183                put_compact_string(buf, &self.protocol_data);
184            } else {
185                put_string(buf, &self.protocol_data);
186            }
187        }
188        if version >= 0 {
189            {
190                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
191                for it in &self.members {
192                    it.encode(buf, version)?;
193                }
194            }
195        }
196        if version >= 3 {
197            put_i32(buf, self.authorized_operations);
198        }
199        if flex {
200            let tagged = WriteTaggedFields::new();
201            tagged.write(buf, &self.unknown_tagged_fields);
202        }
203        Ok(())
204    }
205    fn encoded_len(&self, version: i16) -> usize {
206        let flex = version >= 5;
207        let mut n: usize = 0;
208        if version >= 0 {
209            n += 2;
210        }
211        if version >= 6 {
212            n += if flex {
213                compact_nullable_string_len(self.error_message.as_deref())
214            } else {
215                nullable_string_len(self.error_message.as_deref())
216            };
217        }
218        if version >= 0 {
219            n += if flex {
220                compact_string_len(&self.group_id)
221            } else {
222                string_len(&self.group_id)
223            };
224        }
225        if version >= 0 {
226            n += if flex {
227                compact_string_len(&self.group_state)
228            } else {
229                string_len(&self.group_state)
230            };
231        }
232        if version >= 0 {
233            n += if flex {
234                compact_string_len(&self.protocol_type)
235            } else {
236                string_len(&self.protocol_type)
237            };
238        }
239        if version >= 0 {
240            n += if flex {
241                compact_string_len(&self.protocol_data)
242            } else {
243                string_len(&self.protocol_data)
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 >= 3 {
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 >= 5;
270        let mut out = Self::default();
271        if version >= 0 {
272            out.error_code = get_i16(buf)?;
273        }
274        if version >= 6 {
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.protocol_type = if flex {
297                get_compact_string_owned(buf)?
298            } else {
299                get_string_owned(buf)?
300            };
301        }
302        if version >= 0 {
303            out.protocol_data = if flex {
304                get_compact_string_owned(buf)?
305            } else {
306                get_string_owned(buf)?
307            };
308        }
309        if version >= 0 {
310            out.members = {
311                let n = crate::primitives::array::get_array_len(buf, flex)?;
312                let mut v = Vec::with_capacity(n);
313                for _ in 0..n {
314                    v.push(DescribedGroupMember::decode(buf, version)?);
315                }
316                v
317            };
318        }
319        if version >= 3 {
320            out.authorized_operations = get_i32(buf)?;
321        }
322        if flex {
323            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
324        }
325        Ok(out)
326    }
327}
328#[cfg(test)]
329impl DescribedGroup {
330    #[must_use]
331    pub fn populated(version: i16) -> Self {
332        let mut m = Self::default();
333        if version >= 0 {
334            m.error_code = 1i16;
335        }
336        if version >= 6 {
337            m.error_message = Some("x".to_string());
338        }
339        if version >= 0 {
340            m.group_id = "x".to_string();
341        }
342        if version >= 0 {
343            m.group_state = "x".to_string();
344        }
345        if version >= 0 {
346            m.protocol_type = "x".to_string();
347        }
348        if version >= 0 {
349            m.protocol_data = "x".to_string();
350        }
351        if version >= 0 {
352            m.members = vec![DescribedGroupMember::populated(version)];
353        }
354        if version >= 3 {
355            m.authorized_operations = 1i32;
356        }
357        m
358    }
359}
360#[derive(Debug, Clone, PartialEq, Eq, Default)]
361pub struct DescribedGroupMember {
362    pub member_id: String,
363    pub group_instance_id: Option<String>,
364    pub client_id: String,
365    pub client_host: String,
366    pub member_metadata: ::bytes::Bytes,
367    pub member_assignment: ::bytes::Bytes,
368    pub unknown_tagged_fields: UnknownTaggedFields,
369}
370impl Encode for DescribedGroupMember {
371    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
372        let flex = version >= 5;
373        if version >= 0 {
374            if flex {
375                put_compact_string(buf, &self.member_id);
376            } else {
377                put_string(buf, &self.member_id);
378            }
379        }
380        if version >= 4 {
381            if flex {
382                put_compact_nullable_string(buf, self.group_instance_id.as_deref());
383            } else {
384                put_nullable_string(buf, self.group_instance_id.as_deref());
385            }
386        }
387        if version >= 0 {
388            if flex {
389                put_compact_string(buf, &self.client_id);
390            } else {
391                put_string(buf, &self.client_id);
392            }
393        }
394        if version >= 0 {
395            if flex {
396                put_compact_string(buf, &self.client_host);
397            } else {
398                put_string(buf, &self.client_host);
399            }
400        }
401        if version >= 0 {
402            if flex {
403                put_compact_bytes(buf, &self.member_metadata);
404            } else {
405                put_bytes(buf, &self.member_metadata);
406            }
407        }
408        if version >= 0 {
409            if flex {
410                put_compact_bytes(buf, &self.member_assignment);
411            } else {
412                put_bytes(buf, &self.member_assignment);
413            }
414        }
415        if flex {
416            let tagged = WriteTaggedFields::new();
417            tagged.write(buf, &self.unknown_tagged_fields);
418        }
419        Ok(())
420    }
421    fn encoded_len(&self, version: i16) -> usize {
422        let flex = version >= 5;
423        let mut n: usize = 0;
424        if version >= 0 {
425            n += if flex {
426                compact_string_len(&self.member_id)
427            } else {
428                string_len(&self.member_id)
429            };
430        }
431        if version >= 4 {
432            n += if flex {
433                compact_nullable_string_len(self.group_instance_id.as_deref())
434            } else {
435                nullable_string_len(self.group_instance_id.as_deref())
436            };
437        }
438        if version >= 0 {
439            n += if flex {
440                compact_string_len(&self.client_id)
441            } else {
442                string_len(&self.client_id)
443            };
444        }
445        if version >= 0 {
446            n += if flex {
447                compact_string_len(&self.client_host)
448            } else {
449                string_len(&self.client_host)
450            };
451        }
452        if version >= 0 {
453            n += if flex {
454                compact_bytes_len(&self.member_metadata)
455            } else {
456                bytes_len(&self.member_metadata)
457            };
458        }
459        if version >= 0 {
460            n += if flex {
461                compact_bytes_len(&self.member_assignment)
462            } else {
463                bytes_len(&self.member_assignment)
464            };
465        }
466        if flex {
467            let known_pairs: Vec<(u32, usize)> = Vec::new();
468            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
469        }
470        n
471    }
472}
473impl Decode<'_> for DescribedGroupMember {
474    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
475        let flex = version >= 5;
476        let mut out = Self::default();
477        if version >= 0 {
478            out.member_id = if flex {
479                get_compact_string_owned(buf)?
480            } else {
481                get_string_owned(buf)?
482            };
483        }
484        if version >= 4 {
485            out.group_instance_id = if flex {
486                get_compact_nullable_string_owned(buf)?
487            } else {
488                get_nullable_string_owned(buf)?
489            };
490        }
491        if version >= 0 {
492            out.client_id = if flex {
493                get_compact_string_owned(buf)?
494            } else {
495                get_string_owned(buf)?
496            };
497        }
498        if version >= 0 {
499            out.client_host = if flex {
500                get_compact_string_owned(buf)?
501            } else {
502                get_string_owned(buf)?
503            };
504        }
505        if version >= 0 {
506            out.member_metadata = if flex {
507                get_compact_bytes_owned(buf)?
508            } else {
509                get_bytes_owned(buf)?
510            };
511        }
512        if version >= 0 {
513            out.member_assignment = if flex {
514                get_compact_bytes_owned(buf)?
515            } else {
516                get_bytes_owned(buf)?
517            };
518        }
519        if flex {
520            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
521        }
522        Ok(out)
523    }
524}
525#[cfg(test)]
526impl DescribedGroupMember {
527    #[must_use]
528    pub fn populated(version: i16) -> Self {
529        let mut m = Self::default();
530        if version >= 0 {
531            m.member_id = "x".to_string();
532        }
533        if version >= 4 {
534            m.group_instance_id = Some("x".to_string());
535        }
536        if version >= 0 {
537            m.client_id = "x".to_string();
538        }
539        if version >= 0 {
540            m.client_host = "x".to_string();
541        }
542        if version >= 0 {
543            m.member_metadata = ::bytes::Bytes::from_static(b"x");
544        }
545        if version >= 0 {
546            m.member_assignment = ::bytes::Bytes::from_static(b"x");
547        }
548        m
549    }
550}
551/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
552/// Only includes fields valid for the given version.
553#[must_use]
554#[allow(unused_comparisons)]
555pub fn default_json(version: i16) -> ::serde_json::Value {
556    let mut obj = ::serde_json::Map::new();
557    if version >= 1 {
558        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
559    }
560    obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
561    ::serde_json::Value::Object(obj)
562}