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