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