Skip to main content

odradek_protocol/messages/
sync_group_request.rs

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