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