Skip to main content

kacrab_protocol/generated/
consumer_group_heartbeat_request.rs

1//! Generated from ConsumerGroupHeartbeatRequest.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 ConsumerGroupHeartbeatRequestData {
17    /// The group identifier.
18    pub group_id: KafkaString,
19    /// The member id generated by the consumer. The member id must be kept during the entire
20    /// lifetime of the consumer process.
21    pub member_id: KafkaString,
22    /// The current member epoch; 0 to join the group; -1 to leave the group; -2 to indicate that
23    /// the static member will rejoin.
24    pub member_epoch: i32,
25    /// null if not provided or if it didn't change since the last heartbeat; the instance Id
26    /// otherwise.
27    pub instance_id: Option<KafkaString>,
28    /// null if not provided or if it didn't change since the last heartbeat; the rack ID of
29    /// consumer otherwise.
30    pub rack_id: Option<KafkaString>,
31    /// -1 if it didn't change since the last heartbeat; the maximum time in milliseconds that the
32    /// coordinator will wait on the member to revoke its partitions otherwise.
33    pub rebalance_timeout_ms: i32,
34    /// null if it didn't change since the last heartbeat; the subscribed topic names otherwise.
35    pub subscribed_topic_names: Option<Vec<KafkaString>>,
36    /// null if it didn't change since the last heartbeat; the subscribed topic regex otherwise.
37    pub subscribed_topic_regex: Option<KafkaString>,
38    /// null if not used or if it didn't change since the last heartbeat; the server side assignor
39    /// to use otherwise.
40    pub server_assignor: Option<KafkaString>,
41    /// null if it didn't change since the last heartbeat; the partitions owned by the member.
42    pub topic_partitions: Option<Vec<TopicPartitions>>,
43    pub _unknown_tagged_fields: Vec<RawTaggedField>,
44}
45impl Default for ConsumerGroupHeartbeatRequestData {
46    fn default() -> Self {
47        Self {
48            group_id: KafkaString::default(),
49            member_id: KafkaString::default(),
50            member_epoch: 0_i32,
51            instance_id: None,
52            rack_id: None,
53            rebalance_timeout_ms: -1i32,
54            subscribed_topic_names: None,
55            subscribed_topic_regex: None,
56            server_assignor: None,
57            topic_partitions: None,
58            _unknown_tagged_fields: Vec::new(),
59        }
60    }
61}
62impl ConsumerGroupHeartbeatRequestData {
63    pub fn with_group_id(mut self, value: KafkaString) -> Self {
64        self.group_id = value;
65        self
66    }
67    pub fn with_member_id(mut self, value: KafkaString) -> Self {
68        self.member_id = value;
69        self
70    }
71    pub fn with_member_epoch(mut self, value: i32) -> Self {
72        self.member_epoch = value;
73        self
74    }
75    pub fn with_instance_id(mut self, value: Option<KafkaString>) -> Self {
76        self.instance_id = value;
77        self
78    }
79    pub fn with_rack_id(mut self, value: Option<KafkaString>) -> Self {
80        self.rack_id = value;
81        self
82    }
83    pub fn with_rebalance_timeout_ms(mut self, value: i32) -> Self {
84        self.rebalance_timeout_ms = value;
85        self
86    }
87    pub fn with_subscribed_topic_names(mut self, value: Option<Vec<KafkaString>>) -> Self {
88        self.subscribed_topic_names = value;
89        self
90    }
91    pub fn with_subscribed_topic_regex(mut self, value: Option<KafkaString>) -> Self {
92        self.subscribed_topic_regex = value;
93        self
94    }
95    pub fn with_server_assignor(mut self, value: Option<KafkaString>) -> Self {
96        self.server_assignor = value;
97        self
98    }
99    pub fn with_topic_partitions(mut self, value: Option<Vec<TopicPartitions>>) -> Self {
100        self.topic_partitions = value;
101        self
102    }
103    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
104        if version < 0 || version > 1 {
105            return Err(UnsupportedVersion::new(68, version).into());
106        }
107        let group_id;
108        let member_id;
109        let member_epoch;
110        let instance_id;
111        let rack_id;
112        let rebalance_timeout_ms;
113        let subscribed_topic_names;
114        let mut subscribed_topic_regex = None;
115        let server_assignor;
116        let topic_partitions;
117        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
118        group_id = read_compact_string(buf)?;
119        member_id = read_compact_string(buf)?;
120        member_epoch = read_i32(buf)?;
121        instance_id = read_compact_nullable_string(buf)?;
122        rack_id = read_compact_nullable_string(buf)?;
123        rebalance_timeout_ms = read_i32(buf)?;
124        subscribed_topic_names = {
125            let len = read_compact_array_length(buf)?;
126            if len < 0 {
127                None
128            } else {
129                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
130                for _ in 0..len {
131                    arr.push(read_compact_string(buf)?);
132                }
133                Some(arr)
134            }
135        };
136        if version >= 1 {
137            subscribed_topic_regex = read_compact_nullable_string(buf)?;
138        }
139        server_assignor = read_compact_nullable_string(buf)?;
140        topic_partitions = {
141            let len = read_compact_array_length(buf)?;
142            if len < 0 {
143                None
144            } else {
145                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
146                for _ in 0..len {
147                    arr.push(TopicPartitions::read(buf, version)?);
148                }
149                Some(arr)
150            }
151        };
152        let tagged_fields = read_tagged_fields(buf)?;
153        for field in &tagged_fields {
154            match field.tag {
155                _ => {
156                    _unknown_tagged_fields.push(field.clone());
157                },
158            }
159        }
160        Ok(Self {
161            group_id,
162            member_id,
163            member_epoch,
164            instance_id,
165            rack_id,
166            rebalance_timeout_ms,
167            subscribed_topic_names,
168            subscribed_topic_regex,
169            server_assignor,
170            topic_partitions,
171            _unknown_tagged_fields,
172        })
173    }
174    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
175        if version < 0 || version > 1 {
176            return Err(UnsupportedVersion::new(68, version).into());
177        }
178        write_compact_string(buf, &self.group_id)?;
179        write_compact_string(buf, &self.member_id)?;
180        write_i32(buf, self.member_epoch);
181        write_compact_nullable_string(buf, self.instance_id.as_ref())?;
182        write_compact_nullable_string(buf, self.rack_id.as_ref())?;
183        write_i32(buf, self.rebalance_timeout_ms);
184        match &self.subscribed_topic_names {
185            None => {
186                write_compact_array_length(buf, -1);
187            },
188            Some(arr) => {
189                write_compact_array_length(buf, arr.len() as i32);
190                for el in arr {
191                    write_compact_string(buf, el)?;
192                }
193            },
194        }
195        if version >= 1 {
196            write_compact_nullable_string(buf, self.subscribed_topic_regex.as_ref())?;
197        } else if self.subscribed_topic_regex != None {
198            return Err(UnsupportedFieldVersion::new(68, "subscribed_topic_regex", version).into());
199        }
200        write_compact_nullable_string(buf, self.server_assignor.as_ref())?;
201        match &self.topic_partitions {
202            None => {
203                write_compact_array_length(buf, -1);
204            },
205            Some(arr) => {
206                write_compact_array_length(buf, arr.len() as i32);
207                for el in arr {
208                    el.write(buf, version)?;
209                }
210            },
211        }
212        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
213        all_tags.sort_by_key(|f| f.tag);
214        write_tagged_fields(buf, &all_tags)?;
215        Ok(())
216    }
217    pub fn encoded_len(&self, version: i16) -> Result<usize> {
218        if version < 0 || version > 1 {
219            return Err(UnsupportedVersion::new(68, version).into());
220        }
221        let mut len: usize = 0;
222        len += compact_string_len(&self.group_id)?;
223        len += compact_string_len(&self.member_id)?;
224        len += 4;
225        len += compact_nullable_string_len(self.instance_id.as_ref())?;
226        len += compact_nullable_string_len(self.rack_id.as_ref())?;
227        len += 4;
228        match &self.subscribed_topic_names {
229            None => {
230                len += compact_array_length_len(-1);
231            },
232            Some(arr) => {
233                len += compact_array_length_len(arr.len() as i32);
234                for el in arr {
235                    len += compact_string_len(el)?;
236                }
237            },
238        }
239        if version >= 1 {
240            len += compact_nullable_string_len(self.subscribed_topic_regex.as_ref())?;
241        } else if self.subscribed_topic_regex != None {
242            return Err(UnsupportedFieldVersion::new(68, "subscribed_topic_regex", version).into());
243        }
244        len += compact_nullable_string_len(self.server_assignor.as_ref())?;
245        match &self.topic_partitions {
246            None => {
247                len += compact_array_length_len(-1);
248            },
249            Some(arr) => {
250                len += compact_array_length_len(arr.len() as i32);
251                for el in arr {
252                    len += el.encoded_len(version)?;
253                }
254            },
255        }
256        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
257        all_tags.sort_by_key(|f| f.tag);
258        len += tagged_fields_len(&all_tags)?;
259        Ok(len)
260    }
261}
262#[derive(Debug, Clone, PartialEq)]
263pub struct TopicPartitions {
264    /// The topic ID.
265    pub topic_id: KafkaUuid,
266    /// The partitions.
267    pub partitions: Vec<i32>,
268    pub _unknown_tagged_fields: Vec<RawTaggedField>,
269}
270impl Default for TopicPartitions {
271    fn default() -> Self {
272        Self {
273            topic_id: KafkaUuid::ZERO,
274            partitions: Vec::new(),
275            _unknown_tagged_fields: Vec::new(),
276        }
277    }
278}
279impl TopicPartitions {
280    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
281        self.topic_id = value;
282        self
283    }
284    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
285        self.partitions = value;
286        self
287    }
288    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
289        let topic_id;
290        let partitions;
291        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
292        topic_id = read_uuid(buf)?;
293        partitions = {
294            let len = read_compact_array_length(buf)?;
295            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
296            for _ in 0..len {
297                arr.push(read_i32(buf)?);
298            }
299            arr
300        };
301        let tagged_fields = read_tagged_fields(buf)?;
302        for field in &tagged_fields {
303            match field.tag {
304                _ => {
305                    _unknown_tagged_fields.push(field.clone());
306                },
307            }
308        }
309        Ok(Self {
310            topic_id,
311            partitions,
312            _unknown_tagged_fields,
313        })
314    }
315    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
316        write_uuid(buf, &self.topic_id);
317        write_compact_array_length(buf, self.partitions.len() as i32);
318        for el in &self.partitions {
319            write_i32(buf, *el);
320        }
321        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
322        all_tags.sort_by_key(|f| f.tag);
323        write_tagged_fields(buf, &all_tags)?;
324        Ok(())
325    }
326    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
327        let mut len: usize = 0;
328        len += 16;
329        len += compact_array_length_len(self.partitions.len() as i32);
330        len += self.partitions.len() * 4usize;
331        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
332        all_tags.sort_by_key(|f| f.tag);
333        len += tagged_fields_len(&all_tags)?;
334        Ok(len)
335    }
336}