kacrab_protocol/generated/
sync_group_request.rs1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct SyncGroupRequestData {
17 pub group_id: KafkaString,
19 pub generation_id: i32,
21 pub member_id: KafkaString,
23 pub group_instance_id: Option<KafkaString>,
25 pub protocol_type: Option<KafkaString>,
27 pub protocol_name: Option<KafkaString>,
29 pub assignments: Vec<SyncGroupRequestAssignment>,
31 pub _unknown_tagged_fields: Vec<RawTaggedField>,
32}
33impl Default for SyncGroupRequestData {
34 fn default() -> Self {
35 Self {
36 group_id: KafkaString::default(),
37 generation_id: 0_i32,
38 member_id: KafkaString::default(),
39 group_instance_id: None,
40 protocol_type: None,
41 protocol_name: None,
42 assignments: Vec::new(),
43 _unknown_tagged_fields: Vec::new(),
44 }
45 }
46}
47impl SyncGroupRequestData {
48 pub fn with_group_id(mut self, value: KafkaString) -> Self {
49 self.group_id = value;
50 self
51 }
52 pub fn with_generation_id(mut self, value: i32) -> Self {
53 self.generation_id = value;
54 self
55 }
56 pub fn with_member_id(mut self, value: KafkaString) -> Self {
57 self.member_id = value;
58 self
59 }
60 pub fn with_group_instance_id(mut self, value: Option<KafkaString>) -> Self {
61 self.group_instance_id = value;
62 self
63 }
64 pub fn with_protocol_type(mut self, value: Option<KafkaString>) -> Self {
65 self.protocol_type = value;
66 self
67 }
68 pub fn with_protocol_name(mut self, value: Option<KafkaString>) -> Self {
69 self.protocol_name = value;
70 self
71 }
72 pub fn with_assignments(mut self, value: Vec<SyncGroupRequestAssignment>) -> Self {
73 self.assignments = value;
74 self
75 }
76 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
77 if version < 0 || version > 5 {
78 return Err(UnsupportedVersion::new(14, version).into());
79 }
80 let group_id;
81 let generation_id;
82 let member_id;
83 let mut group_instance_id = None;
84 let mut protocol_type = None;
85 let mut protocol_name = None;
86 let assignments;
87 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
88 if version >= 4 {
89 group_id = read_compact_string(buf)?;
90 } else {
91 group_id = read_string(buf)?;
92 }
93 generation_id = read_i32(buf)?;
94 if version >= 4 {
95 member_id = read_compact_string(buf)?;
96 } else {
97 member_id = read_string(buf)?;
98 }
99 if version >= 3 {
100 if version >= 4 {
101 group_instance_id = read_compact_nullable_string(buf)?;
102 } else {
103 group_instance_id = read_nullable_string(buf)?;
104 }
105 }
106 if version >= 5 {
107 protocol_type = read_compact_nullable_string(buf)?;
108 }
109 if version >= 5 {
110 protocol_name = read_compact_nullable_string(buf)?;
111 }
112 if version >= 4 {
113 assignments = {
114 let len = read_compact_array_length(buf)?;
115 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
116 for _ in 0..len {
117 arr.push(SyncGroupRequestAssignment::read(buf, version)?);
118 }
119 arr
120 };
121 } else {
122 assignments = {
123 let len = read_array_length(buf)?;
124 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
125 for _ in 0..len {
126 arr.push(SyncGroupRequestAssignment::read(buf, version)?);
127 }
128 arr
129 };
130 }
131 if version >= 4 {
132 let tagged_fields = read_tagged_fields(buf)?;
133 for field in &tagged_fields {
134 match field.tag {
135 _ => {
136 _unknown_tagged_fields.push(field.clone());
137 },
138 }
139 }
140 }
141 Ok(Self {
142 group_id,
143 generation_id,
144 member_id,
145 group_instance_id,
146 protocol_type,
147 protocol_name,
148 assignments,
149 _unknown_tagged_fields,
150 })
151 }
152 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
153 if version < 0 || version > 5 {
154 return Err(UnsupportedVersion::new(14, version).into());
155 }
156 if version >= 4 {
157 write_compact_string(buf, &self.group_id)?;
158 } else {
159 write_string(buf, &self.group_id)?;
160 }
161 write_i32(buf, self.generation_id);
162 if version >= 4 {
163 write_compact_string(buf, &self.member_id)?;
164 } else {
165 write_string(buf, &self.member_id)?;
166 }
167 if version >= 3 {
168 if version >= 4 {
169 write_compact_nullable_string(buf, self.group_instance_id.as_ref())?;
170 } else {
171 write_nullable_string(buf, self.group_instance_id.as_ref())?;
172 }
173 } else if self.group_instance_id != None {
174 return Err(UnsupportedFieldVersion::new(14, "group_instance_id", version).into());
175 }
176 if version >= 5 {
177 write_compact_nullable_string(buf, self.protocol_type.as_ref())?;
178 } else if self.protocol_type != None {
179 return Err(UnsupportedFieldVersion::new(14, "protocol_type", version).into());
180 }
181 if version >= 5 {
182 write_compact_nullable_string(buf, self.protocol_name.as_ref())?;
183 } else if self.protocol_name != None {
184 return Err(UnsupportedFieldVersion::new(14, "protocol_name", version).into());
185 }
186 if version >= 4 {
187 write_compact_array_length(buf, self.assignments.len() as i32);
188 for el in &self.assignments {
189 el.write(buf, version)?;
190 }
191 } else {
192 write_array_length(buf, self.assignments.len() as i32);
193 for el in &self.assignments {
194 el.write(buf, version)?;
195 }
196 }
197 if version >= 4 {
198 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
199 all_tags.sort_by_key(|f| f.tag);
200 write_tagged_fields(buf, &all_tags)?;
201 }
202 Ok(())
203 }
204 pub fn encoded_len(&self, version: i16) -> Result<usize> {
205 if version < 0 || version > 5 {
206 return Err(UnsupportedVersion::new(14, version).into());
207 }
208 let mut len: usize = 0;
209 if version >= 4 {
210 len += compact_string_len(&self.group_id)?;
211 } else {
212 len += string_len(&self.group_id)?;
213 }
214 len += 4;
215 if version >= 4 {
216 len += compact_string_len(&self.member_id)?;
217 } else {
218 len += string_len(&self.member_id)?;
219 }
220 if version >= 3 {
221 if version >= 4 {
222 len += compact_nullable_string_len(self.group_instance_id.as_ref())?;
223 } else {
224 len += nullable_string_len(self.group_instance_id.as_ref())?;
225 }
226 } else if self.group_instance_id != None {
227 return Err(UnsupportedFieldVersion::new(14, "group_instance_id", version).into());
228 }
229 if version >= 5 {
230 len += compact_nullable_string_len(self.protocol_type.as_ref())?;
231 } else if self.protocol_type != None {
232 return Err(UnsupportedFieldVersion::new(14, "protocol_type", version).into());
233 }
234 if version >= 5 {
235 len += compact_nullable_string_len(self.protocol_name.as_ref())?;
236 } else if self.protocol_name != None {
237 return Err(UnsupportedFieldVersion::new(14, "protocol_name", version).into());
238 }
239 if version >= 4 {
240 len += compact_array_length_len(self.assignments.len() as i32);
241 for el in &self.assignments {
242 len += el.encoded_len(version)?;
243 }
244 } else {
245 len += array_length_len();
246 for el in &self.assignments {
247 len += el.encoded_len(version)?;
248 }
249 }
250 if version >= 4 {
251 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
252 all_tags.sort_by_key(|f| f.tag);
253 len += tagged_fields_len(&all_tags)?;
254 }
255 Ok(len)
256 }
257}
258#[derive(Debug, Clone, PartialEq)]
259pub struct SyncGroupRequestAssignment {
260 pub member_id: KafkaString,
262 pub assignment: Bytes,
264 pub _unknown_tagged_fields: Vec<RawTaggedField>,
265}
266impl Default for SyncGroupRequestAssignment {
267 fn default() -> Self {
268 Self {
269 member_id: KafkaString::default(),
270 assignment: Bytes::new(),
271 _unknown_tagged_fields: Vec::new(),
272 }
273 }
274}
275impl SyncGroupRequestAssignment {
276 pub fn with_member_id(mut self, value: KafkaString) -> Self {
277 self.member_id = value;
278 self
279 }
280 pub fn with_assignment(mut self, value: Bytes) -> Self {
281 self.assignment = value;
282 self
283 }
284 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
285 let member_id;
286 let assignment;
287 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
288 if version >= 4 {
289 member_id = read_compact_string(buf)?;
290 } else {
291 member_id = read_string(buf)?;
292 }
293 if version >= 4 {
294 assignment = read_compact_bytes(buf)?;
295 } else {
296 assignment = read_bytes(buf)?;
297 }
298 if version >= 4 {
299 let tagged_fields = read_tagged_fields(buf)?;
300 for field in &tagged_fields {
301 match field.tag {
302 _ => {
303 _unknown_tagged_fields.push(field.clone());
304 },
305 }
306 }
307 }
308 Ok(Self {
309 member_id,
310 assignment,
311 _unknown_tagged_fields,
312 })
313 }
314 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
315 if version >= 4 {
316 write_compact_string(buf, &self.member_id)?;
317 } else {
318 write_string(buf, &self.member_id)?;
319 }
320 if version >= 4 {
321 write_compact_bytes(buf, &self.assignment)?;
322 } else {
323 write_bytes(buf, &self.assignment)?;
324 }
325 if version >= 4 {
326 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
327 all_tags.sort_by_key(|f| f.tag);
328 write_tagged_fields(buf, &all_tags)?;
329 }
330 Ok(())
331 }
332 pub fn encoded_len(&self, version: i16) -> Result<usize> {
333 let mut len: usize = 0;
334 if version >= 4 {
335 len += compact_string_len(&self.member_id)?;
336 } else {
337 len += string_len(&self.member_id)?;
338 }
339 if version >= 4 {
340 len += compact_bytes_len(&self.assignment)?;
341 } else {
342 len += bytes_len(&self.assignment)?;
343 }
344 if version >= 4 {
345 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
346 all_tags.sort_by_key(|f| f.tag);
347 len += tagged_fields_len(&all_tags)?;
348 }
349 Ok(len)
350 }
351}