Skip to main content

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