Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionResponse.borrowed.rs

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