Skip to main content

odradek_protocol/messages/
join_group_request.rs

1//! `JoinGroupRequest` — generated from `schemas/JoinGroupRequest.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    version >= 6
25}
26
27/// `JoinGroupRequest`, versions 0-9.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct JoinGroupRequest {
31    /// The group identifier.
32    pub group_id: String,
33    /// The coordinator considers the consumer dead if it receives no heartbeat after this timeout in milliseconds.
34    pub session_timeout_ms: i32,
35    /// The maximum time in milliseconds that the coordinator will wait for each member to rejoin when rebalancing the group.
36    pub rebalance_timeout_ms: i32,
37    /// The member id assigned by the group coordinator.
38    pub member_id: String,
39    /// The unique identifier of the consumer instance provided by end user.
40    pub group_instance_id: Option<String>,
41    /// The unique name the for class of protocols implemented by the group we want to join.
42    pub protocol_type: String,
43    /// The list of protocols that the member supports.
44    pub protocols: Vec<JoinGroupRequestProtocol>,
45    /// The reason why the member (re-)joins the group.
46    pub reason: Option<String>,
47    /// Tagged fields not (yet) known to this crate, kept raw.
48    pub unknown_tagged_fields: Vec<RawTaggedField>,
49}
50
51impl Default for JoinGroupRequest {
52    fn default() -> Self {
53        Self {
54            group_id: String::new(),
55            session_timeout_ms: 0,
56            rebalance_timeout_ms: -1,
57            member_id: String::new(),
58            group_instance_id: None,
59            protocol_type: String::new(),
60            protocols: Vec::new(),
61            reason: None,
62            unknown_tagged_fields: Vec::new(),
63        }
64    }
65}
66
67impl JoinGroupRequest {
68    /// This message's api key in Kafka's registry.
69    pub const API_KEY: i16 = 11;
70    /// The lowest schema version this snapshot can speak.
71    pub const MIN_VERSION: i16 = 0;
72    /// The highest schema version this snapshot can speak.
73    pub const MAX_VERSION: i16 = 9;
74
75    /// Encode this `JoinGroupRequest` at `version`.
76    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
77        if is_flexible(version) {
78            wire::put_compact_string(buf, &self.group_id);
79        } else {
80            wire::put_string(buf, &self.group_id)?;
81        }
82        buf.put_i32(self.session_timeout_ms);
83        if version >= 1 {
84            buf.put_i32(self.rebalance_timeout_ms);
85        }
86        if is_flexible(version) {
87            wire::put_compact_string(buf, &self.member_id);
88        } else {
89            wire::put_string(buf, &self.member_id)?;
90        }
91        if version >= 5 {
92            if is_flexible(version) {
93                wire::put_compact_nullable_string(buf, self.group_instance_id.as_deref());
94            } else {
95                wire::put_nullable_string(buf, self.group_instance_id.as_deref())?;
96            }
97        }
98        if is_flexible(version) {
99            wire::put_compact_string(buf, &self.protocol_type);
100        } else {
101            wire::put_string(buf, &self.protocol_type)?;
102        }
103        if is_flexible(version) {
104            wire::put_compact_array_len(buf, Some(self.protocols.len()));
105        } else {
106            wire::put_array_len(buf, Some(self.protocols.len()))?;
107        }
108        for item in &self.protocols {
109            item.encode(buf, version)?;
110        }
111        if version >= 8 {
112            if is_flexible(version) {
113                wire::put_compact_nullable_string(buf, self.reason.as_deref());
114            } else {
115                wire::put_nullable_string(buf, self.reason.as_deref())?;
116            }
117        }
118        if is_flexible(version) {
119            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
120        }
121        Ok(())
122    }
123
124    /// Decode one `JoinGroupRequest`, bounding allocation by the default
125    /// [`Limits`] derived from `buf`'s remaining length.
126    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
127        Self::decode_with_limits(buf, version, Limits::default())
128    }
129
130    /// Decode one `JoinGroupRequest` under `limits`.
131    pub fn decode_with_limits(
132        buf: &mut impl Buf,
133        version: i16,
134        limits: Limits,
135    ) -> Result<Self, DecodeError> {
136        let mut budget = limits.budget(buf.remaining());
137        Self::decode_with_budget(buf, version, &mut budget)
138    }
139
140    /// Decode one `JoinGroupRequest` against an existing `budget`.
141    pub fn decode_with_budget(
142        buf: &mut impl Buf,
143        version: i16,
144        budget: &mut Budget,
145    ) -> Result<Self, DecodeError> {
146        let mut this = Self::default();
147        this.group_id = if is_flexible(version) {
148            wire::get_compact_string(buf)?
149        } else {
150            wire::get_string(buf)?
151        };
152        this.session_timeout_ms = wire::get_i32(buf)?;
153        if version >= 1 {
154            this.rebalance_timeout_ms = wire::get_i32(buf)?;
155        }
156        this.member_id = if is_flexible(version) {
157            wire::get_compact_string(buf)?
158        } else {
159            wire::get_string(buf)?
160        };
161        if version >= 5 {
162            this.group_instance_id = if is_flexible(version) {
163                wire::get_compact_nullable_string(buf)?
164            } else {
165                wire::get_nullable_string(buf)?
166            };
167        }
168        this.protocol_type = if is_flexible(version) {
169            wire::get_compact_string(buf)?
170        } else {
171            wire::get_string(buf)?
172        };
173        this.protocols = {
174            let len = if is_flexible(version) {
175                wire::get_compact_array_len(buf)?
176            } else {
177                wire::get_array_len(buf)?
178            };
179            match len {
180                None => return Err(DecodeError::InvalidLength(-1)),
181                Some(n) => {
182                    let mut items = Vec::new();
183                    for _ in 0..n {
184                        let mark = buf.remaining();
185                        let item =
186                            JoinGroupRequestProtocol::decode_with_budget(buf, version, budget)?;
187                        budget.progress(mark, buf.remaining())?;
188                        budget.push(&mut items, item)?;
189                    }
190                    items
191                }
192            }
193        };
194        if version >= 8 {
195            this.reason = if is_flexible(version) {
196                wire::get_compact_nullable_string(buf)?
197            } else {
198                wire::get_nullable_string(buf)?
199            };
200        }
201        if is_flexible(version) {
202            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
203        }
204        Ok(this)
205    }
206}
207
208impl crate::Message for JoinGroupRequest {
209    const API_KEY: i16 = 11;
210    const MIN_VERSION: i16 = 0;
211    const MAX_VERSION: i16 = 9;
212
213    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
214        JoinGroupRequest::encode(self, buf, version)
215    }
216    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
217        JoinGroupRequest::decode(buf, version)
218    }
219    fn decode_with_limits(
220        buf: &mut impl Buf,
221        version: i16,
222        limits: Limits,
223    ) -> Result<Self, DecodeError> {
224        JoinGroupRequest::decode_with_limits(buf, version, limits)
225    }
226}
227
228/// `JoinGroupRequestProtocol` (nested in [`JoinGroupRequest`]).
229#[derive(Debug, Clone, PartialEq)]
230#[non_exhaustive]
231pub struct JoinGroupRequestProtocol {
232    /// The protocol name.
233    pub name: String,
234    /// The protocol metadata.
235    pub metadata: bytes::Bytes,
236    /// Tagged fields not (yet) known to this crate, kept raw.
237    pub unknown_tagged_fields: Vec<RawTaggedField>,
238}
239
240impl Default for JoinGroupRequestProtocol {
241    fn default() -> Self {
242        Self {
243            name: String::new(),
244            metadata: bytes::Bytes::new(),
245            unknown_tagged_fields: Vec::new(),
246        }
247    }
248}
249
250impl JoinGroupRequestProtocol {
251    /// Encode this `JoinGroupRequestProtocol` at `version`.
252    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
253        if is_flexible(version) {
254            wire::put_compact_string(buf, &self.name);
255        } else {
256            wire::put_string(buf, &self.name)?;
257        }
258        if is_flexible(version) {
259            wire::put_compact_bytes(buf, &self.metadata);
260        } else {
261            wire::put_bytes(buf, &self.metadata)?;
262        }
263        if is_flexible(version) {
264            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
265        }
266        Ok(())
267    }
268
269    /// Decode one `JoinGroupRequestProtocol`, bounding allocation by the default
270    /// [`Limits`] derived from `buf`'s remaining length.
271    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
272        Self::decode_with_limits(buf, version, Limits::default())
273    }
274
275    /// Decode one `JoinGroupRequestProtocol` under `limits`.
276    pub fn decode_with_limits(
277        buf: &mut impl Buf,
278        version: i16,
279        limits: Limits,
280    ) -> Result<Self, DecodeError> {
281        let mut budget = limits.budget(buf.remaining());
282        Self::decode_with_budget(buf, version, &mut budget)
283    }
284
285    /// Decode one `JoinGroupRequestProtocol` against an existing `budget`.
286    pub fn decode_with_budget(
287        buf: &mut impl Buf,
288        version: i16,
289        budget: &mut Budget,
290    ) -> Result<Self, DecodeError> {
291        let mut this = Self::default();
292        this.name = if is_flexible(version) {
293            wire::get_compact_string(buf)?
294        } else {
295            wire::get_string(buf)?
296        };
297        this.metadata = {
298            let raw = if is_flexible(version) {
299                wire::get_compact_nullable_bytes(buf)?
300            } else {
301                wire::get_nullable_bytes(buf)?
302            };
303            match raw {
304                Some(v) => v,
305                None => return Err(DecodeError::InvalidLength(-1)),
306            }
307        };
308        if is_flexible(version) {
309            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
310        }
311        Ok(this)
312    }
313}