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