Skip to main content

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

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