Skip to main content

odradek_protocol/messages/
leave_group_request.rs

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