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