Skip to main content

kacrab_protocol/generated/
join_group_request.rs

1//! Generated from JoinGroupRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct JoinGroupRequestData {
17    /// The group identifier.
18    pub group_id: KafkaString,
19    /// The coordinator considers the consumer dead if it receives no heartbeat after this timeout
20    /// in milliseconds.
21    pub session_timeout_ms: i32,
22    /// The maximum time in milliseconds that the coordinator will wait for each member to rejoin
23    /// when rebalancing the group.
24    pub rebalance_timeout_ms: i32,
25    /// The member id assigned by the group coordinator.
26    pub member_id: KafkaString,
27    /// The unique identifier of the consumer instance provided by end user.
28    pub group_instance_id: Option<KafkaString>,
29    /// The unique name the for class of protocols implemented by the group we want to join.
30    pub protocol_type: KafkaString,
31    /// The list of protocols that the member supports.
32    pub protocols: Vec<JoinGroupRequestProtocol>,
33    /// The reason why the member (re-)joins the group.
34    pub reason: Option<KafkaString>,
35    pub _unknown_tagged_fields: Vec<RawTaggedField>,
36}
37impl Default for JoinGroupRequestData {
38    fn default() -> Self {
39        Self {
40            group_id: KafkaString::default(),
41            session_timeout_ms: 0_i32,
42            rebalance_timeout_ms: -1i32,
43            member_id: KafkaString::default(),
44            group_instance_id: None,
45            protocol_type: KafkaString::default(),
46            protocols: Vec::new(),
47            reason: None,
48            _unknown_tagged_fields: Vec::new(),
49        }
50    }
51}
52impl JoinGroupRequestData {
53    pub fn with_group_id(mut self, value: KafkaString) -> Self {
54        self.group_id = value;
55        self
56    }
57    pub fn with_session_timeout_ms(mut self, value: i32) -> Self {
58        self.session_timeout_ms = value;
59        self
60    }
61    pub fn with_rebalance_timeout_ms(mut self, value: i32) -> Self {
62        self.rebalance_timeout_ms = value;
63        self
64    }
65    pub fn with_member_id(mut self, value: KafkaString) -> Self {
66        self.member_id = value;
67        self
68    }
69    pub fn with_group_instance_id(mut self, value: Option<KafkaString>) -> Self {
70        self.group_instance_id = value;
71        self
72    }
73    pub fn with_protocol_type(mut self, value: KafkaString) -> Self {
74        self.protocol_type = value;
75        self
76    }
77    pub fn with_protocols(mut self, value: Vec<JoinGroupRequestProtocol>) -> Self {
78        self.protocols = value;
79        self
80    }
81    pub fn with_reason(mut self, value: Option<KafkaString>) -> Self {
82        self.reason = value;
83        self
84    }
85    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
86        if version < 0 || version > 9 {
87            return Err(UnsupportedVersion::new(11, version).into());
88        }
89        let group_id;
90        let session_timeout_ms;
91        let mut rebalance_timeout_ms = -1i32;
92        let member_id;
93        let mut group_instance_id = None;
94        let protocol_type;
95        let protocols;
96        let mut reason = None;
97        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
98        if version >= 6 {
99            group_id = read_compact_string(buf)?;
100        } else {
101            group_id = read_string(buf)?;
102        }
103        session_timeout_ms = read_i32(buf)?;
104        if version >= 1 {
105            rebalance_timeout_ms = read_i32(buf)?;
106        }
107        if version >= 6 {
108            member_id = read_compact_string(buf)?;
109        } else {
110            member_id = read_string(buf)?;
111        }
112        if version >= 5 {
113            if version >= 6 {
114                group_instance_id = read_compact_nullable_string(buf)?;
115            } else {
116                group_instance_id = read_nullable_string(buf)?;
117            }
118        }
119        if version >= 6 {
120            protocol_type = read_compact_string(buf)?;
121        } else {
122            protocol_type = read_string(buf)?;
123        }
124        if version >= 6 {
125            protocols = {
126                let len = read_compact_array_length(buf)?;
127                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
128                for _ in 0..len {
129                    arr.push(JoinGroupRequestProtocol::read(buf, version)?);
130                }
131                arr
132            };
133        } else {
134            protocols = {
135                let len = read_array_length(buf)?;
136                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
137                for _ in 0..len {
138                    arr.push(JoinGroupRequestProtocol::read(buf, version)?);
139                }
140                arr
141            };
142        }
143        if version >= 8 {
144            reason = read_compact_nullable_string(buf)?;
145        }
146        if version >= 6 {
147            let tagged_fields = read_tagged_fields(buf)?;
148            for field in &tagged_fields {
149                match field.tag {
150                    _ => {
151                        _unknown_tagged_fields.push(field.clone());
152                    },
153                }
154            }
155        }
156        Ok(Self {
157            group_id,
158            session_timeout_ms,
159            rebalance_timeout_ms,
160            member_id,
161            group_instance_id,
162            protocol_type,
163            protocols,
164            reason,
165            _unknown_tagged_fields,
166        })
167    }
168    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
169        if version < 0 || version > 9 {
170            return Err(UnsupportedVersion::new(11, version).into());
171        }
172        if version >= 6 {
173            write_compact_string(buf, &self.group_id)?;
174        } else {
175            write_string(buf, &self.group_id)?;
176        }
177        write_i32(buf, self.session_timeout_ms);
178        if version >= 1 {
179            write_i32(buf, self.rebalance_timeout_ms);
180        } else if self.rebalance_timeout_ms != -1i32 {
181            return Err(UnsupportedFieldVersion::new(11, "rebalance_timeout_ms", version).into());
182        }
183        if version >= 6 {
184            write_compact_string(buf, &self.member_id)?;
185        } else {
186            write_string(buf, &self.member_id)?;
187        }
188        if version >= 5 {
189            if version >= 6 {
190                write_compact_nullable_string(buf, self.group_instance_id.as_ref())?;
191            } else {
192                write_nullable_string(buf, self.group_instance_id.as_ref())?;
193            }
194        } else if self.group_instance_id != None {
195            return Err(UnsupportedFieldVersion::new(11, "group_instance_id", version).into());
196        }
197        if version >= 6 {
198            write_compact_string(buf, &self.protocol_type)?;
199        } else {
200            write_string(buf, &self.protocol_type)?;
201        }
202        if version >= 6 {
203            write_compact_array_length(buf, self.protocols.len() as i32);
204            for el in &self.protocols {
205                el.write(buf, version)?;
206            }
207        } else {
208            write_array_length(buf, self.protocols.len() as i32);
209            for el in &self.protocols {
210                el.write(buf, version)?;
211            }
212        }
213        if version >= 8 {
214            write_compact_nullable_string(buf, self.reason.as_ref())?;
215        } else if self.reason != None {
216            return Err(UnsupportedFieldVersion::new(11, "reason", version).into());
217        }
218        if version >= 6 {
219            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
220            all_tags.sort_by_key(|f| f.tag);
221            write_tagged_fields(buf, &all_tags)?;
222        }
223        Ok(())
224    }
225    pub fn encoded_len(&self, version: i16) -> Result<usize> {
226        if version < 0 || version > 9 {
227            return Err(UnsupportedVersion::new(11, version).into());
228        }
229        let mut len: usize = 0;
230        if version >= 6 {
231            len += compact_string_len(&self.group_id)?;
232        } else {
233            len += string_len(&self.group_id)?;
234        }
235        len += 4;
236        if version >= 1 {
237            len += 4;
238        } else if self.rebalance_timeout_ms != -1i32 {
239            return Err(UnsupportedFieldVersion::new(11, "rebalance_timeout_ms", version).into());
240        }
241        if version >= 6 {
242            len += compact_string_len(&self.member_id)?;
243        } else {
244            len += string_len(&self.member_id)?;
245        }
246        if version >= 5 {
247            if version >= 6 {
248                len += compact_nullable_string_len(self.group_instance_id.as_ref())?;
249            } else {
250                len += nullable_string_len(self.group_instance_id.as_ref())?;
251            }
252        } else if self.group_instance_id != None {
253            return Err(UnsupportedFieldVersion::new(11, "group_instance_id", version).into());
254        }
255        if version >= 6 {
256            len += compact_string_len(&self.protocol_type)?;
257        } else {
258            len += string_len(&self.protocol_type)?;
259        }
260        if version >= 6 {
261            len += compact_array_length_len(self.protocols.len() as i32);
262            for el in &self.protocols {
263                len += el.encoded_len(version)?;
264            }
265        } else {
266            len += array_length_len();
267            for el in &self.protocols {
268                len += el.encoded_len(version)?;
269            }
270        }
271        if version >= 8 {
272            len += compact_nullable_string_len(self.reason.as_ref())?;
273        } else if self.reason != None {
274            return Err(UnsupportedFieldVersion::new(11, "reason", version).into());
275        }
276        if version >= 6 {
277            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
278            all_tags.sort_by_key(|f| f.tag);
279            len += tagged_fields_len(&all_tags)?;
280        }
281        Ok(len)
282    }
283}
284#[derive(Debug, Clone, PartialEq)]
285pub struct JoinGroupRequestProtocol {
286    /// The protocol name.
287    pub name: KafkaString,
288    /// The protocol metadata.
289    pub metadata: Bytes,
290    pub _unknown_tagged_fields: Vec<RawTaggedField>,
291}
292impl Default for JoinGroupRequestProtocol {
293    fn default() -> Self {
294        Self {
295            name: KafkaString::default(),
296            metadata: Bytes::new(),
297            _unknown_tagged_fields: Vec::new(),
298        }
299    }
300}
301impl JoinGroupRequestProtocol {
302    pub fn with_name(mut self, value: KafkaString) -> Self {
303        self.name = value;
304        self
305    }
306    pub fn with_metadata(mut self, value: Bytes) -> Self {
307        self.metadata = value;
308        self
309    }
310    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
311        let name;
312        let metadata;
313        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
314        if version >= 6 {
315            name = read_compact_string(buf)?;
316        } else {
317            name = read_string(buf)?;
318        }
319        if version >= 6 {
320            metadata = read_compact_bytes(buf)?;
321        } else {
322            metadata = read_bytes(buf)?;
323        }
324        if version >= 6 {
325            let tagged_fields = read_tagged_fields(buf)?;
326            for field in &tagged_fields {
327                match field.tag {
328                    _ => {
329                        _unknown_tagged_fields.push(field.clone());
330                    },
331                }
332            }
333        }
334        Ok(Self {
335            name,
336            metadata,
337            _unknown_tagged_fields,
338        })
339    }
340    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
341        if version >= 6 {
342            write_compact_string(buf, &self.name)?;
343        } else {
344            write_string(buf, &self.name)?;
345        }
346        if version >= 6 {
347            write_compact_bytes(buf, &self.metadata)?;
348        } else {
349            write_bytes(buf, &self.metadata)?;
350        }
351        if version >= 6 {
352            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
353            all_tags.sort_by_key(|f| f.tag);
354            write_tagged_fields(buf, &all_tags)?;
355        }
356        Ok(())
357    }
358    pub fn encoded_len(&self, version: i16) -> Result<usize> {
359        let mut len: usize = 0;
360        if version >= 6 {
361            len += compact_string_len(&self.name)?;
362        } else {
363            len += string_len(&self.name)?;
364        }
365        if version >= 6 {
366            len += compact_bytes_len(&self.metadata)?;
367        } else {
368            len += bytes_len(&self.metadata)?;
369        }
370        if version >= 6 {
371            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
372            all_tags.sort_by_key(|f| f.tag);
373            len += tagged_fields_len(&all_tags)?;
374        }
375        Ok(len)
376    }
377}