Skip to main content

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

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i16, get_i32, put_i16, put_i32},
9        string_bytes::{
10            bytes_len, compact_bytes_len, compact_nullable_string_len, compact_string_len,
11            get_bytes_owned, get_compact_bytes_owned, get_compact_nullable_string_owned,
12            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13            nullable_string_len, put_bytes, put_compact_bytes, put_compact_nullable_string,
14            put_compact_string, put_nullable_string, put_string, string_len,
15        },
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 15;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 6;
22pub const FLEXIBLE_MIN: i16 = 5;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct DescribeGroupsResponse {
30    pub throttle_time_ms: i32,
31    pub groups: Vec<DescribedGroup>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for DescribeGroupsResponse {
35    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37            return Err(ProtocolError::UnsupportedVersion {
38                api_key: API_KEY,
39                version,
40            });
41        }
42        let flex = is_flexible(version);
43        if version >= 1 {
44            put_i32(buf, self.throttle_time_ms);
45        }
46        if version >= 0 {
47            {
48                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
49                for it in &self.groups {
50                    it.encode(buf, version)?;
51                }
52            };
53        }
54        if flex {
55            let tagged = WriteTaggedFields::new();
56            tagged.write(buf, &self.unknown_tagged_fields);
57        }
58        Ok(())
59    }
60    fn encoded_len(&self, version: i16) -> usize {
61        let flex = is_flexible(version);
62        let mut n: usize = 0;
63        if version >= 1 {
64            n += 4;
65        }
66        if version >= 0 {
67            n += {
68                let prefix =
69                    crate::primitives::array::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 DescribeGroupsResponse {
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 >= 1 {
92            out.throttle_time_ms = get_i32(buf)?;
93        }
94        if version >= 0 {
95            out.groups = {
96                let n = crate::primitives::array::get_array_len(buf, flex)?;
97                let mut v = Vec::with_capacity(n);
98                for _ in 0..n {
99                    v.push(DescribedGroup::decode(buf, version)?);
100                }
101                v
102            };
103        }
104        if flex {
105            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
106        }
107        Ok(out)
108    }
109}
110#[cfg(test)]
111impl DescribeGroupsResponse {
112    #[must_use]
113    pub fn populated(version: i16) -> Self {
114        let mut m = Self::default();
115        if version >= 1 {
116            m.throttle_time_ms = 1i32;
117        }
118        if version >= 0 {
119            m.groups = vec![DescribedGroup::populated(version)];
120        }
121        m
122    }
123}
124#[derive(Debug, Clone, PartialEq, Eq)]
125pub struct DescribedGroup {
126    pub error_code: i16,
127    pub error_message: Option<String>,
128    pub group_id: String,
129    pub group_state: String,
130    pub protocol_type: String,
131    pub protocol_data: String,
132    pub members: Vec<DescribedGroupMember>,
133    pub authorized_operations: i32,
134    pub unknown_tagged_fields: UnknownTaggedFields,
135}
136impl Default for DescribedGroup {
137    fn default() -> Self {
138        Self {
139            error_code: 0i16,
140            error_message: None,
141            group_id: String::new(),
142            group_state: String::new(),
143            protocol_type: String::new(),
144            protocol_data: String::new(),
145            members: Vec::new(),
146            authorized_operations: -2_147_483_648i32,
147            unknown_tagged_fields: UnknownTaggedFields::default(),
148        }
149    }
150}
151impl DescribedGroup {
152    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
153        if version >= 0 {
154            put_i16(buf, self.error_code);
155        }
156    }
157    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
158        if version >= 6 {
159            if flex {
160                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
161            } else {
162                let () = put_nullable_string(buf, self.error_message.as_deref());
163            }
164        }
165    }
166    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
167        if version >= 0 {
168            if flex {
169                let () = put_compact_string(buf, &self.group_id);
170            } else {
171                let () = put_string(buf, &self.group_id);
172            }
173        }
174    }
175    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
176        if version >= 0 {
177            if flex {
178                let () = put_compact_string(buf, &self.group_state);
179            } else {
180                let () = put_string(buf, &self.group_state);
181            }
182        }
183    }
184    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
185        if version >= 0 {
186            if flex {
187                let () = put_compact_string(buf, &self.protocol_type);
188            } else {
189                let () = put_string(buf, &self.protocol_type);
190            }
191        }
192    }
193    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
194        if version >= 0 {
195            if flex {
196                let () = put_compact_string(buf, &self.protocol_data);
197            } else {
198                let () = put_string(buf, &self.protocol_data);
199            }
200        }
201    }
202    fn encode_field_6<B: BufMut>(
203        &self,
204        buf: &mut B,
205        version: i16,
206        flex: bool,
207    ) -> Result<(), ProtocolError> {
208        if version >= 0 {
209            {
210                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
211                for it in &self.members {
212                    it.encode(buf, version)?;
213                }
214            };
215        }
216        Ok(())
217    }
218    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
219        if version >= 3 {
220            put_i32(buf, self.authorized_operations);
221        }
222    }
223    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
224        if flex {
225            let tagged = WriteTaggedFields::new();
226            tagged.write(buf, &self.unknown_tagged_fields);
227        }
228    }
229    fn decode_field_0<B: Buf>(
230        out: &mut Self,
231        buf: &mut B,
232        version: i16,
233        _flex: bool,
234    ) -> Result<(), ProtocolError> {
235        if version >= 0 {
236            out.error_code = get_i16(buf)?;
237        }
238        Ok(())
239    }
240    fn decode_field_1<B: Buf>(
241        out: &mut Self,
242        buf: &mut B,
243        version: i16,
244        flex: bool,
245    ) -> Result<(), ProtocolError> {
246        if version >= 6 {
247            out.error_message = if flex {
248                get_compact_nullable_string_owned(buf)?
249            } else {
250                get_nullable_string_owned(buf)?
251            };
252        }
253        Ok(())
254    }
255    fn decode_field_2<B: Buf>(
256        out: &mut Self,
257        buf: &mut B,
258        version: i16,
259        flex: bool,
260    ) -> Result<(), ProtocolError> {
261        if version >= 0 {
262            out.group_id = if flex {
263                get_compact_string_owned(buf)?
264            } else {
265                get_string_owned(buf)?
266            };
267        }
268        Ok(())
269    }
270    fn decode_field_3<B: Buf>(
271        out: &mut Self,
272        buf: &mut B,
273        version: i16,
274        flex: bool,
275    ) -> Result<(), ProtocolError> {
276        if version >= 0 {
277            out.group_state = if flex {
278                get_compact_string_owned(buf)?
279            } else {
280                get_string_owned(buf)?
281            };
282        }
283        Ok(())
284    }
285    fn decode_field_4<B: Buf>(
286        out: &mut Self,
287        buf: &mut B,
288        version: i16,
289        flex: bool,
290    ) -> Result<(), ProtocolError> {
291        if version >= 0 {
292            out.protocol_type = if flex {
293                get_compact_string_owned(buf)?
294            } else {
295                get_string_owned(buf)?
296            };
297        }
298        Ok(())
299    }
300    fn decode_field_5<B: Buf>(
301        out: &mut Self,
302        buf: &mut B,
303        version: i16,
304        flex: bool,
305    ) -> Result<(), ProtocolError> {
306        if version >= 0 {
307            out.protocol_data = if flex {
308                get_compact_string_owned(buf)?
309            } else {
310                get_string_owned(buf)?
311            };
312        }
313        Ok(())
314    }
315    fn decode_field_6<B: Buf>(
316        out: &mut Self,
317        buf: &mut B,
318        version: i16,
319        flex: bool,
320    ) -> Result<(), ProtocolError> {
321        if version >= 0 {
322            out.members = {
323                let n = crate::primitives::array::get_array_len(buf, flex)?;
324                let mut v = Vec::with_capacity(n);
325                for _ in 0..n {
326                    v.push(DescribedGroupMember::decode(buf, version)?);
327                }
328                v
329            };
330        }
331        Ok(())
332    }
333    fn decode_field_7<B: Buf>(
334        out: &mut Self,
335        buf: &mut B,
336        version: i16,
337        _flex: bool,
338    ) -> Result<(), ProtocolError> {
339        if version >= 3 {
340            out.authorized_operations = get_i32(buf)?;
341        }
342        Ok(())
343    }
344    fn decode_tagged_fields<B: Buf>(
345        out: &mut Self,
346        buf: &mut B,
347        _version: i16,
348        flex: bool,
349    ) -> Result<(), ProtocolError> {
350        if flex {
351            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
352        }
353        Ok(())
354    }
355}
356impl Encode for DescribedGroup {
357    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
358        let flex = version >= 5;
359        self.encode_field_0(buf, version, flex);
360        self.encode_field_1(buf, version, flex);
361        self.encode_field_2(buf, version, flex);
362        self.encode_field_3(buf, version, flex);
363        self.encode_field_4(buf, version, flex);
364        self.encode_field_5(buf, version, flex);
365        self.encode_field_6(buf, version, flex)?;
366        self.encode_field_7(buf, version, flex);
367        self.encode_tagged_fields(buf, version, flex);
368        Ok(())
369    }
370    fn encoded_len(&self, version: i16) -> usize {
371        let flex = version >= 5;
372        let mut n: usize = 0;
373        if version >= 0 {
374            n += 2;
375        }
376        if version >= 6 {
377            n += if flex {
378                compact_nullable_string_len(self.error_message.as_deref())
379            } else {
380                nullable_string_len(self.error_message.as_deref())
381            };
382        }
383        if version >= 0 {
384            n += if flex {
385                compact_string_len(&self.group_id)
386            } else {
387                string_len(&self.group_id)
388            };
389        }
390        if version >= 0 {
391            n += if flex {
392                compact_string_len(&self.group_state)
393            } else {
394                string_len(&self.group_state)
395            };
396        }
397        if version >= 0 {
398            n += if flex {
399                compact_string_len(&self.protocol_type)
400            } else {
401                string_len(&self.protocol_type)
402            };
403        }
404        if version >= 0 {
405            n += if flex {
406                compact_string_len(&self.protocol_data)
407            } else {
408                string_len(&self.protocol_data)
409            };
410        }
411        if version >= 0 {
412            n += {
413                let prefix =
414                    crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
415                let body: usize = (self.members)
416                    .iter()
417                    .map(|it| it.encoded_len(version))
418                    .sum();
419                prefix + body
420            };
421        }
422        if version >= 3 {
423            n += 4;
424        }
425        if flex {
426            let known_pairs: Vec<(u32, usize)> = Vec::new();
427            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
428        }
429        n
430    }
431}
432impl Decode<'_> for DescribedGroup {
433    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
434        let flex = version >= 5;
435        let mut out = Self::default();
436        Self::decode_field_0(&mut out, buf, version, flex)?;
437        Self::decode_field_1(&mut out, buf, version, flex)?;
438        Self::decode_field_2(&mut out, buf, version, flex)?;
439        Self::decode_field_3(&mut out, buf, version, flex)?;
440        Self::decode_field_4(&mut out, buf, version, flex)?;
441        Self::decode_field_5(&mut out, buf, version, flex)?;
442        Self::decode_field_6(&mut out, buf, version, flex)?;
443        Self::decode_field_7(&mut out, buf, version, flex)?;
444        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
445        Ok(out)
446    }
447}
448#[cfg(test)]
449impl DescribedGroup {
450    #[must_use]
451    pub fn populated(version: i16) -> Self {
452        let mut m = Self::default();
453        if version >= 0 {
454            m.error_code = 1i16;
455        }
456        if version >= 6 {
457            m.error_message = Some("x".to_string());
458        }
459        if version >= 0 {
460            m.group_id = "x".to_string();
461        }
462        if version >= 0 {
463            m.group_state = "x".to_string();
464        }
465        if version >= 0 {
466            m.protocol_type = "x".to_string();
467        }
468        if version >= 0 {
469            m.protocol_data = "x".to_string();
470        }
471        if version >= 0 {
472            m.members = vec![DescribedGroupMember::populated(version)];
473        }
474        if version >= 3 {
475            m.authorized_operations = 1i32;
476        }
477        m
478    }
479}
480#[derive(Debug, Clone, PartialEq, Eq, Default)]
481pub struct DescribedGroupMember {
482    pub member_id: String,
483    pub group_instance_id: Option<String>,
484    pub client_id: String,
485    pub client_host: String,
486    pub member_metadata: ::bytes::Bytes,
487    pub member_assignment: ::bytes::Bytes,
488    pub unknown_tagged_fields: UnknownTaggedFields,
489}
490impl Encode for DescribedGroupMember {
491    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
492        let flex = version >= 5;
493        if version >= 0 {
494            if flex {
495                let () = put_compact_string(buf, &self.member_id);
496            } else {
497                let () = put_string(buf, &self.member_id);
498            }
499        }
500        if version >= 4 {
501            if flex {
502                let () = put_compact_nullable_string(buf, self.group_instance_id.as_deref());
503            } else {
504                let () = put_nullable_string(buf, self.group_instance_id.as_deref());
505            }
506        }
507        if version >= 0 {
508            if flex {
509                let () = put_compact_string(buf, &self.client_id);
510            } else {
511                let () = put_string(buf, &self.client_id);
512            }
513        }
514        if version >= 0 {
515            if flex {
516                let () = put_compact_string(buf, &self.client_host);
517            } else {
518                let () = put_string(buf, &self.client_host);
519            }
520        }
521        if version >= 0 {
522            if flex {
523                let () = put_compact_bytes(buf, &self.member_metadata);
524            } else {
525                let () = put_bytes(buf, &self.member_metadata);
526            }
527        }
528        if version >= 0 {
529            if flex {
530                let () = put_compact_bytes(buf, &self.member_assignment);
531            } else {
532                let () = put_bytes(buf, &self.member_assignment);
533            }
534        }
535        if flex {
536            let tagged = WriteTaggedFields::new();
537            tagged.write(buf, &self.unknown_tagged_fields);
538        }
539        Ok(())
540    }
541    fn encoded_len(&self, version: i16) -> usize {
542        let flex = version >= 5;
543        let mut n: usize = 0;
544        if version >= 0 {
545            n += if flex {
546                compact_string_len(&self.member_id)
547            } else {
548                string_len(&self.member_id)
549            };
550        }
551        if version >= 4 {
552            n += if flex {
553                compact_nullable_string_len(self.group_instance_id.as_deref())
554            } else {
555                nullable_string_len(self.group_instance_id.as_deref())
556            };
557        }
558        if version >= 0 {
559            n += if flex {
560                compact_string_len(&self.client_id)
561            } else {
562                string_len(&self.client_id)
563            };
564        }
565        if version >= 0 {
566            n += if flex {
567                compact_string_len(&self.client_host)
568            } else {
569                string_len(&self.client_host)
570            };
571        }
572        if version >= 0 {
573            n += if flex {
574                compact_bytes_len(&self.member_metadata)
575            } else {
576                bytes_len(&self.member_metadata)
577            };
578        }
579        if version >= 0 {
580            n += if flex {
581                compact_bytes_len(&self.member_assignment)
582            } else {
583                bytes_len(&self.member_assignment)
584            };
585        }
586        if flex {
587            let known_pairs: Vec<(u32, usize)> = Vec::new();
588            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
589        }
590        n
591    }
592}
593impl Decode<'_> for DescribedGroupMember {
594    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
595        let flex = version >= 5;
596        let mut out = Self::default();
597        if version >= 0 {
598            out.member_id = if flex {
599                get_compact_string_owned(buf)?
600            } else {
601                get_string_owned(buf)?
602            };
603        }
604        if version >= 4 {
605            out.group_instance_id = if flex {
606                get_compact_nullable_string_owned(buf)?
607            } else {
608                get_nullable_string_owned(buf)?
609            };
610        }
611        if version >= 0 {
612            out.client_id = if flex {
613                get_compact_string_owned(buf)?
614            } else {
615                get_string_owned(buf)?
616            };
617        }
618        if version >= 0 {
619            out.client_host = if flex {
620                get_compact_string_owned(buf)?
621            } else {
622                get_string_owned(buf)?
623            };
624        }
625        if version >= 0 {
626            out.member_metadata = if flex {
627                get_compact_bytes_owned(buf)?
628            } else {
629                get_bytes_owned(buf)?
630            };
631        }
632        if version >= 0 {
633            out.member_assignment = if flex {
634                get_compact_bytes_owned(buf)?
635            } else {
636                get_bytes_owned(buf)?
637            };
638        }
639        if flex {
640            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
641        }
642        Ok(out)
643    }
644}
645#[cfg(test)]
646impl DescribedGroupMember {
647    #[must_use]
648    pub fn populated(version: i16) -> Self {
649        let mut m = Self::default();
650        if version >= 0 {
651            m.member_id = "x".to_string();
652        }
653        if version >= 4 {
654            m.group_instance_id = Some("x".to_string());
655        }
656        if version >= 0 {
657            m.client_id = "x".to_string();
658        }
659        if version >= 0 {
660            m.client_host = "x".to_string();
661        }
662        if version >= 0 {
663            m.member_metadata = ::bytes::Bytes::from_static(b"x");
664        }
665        if version >= 0 {
666            m.member_assignment = ::bytes::Bytes::from_static(b"x");
667        }
668        m
669    }
670}
671/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
672/// Only includes fields valid for the given version.
673#[must_use]
674#[allow(unused_comparisons)]
675pub fn default_json(version: i16) -> ::serde_json::Value {
676    let mut obj = ::serde_json::Map::new();
677    if version >= 1 {
678        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
679    }
680    obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
681    ::serde_json::Value::Object(obj)
682}