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