crabka_protocol/opt/rustwide/workdir/generated/
JoinGroupResponse.borrowed.rs1use bytes::{BufMut, Bytes};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, put_bool, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
9};
10use crate::primitives::string_bytes::{put_bytes, put_compact_bytes};
11use crate::primitives::string_bytes_borrowed::{get_bytes_borrowed, get_compact_bytes_borrowed};
12use crate::primitives::string_bytes_borrowed::{
13 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
14 get_nullable_string_borrowed, get_string_borrowed,
15};
16use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
17use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
18
19pub const API_KEY: i16 = 11;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 9;
22pub const FLEXIBLE_MIN: i16 = 6;
23
24#[inline]
25fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct JoinGroupResponse<'a> {
31 pub throttle_time_ms: i32,
32 pub error_code: i16,
33 pub generation_id: i32,
34 pub protocol_type: Option<&'a str>,
35 pub protocol_name: Option<&'a str>,
36 pub leader: &'a str,
37 pub skip_assignment: bool,
38 pub member_id: &'a str,
39 pub members: Vec<JoinGroupResponseMember<'a>>,
40 pub unknown_tagged_fields: UnknownTaggedFields,
41}
42impl Default for JoinGroupResponse<'_> {
43 fn default() -> Self {
44 Self {
45 throttle_time_ms: 0i32,
46 error_code: 0i16,
47 generation_id: -1i32,
48 protocol_type: None,
49 protocol_name: None,
50 leader: "",
51 skip_assignment: false,
52 member_id: "",
53 members: Vec::new(),
54 unknown_tagged_fields: Default::default(),
55 }
56 }
57}
58impl JoinGroupResponse<'_> {
59 pub fn to_owned(&self) -> crate::owned::join_group_response::JoinGroupResponse {
60 crate::owned::join_group_response::JoinGroupResponse {
61 throttle_time_ms: (self.throttle_time_ms),
62 error_code: (self.error_code),
63 generation_id: (self.generation_id),
64 protocol_type: (self.protocol_type).map(std::string::ToString::to_string),
65 protocol_name: (self.protocol_name).map(std::string::ToString::to_string),
66 leader: (self.leader).to_string(),
67 skip_assignment: (self.skip_assignment),
68 member_id: (self.member_id).to_string(),
69 members: (self.members)
70 .iter()
71 .map(JoinGroupResponseMember::to_owned)
72 .collect(),
73 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
74 }
75 }
76}
77impl Encode for JoinGroupResponse<'_> {
78 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
79 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80 return Err(ProtocolError::UnsupportedVersion {
81 api_key: API_KEY,
82 version,
83 });
84 }
85 let flex = is_flexible(version);
86 if version >= 2 {
87 put_i32(buf, self.throttle_time_ms);
88 }
89 if version >= 0 {
90 put_i16(buf, self.error_code);
91 }
92 if version >= 0 {
93 put_i32(buf, self.generation_id);
94 }
95 if version >= 7 {
96 if flex {
97 put_compact_nullable_string(buf, self.protocol_type);
98 } else {
99 put_nullable_string(buf, self.protocol_type);
100 }
101 }
102 if version >= 0 {
103 if version >= 7 {
104 if flex {
105 put_compact_nullable_string(buf, self.protocol_name);
106 } else {
107 put_nullable_string(buf, self.protocol_name);
108 }
109 } else {
110 if flex {
111 put_compact_string(buf, (self.protocol_name).unwrap_or(""));
112 } else {
113 put_string(buf, (self.protocol_name).unwrap_or(""));
114 }
115 }
116 }
117 if version >= 0 {
118 if flex {
119 put_compact_string(buf, self.leader);
120 } else {
121 put_string(buf, self.leader);
122 }
123 }
124 if version >= 9 {
125 put_bool(buf, self.skip_assignment);
126 }
127 if version >= 0 {
128 if flex {
129 put_compact_string(buf, self.member_id);
130 } else {
131 put_string(buf, self.member_id);
132 }
133 }
134 if version >= 0 {
135 {
136 crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
137 for it in &self.members {
138 it.encode(buf, version)?;
139 }
140 }
141 }
142 if flex {
143 let tagged = WriteTaggedFields::new();
144 tagged.write(buf, &self.unknown_tagged_fields);
145 }
146 Ok(())
147 }
148 fn encoded_len(&self, version: i16) -> usize {
149 let flex = is_flexible(version);
150 let mut n: usize = 0;
151 if version >= 2 {
152 n += 4;
153 }
154 if version >= 0 {
155 n += 2;
156 }
157 if version >= 0 {
158 n += 4;
159 }
160 if version >= 7 {
161 n += if flex {
162 compact_nullable_string_len(self.protocol_type)
163 } else {
164 nullable_string_len(self.protocol_type)
165 };
166 }
167 if version >= 0 {
168 n += if version >= 7 {
169 if flex {
170 compact_nullable_string_len(self.protocol_name)
171 } else {
172 nullable_string_len(self.protocol_name)
173 }
174 } else {
175 if flex {
176 compact_string_len((self.protocol_name).unwrap_or(""))
177 } else {
178 string_len((self.protocol_name).unwrap_or(""))
179 }
180 };
181 }
182 if version >= 0 {
183 n += if flex {
184 compact_string_len(self.leader)
185 } else {
186 string_len(self.leader)
187 };
188 }
189 if version >= 9 {
190 n += 1;
191 }
192 if version >= 0 {
193 n += if flex {
194 compact_string_len(self.member_id)
195 } else {
196 string_len(self.member_id)
197 };
198 }
199 if version >= 0 {
200 n += {
201 let prefix =
202 crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
203 let body: usize = (self.members)
204 .iter()
205 .map(|it| it.encoded_len(version))
206 .sum();
207 prefix + body
208 };
209 }
210 if flex {
211 let known_pairs: Vec<(u32, usize)> = Vec::new();
212 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
213 }
214 n
215 }
216}
217impl<'de> DecodeBorrow<'de> for JoinGroupResponse<'de> {
218 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
219 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
220 return Err(ProtocolError::UnsupportedVersion {
221 api_key: API_KEY,
222 version,
223 });
224 }
225 let flex = is_flexible(version);
226 let mut out = Self::default();
227 if version >= 2 {
228 out.throttle_time_ms = get_i32(buf)?;
229 }
230 if version >= 0 {
231 out.error_code = get_i16(buf)?;
232 }
233 if version >= 0 {
234 out.generation_id = get_i32(buf)?;
235 }
236 if version >= 7 {
237 out.protocol_type = if flex {
238 get_compact_nullable_string_borrowed(buf)?
239 } else {
240 get_nullable_string_borrowed(buf)?
241 };
242 }
243 if version >= 0 {
244 out.protocol_name = if version >= 7 {
245 if flex {
246 get_compact_nullable_string_borrowed(buf)?
247 } else {
248 get_nullable_string_borrowed(buf)?
249 }
250 } else {
251 Some(if flex {
252 get_compact_string_borrowed(buf)?
253 } else {
254 get_string_borrowed(buf)?
255 })
256 };
257 }
258 if version >= 0 {
259 out.leader = if flex {
260 get_compact_string_borrowed(buf)?
261 } else {
262 get_string_borrowed(buf)?
263 };
264 }
265 if version >= 9 {
266 out.skip_assignment = get_bool(buf)?;
267 }
268 if version >= 0 {
269 out.member_id = if flex {
270 get_compact_string_borrowed(buf)?
271 } else {
272 get_string_borrowed(buf)?
273 };
274 }
275 if version >= 0 {
276 out.members = {
277 let n = crate::primitives::array::get_array_len(buf, flex)?;
278 let mut v = Vec::with_capacity(n);
279 for _ in 0..n {
280 v.push(JoinGroupResponseMember::decode_borrow(buf, version)?);
281 }
282 v
283 };
284 }
285 if flex {
286 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
287 }
288 Ok(out)
289 }
290}
291#[cfg(test)]
292impl JoinGroupResponse<'_> {
293 #[must_use]
294 pub fn populated(version: i16) -> Self {
295 let mut m = Self::default();
296 if version >= 2 {
297 m.throttle_time_ms = 1i32;
298 }
299 if version >= 0 {
300 m.error_code = 1i16;
301 }
302 if version >= 0 {
303 m.generation_id = 1i32;
304 }
305 if version >= 7 {
306 m.protocol_type = Some("x");
307 }
308 if version >= 0 {
309 m.protocol_name = Some("x");
310 }
311 if version >= 0 {
312 m.leader = "x";
313 }
314 if version >= 9 {
315 m.skip_assignment = true;
316 }
317 if version >= 0 {
318 m.member_id = "x";
319 }
320 if version >= 0 {
321 m.members = vec![JoinGroupResponseMember::populated(version)];
322 }
323 m
324 }
325}
326#[derive(Debug, Clone, PartialEq, Eq, Default)]
327pub struct JoinGroupResponseMember<'a> {
328 pub member_id: &'a str,
329 pub group_instance_id: Option<&'a str>,
330 pub metadata: &'a [u8],
331 pub unknown_tagged_fields: UnknownTaggedFields,
332}
333impl JoinGroupResponseMember<'_> {
334 pub fn to_owned(&self) -> crate::owned::join_group_response::JoinGroupResponseMember {
335 crate::owned::join_group_response::JoinGroupResponseMember {
336 member_id: (self.member_id).to_string(),
337 group_instance_id: (self.group_instance_id).map(std::string::ToString::to_string),
338 metadata: Bytes::copy_from_slice(self.metadata),
339 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
340 }
341 }
342}
343impl Encode for JoinGroupResponseMember<'_> {
344 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
345 let flex = version >= 6;
346 if version >= 0 {
347 if flex {
348 put_compact_string(buf, self.member_id);
349 } else {
350 put_string(buf, self.member_id);
351 }
352 }
353 if version >= 5 {
354 if flex {
355 put_compact_nullable_string(buf, self.group_instance_id);
356 } else {
357 put_nullable_string(buf, self.group_instance_id);
358 }
359 }
360 if version >= 0 {
361 if flex {
362 put_compact_bytes(buf, self.metadata);
363 } else {
364 put_bytes(buf, self.metadata);
365 }
366 }
367 if flex {
368 let tagged = WriteTaggedFields::new();
369 tagged.write(buf, &self.unknown_tagged_fields);
370 }
371 Ok(())
372 }
373 fn encoded_len(&self, version: i16) -> usize {
374 let flex = version >= 6;
375 let mut n: usize = 0;
376 if version >= 0 {
377 n += if flex {
378 compact_string_len(self.member_id)
379 } else {
380 string_len(self.member_id)
381 };
382 }
383 if version >= 5 {
384 n += if flex {
385 compact_nullable_string_len(self.group_instance_id)
386 } else {
387 nullable_string_len(self.group_instance_id)
388 };
389 }
390 if version >= 0 {
391 n += if flex {
392 crate::primitives::varint::uvarint_len(
393 u32::try_from((self.metadata).len() + 1).unwrap(),
394 ) + (self.metadata).len()
395 } else {
396 4 + (self.metadata).len()
397 };
398 }
399 if flex {
400 let known_pairs: Vec<(u32, usize)> = Vec::new();
401 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
402 }
403 n
404 }
405}
406impl<'de> DecodeBorrow<'de> for JoinGroupResponseMember<'de> {
407 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
408 let flex = version >= 6;
409 let mut out = Self::default();
410 if version >= 0 {
411 out.member_id = if flex {
412 get_compact_string_borrowed(buf)?
413 } else {
414 get_string_borrowed(buf)?
415 };
416 }
417 if version >= 5 {
418 out.group_instance_id = if flex {
419 get_compact_nullable_string_borrowed(buf)?
420 } else {
421 get_nullable_string_borrowed(buf)?
422 };
423 }
424 if version >= 0 {
425 out.metadata = if flex {
426 get_compact_bytes_borrowed(buf)?
427 } else {
428 get_bytes_borrowed(buf)?
429 };
430 }
431 if flex {
432 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
433 }
434 Ok(out)
435 }
436}
437#[cfg(test)]
438impl JoinGroupResponseMember<'_> {
439 #[must_use]
440 pub fn populated(version: i16) -> Self {
441 let mut m = Self::default();
442 if version >= 0 {
443 m.member_id = "x";
444 }
445 if version >= 5 {
446 m.group_instance_id = Some("x");
447 }
448 if version >= 0 {
449 m.metadata = &b"x"[..];
450 }
451 m
452 }
453}