Skip to main content

odradek_protocol/messages/
join_group_response.rs

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