Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_bool, get_i16, get_i32, put_bool, 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 = 11;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 9;
19pub const FLEXIBLE_MIN: i16 = 6;
20#[inline]
21fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct JoinGroupResponse {
26    pub throttle_time_ms: i32,
27    pub error_code: i16,
28    pub generation_id: i32,
29    pub protocol_type: Option<String>,
30    pub protocol_name: Option<String>,
31    pub leader: String,
32    pub skip_assignment: bool,
33    pub member_id: String,
34    pub members: Vec<JoinGroupResponseMember>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Default for JoinGroupResponse {
38    fn default() -> Self {
39        Self {
40            throttle_time_ms: 0i32,
41            error_code: 0i16,
42            generation_id: -1i32,
43            protocol_type: None,
44            protocol_name: None,
45            leader: String::new(),
46            skip_assignment: false,
47            member_id: String::new(),
48            members: Vec::new(),
49            unknown_tagged_fields: Default::default(),
50        }
51    }
52}
53impl Encode for JoinGroupResponse {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion {
57                api_key: API_KEY,
58                version,
59            });
60        }
61        let flex = is_flexible(version);
62        if version >= 2 {
63            put_i32(buf, self.throttle_time_ms);
64        }
65        if version >= 0 {
66            put_i16(buf, self.error_code);
67        }
68        if version >= 0 {
69            put_i32(buf, self.generation_id);
70        }
71        if version >= 7 {
72            if flex {
73                put_compact_nullable_string(buf, self.protocol_type.as_deref());
74            } else {
75                put_nullable_string(buf, self.protocol_type.as_deref());
76            }
77        }
78        if version >= 0 {
79            if version >= 7 {
80                if flex {
81                    put_compact_nullable_string(buf, self.protocol_name.as_deref());
82                } else {
83                    put_nullable_string(buf, self.protocol_name.as_deref());
84                }
85            } else {
86                if flex {
87                    put_compact_string(buf, (self.protocol_name).as_deref().unwrap_or(""));
88                } else {
89                    put_string(buf, (self.protocol_name).as_deref().unwrap_or(""));
90                }
91            }
92        }
93        if version >= 0 {
94            if flex {
95                put_compact_string(buf, &self.leader);
96            } else {
97                put_string(buf, &self.leader);
98            }
99        }
100        if version >= 9 {
101            put_bool(buf, self.skip_assignment);
102        }
103        if version >= 0 {
104            if flex {
105                put_compact_string(buf, &self.member_id);
106            } else {
107                put_string(buf, &self.member_id);
108            }
109        }
110        if version >= 0 {
111            {
112                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
113                for it in &self.members {
114                    it.encode(buf, version)?;
115                }
116            }
117        }
118        if flex {
119            let tagged = WriteTaggedFields::new();
120            tagged.write(buf, &self.unknown_tagged_fields);
121        }
122        Ok(())
123    }
124    fn encoded_len(&self, version: i16) -> usize {
125        let flex = is_flexible(version);
126        let mut n: usize = 0;
127        if version >= 2 {
128            n += 4;
129        }
130        if version >= 0 {
131            n += 2;
132        }
133        if version >= 0 {
134            n += 4;
135        }
136        if version >= 7 {
137            n += if flex {
138                compact_nullable_string_len(self.protocol_type.as_deref())
139            } else {
140                nullable_string_len(self.protocol_type.as_deref())
141            };
142        }
143        if version >= 0 {
144            n += if version >= 7 {
145                if flex {
146                    compact_nullable_string_len(self.protocol_name.as_deref())
147                } else {
148                    nullable_string_len(self.protocol_name.as_deref())
149                }
150            } else {
151                if flex {
152                    compact_string_len((self.protocol_name).as_deref().unwrap_or(""))
153                } else {
154                    string_len((self.protocol_name).as_deref().unwrap_or(""))
155                }
156            };
157        }
158        if version >= 0 {
159            n += if flex {
160                compact_string_len(&self.leader)
161            } else {
162                string_len(&self.leader)
163            };
164        }
165        if version >= 9 {
166            n += 1;
167        }
168        if version >= 0 {
169            n += if flex {
170                compact_string_len(&self.member_id)
171            } else {
172                string_len(&self.member_id)
173            };
174        }
175        if version >= 0 {
176            n += {
177                let prefix =
178                    crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
179                let body: usize = (self.members)
180                    .iter()
181                    .map(|it| it.encoded_len(version))
182                    .sum();
183                prefix + body
184            };
185        }
186        if flex {
187            let known_pairs: Vec<(u32, usize)> = Vec::new();
188            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
189        }
190        n
191    }
192}
193impl Decode<'_> for JoinGroupResponse {
194    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
195        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
196            return Err(ProtocolError::UnsupportedVersion {
197                api_key: API_KEY,
198                version,
199            });
200        }
201        let flex = is_flexible(version);
202        let mut out = Self::default();
203        if version >= 2 {
204            out.throttle_time_ms = get_i32(buf)?;
205        }
206        if version >= 0 {
207            out.error_code = get_i16(buf)?;
208        }
209        if version >= 0 {
210            out.generation_id = get_i32(buf)?;
211        }
212        if version >= 7 {
213            out.protocol_type = if flex {
214                get_compact_nullable_string_owned(buf)?
215            } else {
216                get_nullable_string_owned(buf)?
217            };
218        }
219        if version >= 0 {
220            out.protocol_name = if version >= 7 {
221                if flex {
222                    get_compact_nullable_string_owned(buf)?
223                } else {
224                    get_nullable_string_owned(buf)?
225                }
226            } else {
227                Some(if flex {
228                    get_compact_string_owned(buf)?
229                } else {
230                    get_string_owned(buf)?
231                })
232            };
233        }
234        if version >= 0 {
235            out.leader = if flex {
236                get_compact_string_owned(buf)?
237            } else {
238                get_string_owned(buf)?
239            };
240        }
241        if version >= 9 {
242            out.skip_assignment = get_bool(buf)?;
243        }
244        if version >= 0 {
245            out.member_id = if flex {
246                get_compact_string_owned(buf)?
247            } else {
248                get_string_owned(buf)?
249            };
250        }
251        if version >= 0 {
252            out.members = {
253                let n = crate::primitives::array::get_array_len(buf, flex)?;
254                let mut v = Vec::with_capacity(n);
255                for _ in 0..n {
256                    v.push(JoinGroupResponseMember::decode(buf, version)?);
257                }
258                v
259            };
260        }
261        if flex {
262            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
263        }
264        Ok(out)
265    }
266}
267#[cfg(test)]
268impl JoinGroupResponse {
269    #[must_use]
270    pub fn populated(version: i16) -> Self {
271        let mut m = Self::default();
272        if version >= 2 {
273            m.throttle_time_ms = 1i32;
274        }
275        if version >= 0 {
276            m.error_code = 1i16;
277        }
278        if version >= 0 {
279            m.generation_id = 1i32;
280        }
281        if version >= 7 {
282            m.protocol_type = Some("x".to_string());
283        }
284        if version >= 0 {
285            m.protocol_name = Some("x".to_string());
286        }
287        if version >= 0 {
288            m.leader = "x".to_string();
289        }
290        if version >= 9 {
291            m.skip_assignment = true;
292        }
293        if version >= 0 {
294            m.member_id = "x".to_string();
295        }
296        if version >= 0 {
297            m.members = vec![JoinGroupResponseMember::populated(version)];
298        }
299        m
300    }
301}
302#[derive(Debug, Clone, PartialEq, Eq, Default)]
303pub struct JoinGroupResponseMember {
304    pub member_id: String,
305    pub group_instance_id: Option<String>,
306    pub metadata: ::bytes::Bytes,
307    pub unknown_tagged_fields: UnknownTaggedFields,
308}
309impl Encode for JoinGroupResponseMember {
310    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
311        let flex = version >= 6;
312        if version >= 0 {
313            if flex {
314                put_compact_string(buf, &self.member_id);
315            } else {
316                put_string(buf, &self.member_id);
317            }
318        }
319        if version >= 5 {
320            if flex {
321                put_compact_nullable_string(buf, self.group_instance_id.as_deref());
322            } else {
323                put_nullable_string(buf, self.group_instance_id.as_deref());
324            }
325        }
326        if version >= 0 {
327            if flex {
328                put_compact_bytes(buf, &self.metadata);
329            } else {
330                put_bytes(buf, &self.metadata);
331            }
332        }
333        if flex {
334            let tagged = WriteTaggedFields::new();
335            tagged.write(buf, &self.unknown_tagged_fields);
336        }
337        Ok(())
338    }
339    fn encoded_len(&self, version: i16) -> usize {
340        let flex = version >= 6;
341        let mut n: usize = 0;
342        if version >= 0 {
343            n += if flex {
344                compact_string_len(&self.member_id)
345            } else {
346                string_len(&self.member_id)
347            };
348        }
349        if version >= 5 {
350            n += if flex {
351                compact_nullable_string_len(self.group_instance_id.as_deref())
352            } else {
353                nullable_string_len(self.group_instance_id.as_deref())
354            };
355        }
356        if version >= 0 {
357            n += if flex {
358                compact_bytes_len(&self.metadata)
359            } else {
360                bytes_len(&self.metadata)
361            };
362        }
363        if flex {
364            let known_pairs: Vec<(u32, usize)> = Vec::new();
365            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
366        }
367        n
368    }
369}
370impl Decode<'_> for JoinGroupResponseMember {
371    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
372        let flex = version >= 6;
373        let mut out = Self::default();
374        if version >= 0 {
375            out.member_id = if flex {
376                get_compact_string_owned(buf)?
377            } else {
378                get_string_owned(buf)?
379            };
380        }
381        if version >= 5 {
382            out.group_instance_id = if flex {
383                get_compact_nullable_string_owned(buf)?
384            } else {
385                get_nullable_string_owned(buf)?
386            };
387        }
388        if version >= 0 {
389            out.metadata = if flex {
390                get_compact_bytes_owned(buf)?
391            } else {
392                get_bytes_owned(buf)?
393            };
394        }
395        if flex {
396            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
397        }
398        Ok(out)
399    }
400}
401#[cfg(test)]
402impl JoinGroupResponseMember {
403    #[must_use]
404    pub fn populated(version: i16) -> Self {
405        let mut m = Self::default();
406        if version >= 0 {
407            m.member_id = "x".to_string();
408        }
409        if version >= 5 {
410            m.group_instance_id = Some("x".to_string());
411        }
412        if version >= 0 {
413            m.metadata = ::bytes::Bytes::from_static(b"x");
414        }
415        m
416    }
417}
418/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
419/// Only includes fields valid for the given version.
420#[must_use]
421#[allow(unused_comparisons)]
422pub fn default_json(version: i16) -> ::serde_json::Value {
423    let mut obj = ::serde_json::Map::new();
424    if version >= 2 {
425        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
426    }
427    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
428    obj.insert("generationId".to_string(), ::serde_json::json!(-1));
429    if version >= 7 {
430        obj.insert("protocolType".to_string(), ::serde_json::Value::Null);
431    }
432    obj.insert(
433        "protocolName".to_string(),
434        if version >= 7 {
435            ::serde_json::Value::Null
436        } else {
437            ::serde_json::Value::String(String::new())
438        },
439    );
440    obj.insert(
441        "leader".to_string(),
442        ::serde_json::Value::String(String::new()),
443    );
444    if version >= 9 {
445        obj.insert(
446            "skipAssignment".to_string(),
447            ::serde_json::Value::Bool(false),
448        );
449    }
450    obj.insert(
451        "memberId".to_string(),
452        ::serde_json::Value::String(String::new()),
453    );
454    obj.insert("members".to_string(), ::serde_json::Value::Array(vec![]));
455    ::serde_json::Value::Object(obj)
456}