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