Skip to main content

odradek_protocol/messages/
consumer_group_heartbeat_request.rs

1//! `ConsumerGroupHeartbeatRequest` — generated from `schemas/ConsumerGroupHeartbeatRequest.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    true
25}
26
27/// `ConsumerGroupHeartbeatRequest`, versions 0-1.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct ConsumerGroupHeartbeatRequest {
31    /// The group identifier.
32    pub group_id: String,
33    /// The member id generated by the consumer. The member id must be kept during the entire lifetime of the consumer process.
34    pub member_id: String,
35    /// The current member epoch; 0 to join the group; -1 to leave the group; -2 to indicate that the static member will rejoin.
36    pub member_epoch: i32,
37    /// null if not provided or if it didn't change since the last heartbeat; the instance Id otherwise.
38    pub instance_id: Option<String>,
39    /// null if not provided or if it didn't change since the last heartbeat; the rack ID of consumer otherwise.
40    pub rack_id: Option<String>,
41    /// -1 if it didn't change since the last heartbeat; the maximum time in milliseconds that the coordinator will wait on the member to revoke its partitions otherwise.
42    pub rebalance_timeout_ms: i32,
43    /// null if it didn't change since the last heartbeat; the subscribed topic names otherwise.
44    pub subscribed_topic_names: Option<Vec<String>>,
45    /// null if it didn't change since the last heartbeat; the subscribed topic regex otherwise.
46    pub subscribed_topic_regex: Option<String>,
47    /// null if not used or if it didn't change since the last heartbeat; the server side assignor to use otherwise.
48    pub server_assignor: Option<String>,
49    /// null if it didn't change since the last heartbeat; the partitions owned by the member.
50    pub topic_partitions: Option<Vec<TopicPartitions>>,
51    /// Tagged fields not (yet) known to this crate, kept raw.
52    pub unknown_tagged_fields: Vec<RawTaggedField>,
53}
54
55impl Default for ConsumerGroupHeartbeatRequest {
56    fn default() -> Self {
57        Self {
58            group_id: String::new(),
59            member_id: String::new(),
60            member_epoch: 0,
61            instance_id: None,
62            rack_id: None,
63            rebalance_timeout_ms: -1,
64            subscribed_topic_names: None,
65            subscribed_topic_regex: None,
66            server_assignor: None,
67            topic_partitions: None,
68            unknown_tagged_fields: Vec::new(),
69        }
70    }
71}
72
73impl ConsumerGroupHeartbeatRequest {
74    /// This message's api key in Kafka's registry.
75    pub const API_KEY: i16 = 68;
76    /// The lowest schema version this snapshot can speak.
77    pub const MIN_VERSION: i16 = 0;
78    /// The highest schema version this snapshot can speak.
79    pub const MAX_VERSION: i16 = 1;
80
81    /// Encode this `ConsumerGroupHeartbeatRequest` at `version`.
82    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
83        if is_flexible(version) {
84            wire::put_compact_string(buf, &self.group_id);
85        } else {
86            wire::put_string(buf, &self.group_id)?;
87        }
88        if is_flexible(version) {
89            wire::put_compact_string(buf, &self.member_id);
90        } else {
91            wire::put_string(buf, &self.member_id)?;
92        }
93        buf.put_i32(self.member_epoch);
94        if is_flexible(version) {
95            wire::put_compact_nullable_string(buf, self.instance_id.as_deref());
96        } else {
97            wire::put_nullable_string(buf, self.instance_id.as_deref())?;
98        }
99        if is_flexible(version) {
100            wire::put_compact_nullable_string(buf, self.rack_id.as_deref());
101        } else {
102            wire::put_nullable_string(buf, self.rack_id.as_deref())?;
103        }
104        buf.put_i32(self.rebalance_timeout_ms);
105        match &self.subscribed_topic_names {
106            Some(items) => {
107                if is_flexible(version) {
108                    wire::put_compact_array_len(buf, Some(items.len()));
109                } else {
110                    wire::put_array_len(buf, Some(items.len()))?;
111                }
112                for item in items {
113                    if is_flexible(version) {
114                        wire::put_compact_string(buf, item);
115                    } else {
116                        wire::put_string(buf, item)?;
117                    }
118                }
119            }
120            None => {
121                if is_flexible(version) {
122                    wire::put_compact_array_len(buf, None);
123                } else {
124                    wire::put_array_len(buf, None)?;
125                }
126            }
127        }
128        if version >= 1 {
129            if is_flexible(version) {
130                wire::put_compact_nullable_string(buf, self.subscribed_topic_regex.as_deref());
131            } else {
132                wire::put_nullable_string(buf, self.subscribed_topic_regex.as_deref())?;
133            }
134        }
135        if is_flexible(version) {
136            wire::put_compact_nullable_string(buf, self.server_assignor.as_deref());
137        } else {
138            wire::put_nullable_string(buf, self.server_assignor.as_deref())?;
139        }
140        match &self.topic_partitions {
141            Some(items) => {
142                if is_flexible(version) {
143                    wire::put_compact_array_len(buf, Some(items.len()));
144                } else {
145                    wire::put_array_len(buf, Some(items.len()))?;
146                }
147                for item in items {
148                    item.encode(buf, version)?;
149                }
150            }
151            None => {
152                if is_flexible(version) {
153                    wire::put_compact_array_len(buf, None);
154                } else {
155                    wire::put_array_len(buf, None)?;
156                }
157            }
158        }
159        if is_flexible(version) {
160            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
161        }
162        Ok(())
163    }
164
165    /// Decode one `ConsumerGroupHeartbeatRequest`, bounding allocation by the default
166    /// [`Limits`] derived from `buf`'s remaining length.
167    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
168        Self::decode_with_limits(buf, version, Limits::default())
169    }
170
171    /// Decode one `ConsumerGroupHeartbeatRequest` under `limits`.
172    pub fn decode_with_limits(
173        buf: &mut impl Buf,
174        version: i16,
175        limits: Limits,
176    ) -> Result<Self, DecodeError> {
177        let mut budget = limits.budget(buf.remaining());
178        Self::decode_with_budget(buf, version, &mut budget)
179    }
180
181    /// Decode one `ConsumerGroupHeartbeatRequest` against an existing `budget`.
182    pub fn decode_with_budget(
183        buf: &mut impl Buf,
184        version: i16,
185        budget: &mut Budget,
186    ) -> Result<Self, DecodeError> {
187        let mut this = Self::default();
188        this.group_id = if is_flexible(version) {
189            wire::get_compact_string(buf)?
190        } else {
191            wire::get_string(buf)?
192        };
193        this.member_id = if is_flexible(version) {
194            wire::get_compact_string(buf)?
195        } else {
196            wire::get_string(buf)?
197        };
198        this.member_epoch = wire::get_i32(buf)?;
199        this.instance_id = if is_flexible(version) {
200            wire::get_compact_nullable_string(buf)?
201        } else {
202            wire::get_nullable_string(buf)?
203        };
204        this.rack_id = if is_flexible(version) {
205            wire::get_compact_nullable_string(buf)?
206        } else {
207            wire::get_nullable_string(buf)?
208        };
209        this.rebalance_timeout_ms = wire::get_i32(buf)?;
210        this.subscribed_topic_names = {
211            let len = if is_flexible(version) {
212                wire::get_compact_array_len(buf)?
213            } else {
214                wire::get_array_len(buf)?
215            };
216            match len {
217                None => None,
218                Some(n) => {
219                    let mut items = Vec::new();
220                    for _ in 0..n {
221                        budget.push(
222                            &mut items,
223                            if is_flexible(version) {
224                                wire::get_compact_string(buf)?
225                            } else {
226                                wire::get_string(buf)?
227                            },
228                        )?;
229                    }
230                    Some(items)
231                }
232            }
233        };
234        if version >= 1 {
235            this.subscribed_topic_regex = if is_flexible(version) {
236                wire::get_compact_nullable_string(buf)?
237            } else {
238                wire::get_nullable_string(buf)?
239            };
240        }
241        this.server_assignor = if is_flexible(version) {
242            wire::get_compact_nullable_string(buf)?
243        } else {
244            wire::get_nullable_string(buf)?
245        };
246        this.topic_partitions = {
247            let len = if is_flexible(version) {
248                wire::get_compact_array_len(buf)?
249            } else {
250                wire::get_array_len(buf)?
251            };
252            match len {
253                None => None,
254                Some(n) => {
255                    let mut items = Vec::new();
256                    for _ in 0..n {
257                        let mark = buf.remaining();
258                        let item = TopicPartitions::decode_with_budget(buf, version, budget)?;
259                        budget.progress(mark, buf.remaining())?;
260                        budget.push(&mut items, item)?;
261                    }
262                    Some(items)
263                }
264            }
265        };
266        if is_flexible(version) {
267            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
268        }
269        Ok(this)
270    }
271}
272
273impl crate::Message for ConsumerGroupHeartbeatRequest {
274    const API_KEY: i16 = 68;
275    const MIN_VERSION: i16 = 0;
276    const MAX_VERSION: i16 = 1;
277
278    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
279        ConsumerGroupHeartbeatRequest::encode(self, buf, version)
280    }
281    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
282        ConsumerGroupHeartbeatRequest::decode(buf, version)
283    }
284    fn decode_with_limits(
285        buf: &mut impl Buf,
286        version: i16,
287        limits: Limits,
288    ) -> Result<Self, DecodeError> {
289        ConsumerGroupHeartbeatRequest::decode_with_limits(buf, version, limits)
290    }
291}
292
293/// `TopicPartitions` (nested in [`ConsumerGroupHeartbeatRequest`]).
294#[derive(Debug, Clone, PartialEq)]
295#[non_exhaustive]
296pub struct TopicPartitions {
297    /// The topic ID.
298    pub topic_id: [u8; 16],
299    /// The partitions.
300    pub partitions: Vec<i32>,
301    /// Tagged fields not (yet) known to this crate, kept raw.
302    pub unknown_tagged_fields: Vec<RawTaggedField>,
303}
304
305impl Default for TopicPartitions {
306    fn default() -> Self {
307        Self {
308            topic_id: [0u8; 16],
309            partitions: Vec::new(),
310            unknown_tagged_fields: Vec::new(),
311        }
312    }
313}
314
315impl TopicPartitions {
316    /// Encode this `TopicPartitions` at `version`.
317    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
318        wire::put_uuid(buf, self.topic_id);
319        if is_flexible(version) {
320            wire::put_compact_array_len(buf, Some(self.partitions.len()));
321        } else {
322            wire::put_array_len(buf, Some(self.partitions.len()))?;
323        }
324        for item in &self.partitions {
325            buf.put_i32(*item);
326        }
327        if is_flexible(version) {
328            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
329        }
330        Ok(())
331    }
332
333    /// Decode one `TopicPartitions`, bounding allocation by the default
334    /// [`Limits`] derived from `buf`'s remaining length.
335    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
336        Self::decode_with_limits(buf, version, Limits::default())
337    }
338
339    /// Decode one `TopicPartitions` under `limits`.
340    pub fn decode_with_limits(
341        buf: &mut impl Buf,
342        version: i16,
343        limits: Limits,
344    ) -> Result<Self, DecodeError> {
345        let mut budget = limits.budget(buf.remaining());
346        Self::decode_with_budget(buf, version, &mut budget)
347    }
348
349    /// Decode one `TopicPartitions` against an existing `budget`.
350    pub fn decode_with_budget(
351        buf: &mut impl Buf,
352        version: i16,
353        budget: &mut Budget,
354    ) -> Result<Self, DecodeError> {
355        let mut this = Self::default();
356        this.topic_id = wire::get_uuid(buf)?;
357        this.partitions = {
358            let len = if is_flexible(version) {
359                wire::get_compact_array_len(buf)?
360            } else {
361                wire::get_array_len(buf)?
362            };
363            match len {
364                None => return Err(DecodeError::InvalidLength(-1)),
365                Some(n) => {
366                    let mut items = Vec::new();
367                    for _ in 0..n {
368                        budget.push(&mut items, wire::get_i32(buf)?)?;
369                    }
370                    items
371                }
372            }
373        };
374        if is_flexible(version) {
375            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
376        }
377        Ok(this)
378    }
379}