Skip to main content

odradek_protocol/messages/
leave_group_response.rs

1//! `LeaveGroupResponse` — generated from `schemas/LeaveGroupResponse.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 >= 4
25}
26
27/// `LeaveGroupResponse`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct LeaveGroupResponse {
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    /// List of leaving member responses.
36    pub members: Vec<MemberResponse>,
37    /// Tagged fields not (yet) known to this crate, kept raw.
38    pub unknown_tagged_fields: Vec<RawTaggedField>,
39}
40
41impl Default for LeaveGroupResponse {
42    fn default() -> Self {
43        Self {
44            throttle_time_ms: 0,
45            error_code: 0,
46            members: Vec::new(),
47            unknown_tagged_fields: Vec::new(),
48        }
49    }
50}
51
52impl LeaveGroupResponse {
53    /// This message's api key in Kafka's registry.
54    pub const API_KEY: i16 = 13;
55    /// The lowest schema version this snapshot can speak.
56    pub const MIN_VERSION: i16 = 0;
57    /// The highest schema version this snapshot can speak.
58    pub const MAX_VERSION: i16 = 5;
59
60    /// Encode this `LeaveGroupResponse` at `version`.
61    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
62        if version >= 1 {
63            buf.put_i32(self.throttle_time_ms);
64        }
65        buf.put_i16(self.error_code);
66        if version >= 3 {
67            if is_flexible(version) {
68                wire::put_compact_array_len(buf, Some(self.members.len()));
69            } else {
70                wire::put_array_len(buf, Some(self.members.len()))?;
71            }
72            for item in &self.members {
73                item.encode(buf, version)?;
74            }
75        }
76        if is_flexible(version) {
77            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
78        }
79        Ok(())
80    }
81
82    /// Decode one `LeaveGroupResponse`, bounding allocation by the default
83    /// [`Limits`] derived from `buf`'s remaining length.
84    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
85        Self::decode_with_limits(buf, version, Limits::default())
86    }
87
88    /// Decode one `LeaveGroupResponse` under `limits`.
89    pub fn decode_with_limits(
90        buf: &mut impl Buf,
91        version: i16,
92        limits: Limits,
93    ) -> Result<Self, DecodeError> {
94        let mut budget = limits.budget(buf.remaining());
95        Self::decode_with_budget(buf, version, &mut budget)
96    }
97
98    /// Decode one `LeaveGroupResponse` against an existing `budget`.
99    pub fn decode_with_budget(
100        buf: &mut impl Buf,
101        version: i16,
102        budget: &mut Budget,
103    ) -> Result<Self, DecodeError> {
104        let mut this = Self::default();
105        if version >= 1 {
106            this.throttle_time_ms = wire::get_i32(buf)?;
107        }
108        this.error_code = wire::get_i16(buf)?;
109        if version >= 3 {
110            this.members = {
111                let len = if is_flexible(version) {
112                    wire::get_compact_array_len(buf)?
113                } else {
114                    wire::get_array_len(buf)?
115                };
116                match len {
117                    None => return Err(DecodeError::InvalidLength(-1)),
118                    Some(n) => {
119                        let mut items = Vec::new();
120                        for _ in 0..n {
121                            let mark = buf.remaining();
122                            let item = MemberResponse::decode_with_budget(buf, version, budget)?;
123                            budget.progress(mark, buf.remaining())?;
124                            budget.push(&mut items, item)?;
125                        }
126                        items
127                    }
128                }
129            };
130        }
131        if is_flexible(version) {
132            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
133        }
134        Ok(this)
135    }
136}
137
138impl crate::Message for LeaveGroupResponse {
139    const API_KEY: i16 = 13;
140    const MIN_VERSION: i16 = 0;
141    const MAX_VERSION: i16 = 5;
142
143    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
144        LeaveGroupResponse::encode(self, buf, version)
145    }
146    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
147        LeaveGroupResponse::decode(buf, version)
148    }
149    fn decode_with_limits(
150        buf: &mut impl Buf,
151        version: i16,
152        limits: Limits,
153    ) -> Result<Self, DecodeError> {
154        LeaveGroupResponse::decode_with_limits(buf, version, limits)
155    }
156    fn throttle_time_ms(&self) -> Option<i32> {
157        Some(self.throttle_time_ms)
158    }
159}
160
161/// `MemberResponse` (nested in [`LeaveGroupResponse`]).
162#[derive(Debug, Clone, PartialEq)]
163#[non_exhaustive]
164pub struct MemberResponse {
165    /// The member ID to remove from the group.
166    pub member_id: String,
167    /// The group instance ID to remove from the group.
168    pub group_instance_id: Option<String>,
169    /// The error code, or 0 if there was no error.
170    pub error_code: i16,
171    /// Tagged fields not (yet) known to this crate, kept raw.
172    pub unknown_tagged_fields: Vec<RawTaggedField>,
173}
174
175impl Default for MemberResponse {
176    fn default() -> Self {
177        Self {
178            member_id: String::new(),
179            group_instance_id: Some(String::new()),
180            error_code: 0,
181            unknown_tagged_fields: Vec::new(),
182        }
183    }
184}
185
186impl MemberResponse {
187    /// Encode this `MemberResponse` at `version`.
188    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
189        if version >= 3 {
190            if is_flexible(version) {
191                wire::put_compact_string(buf, &self.member_id);
192            } else {
193                wire::put_string(buf, &self.member_id)?;
194            }
195        }
196        if version >= 3 {
197            if is_flexible(version) {
198                wire::put_compact_nullable_string(buf, self.group_instance_id.as_deref());
199            } else {
200                wire::put_nullable_string(buf, self.group_instance_id.as_deref())?;
201            }
202        }
203        if version >= 3 {
204            buf.put_i16(self.error_code);
205        }
206        if is_flexible(version) {
207            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
208        }
209        Ok(())
210    }
211
212    /// Decode one `MemberResponse`, bounding allocation by the default
213    /// [`Limits`] derived from `buf`'s remaining length.
214    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
215        Self::decode_with_limits(buf, version, Limits::default())
216    }
217
218    /// Decode one `MemberResponse` under `limits`.
219    pub fn decode_with_limits(
220        buf: &mut impl Buf,
221        version: i16,
222        limits: Limits,
223    ) -> Result<Self, DecodeError> {
224        let mut budget = limits.budget(buf.remaining());
225        Self::decode_with_budget(buf, version, &mut budget)
226    }
227
228    /// Decode one `MemberResponse` against an existing `budget`.
229    pub fn decode_with_budget(
230        buf: &mut impl Buf,
231        version: i16,
232        budget: &mut Budget,
233    ) -> Result<Self, DecodeError> {
234        let mut this = Self::default();
235        if version >= 3 {
236            this.member_id = if is_flexible(version) {
237                wire::get_compact_string(buf)?
238            } else {
239                wire::get_string(buf)?
240            };
241        }
242        if version >= 3 {
243            this.group_instance_id = if is_flexible(version) {
244                wire::get_compact_nullable_string(buf)?
245            } else {
246                wire::get_nullable_string(buf)?
247            };
248        }
249        if version >= 3 {
250            this.error_code = wire::get_i16(buf)?;
251        }
252        if is_flexible(version) {
253            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
254        }
255        Ok(this)
256    }
257}