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