Skip to main content

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