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