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