Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_i16, get_i32, put_i16, put_i32},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 34;
14pub const MIN_VERSION: i16 = 1;
15pub const MAX_VERSION: i16 = 2;
16pub const FLEXIBLE_MIN: i16 = 2;
17#[inline]
18#[must_use]
19pub fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct AlterReplicaLogDirsResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub results: Vec<AlterReplicaLogDirTopicResult<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl AlterReplicaLogDirsResponse<'_> {
29    /// # Panics
30    ///
31    /// Panics if a records field contains an invalid encoded record batch.
32    #[must_use]
33    pub fn to_owned(
34        &self,
35    ) -> crate::owned::alter_replica_log_dirs_response::AlterReplicaLogDirsResponse {
36        crate::owned::alter_replica_log_dirs_response::AlterReplicaLogDirsResponse {
37            throttle_time_ms: (self.throttle_time_ms),
38            results: (self.results)
39                .iter()
40                .map(AlterReplicaLogDirTopicResult::to_owned)
41                .collect(),
42            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43        }
44    }
45}
46impl Encode for AlterReplicaLogDirsResponse<'_> {
47    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
48        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
49            return Err(ProtocolError::UnsupportedVersion {
50                api_key: API_KEY,
51                version,
52            });
53        }
54        let flex = is_flexible(version);
55        if version >= 0 {
56            put_i32(buf, self.throttle_time_ms);
57        }
58        if version >= 0 {
59            {
60                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
61                for it in &self.results {
62                    it.encode(buf, version)?;
63                }
64            };
65        }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 0 {
76            n += 4;
77        }
78        if version >= 0 {
79            n += {
80                let prefix =
81                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
82                let body: usize = (self.results)
83                    .iter()
84                    .map(|it| it.encoded_len(version))
85                    .sum();
86                prefix + body
87            };
88        }
89        if flex {
90            let known_pairs: Vec<(u32, usize)> = Vec::new();
91            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
92        }
93        n
94    }
95}
96impl<'de> DecodeBorrow<'de> for AlterReplicaLogDirsResponse<'de> {
97    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
98        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
99            return Err(ProtocolError::UnsupportedVersion {
100                api_key: API_KEY,
101                version,
102            });
103        }
104        let flex = is_flexible(version);
105        let mut out = Self::default();
106        if version >= 0 {
107            out.throttle_time_ms = get_i32(buf)?;
108        }
109        if version >= 0 {
110            out.results = {
111                let n = crate::primitives::array::get_array_len(buf, flex)?;
112                let mut v = Vec::with_capacity(n);
113                for _ in 0..n {
114                    v.push(AlterReplicaLogDirTopicResult::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 AlterReplicaLogDirsResponse<'_> {
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.results = vec![AlterReplicaLogDirTopicResult::populated(version)];
135        }
136        m
137    }
138}
139#[derive(Debug, Clone, PartialEq, Eq, Default)]
140pub struct AlterReplicaLogDirTopicResult<'a> {
141    pub topic_name: &'a str,
142    pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
143    pub unknown_tagged_fields: UnknownTaggedFields,
144}
145impl AlterReplicaLogDirTopicResult<'_> {
146    /// # Panics
147    ///
148    /// Panics if a records field contains an invalid encoded record batch.
149    #[must_use]
150    pub fn to_owned(
151        &self,
152    ) -> crate::owned::alter_replica_log_dirs_response::AlterReplicaLogDirTopicResult {
153        crate::owned::alter_replica_log_dirs_response::AlterReplicaLogDirTopicResult {
154            topic_name: (self.topic_name).to_string(),
155            partitions: (self.partitions)
156                .iter()
157                .map(AlterReplicaLogDirPartitionResult::to_owned)
158                .collect(),
159            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
160        }
161    }
162}
163impl Encode for AlterReplicaLogDirTopicResult<'_> {
164    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
165        let flex = version >= 2;
166        if version >= 0 {
167            if flex {
168                let () = put_compact_string(buf, self.topic_name);
169            } else {
170                let () = put_string(buf, self.topic_name);
171            }
172        }
173        if version >= 0 {
174            {
175                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
176                for it in &self.partitions {
177                    it.encode(buf, version)?;
178                }
179            };
180        }
181        if flex {
182            let tagged = WriteTaggedFields::new();
183            tagged.write(buf, &self.unknown_tagged_fields);
184        }
185        Ok(())
186    }
187    fn encoded_len(&self, version: i16) -> usize {
188        let flex = version >= 2;
189        let mut n: usize = 0;
190        if version >= 0 {
191            n += if flex {
192                compact_string_len(self.topic_name)
193            } else {
194                string_len(self.topic_name)
195            };
196        }
197        if version >= 0 {
198            n += {
199                let prefix =
200                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
201                let body: usize = (self.partitions)
202                    .iter()
203                    .map(|it| it.encoded_len(version))
204                    .sum();
205                prefix + body
206            };
207        }
208        if flex {
209            let known_pairs: Vec<(u32, usize)> = Vec::new();
210            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
211        }
212        n
213    }
214}
215impl<'de> DecodeBorrow<'de> for AlterReplicaLogDirTopicResult<'de> {
216    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
217        let flex = version >= 2;
218        let mut out = Self::default();
219        if version >= 0 {
220            out.topic_name = if flex {
221                get_compact_string_borrowed(buf)?
222            } else {
223                get_string_borrowed(buf)?
224            };
225        }
226        if version >= 0 {
227            out.partitions = {
228                let n = crate::primitives::array::get_array_len(buf, flex)?;
229                let mut v = Vec::with_capacity(n);
230                for _ in 0..n {
231                    v.push(AlterReplicaLogDirPartitionResult::decode_borrow(
232                        buf, version,
233                    )?);
234                }
235                v
236            };
237        }
238        if flex {
239            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
240        }
241        Ok(out)
242    }
243}
244#[cfg(test)]
245impl AlterReplicaLogDirTopicResult<'_> {
246    #[must_use]
247    pub fn populated(version: i16) -> Self {
248        let mut m = Self::default();
249        if version >= 0 {
250            m.topic_name = "x";
251        }
252        if version >= 0 {
253            m.partitions = vec![AlterReplicaLogDirPartitionResult::populated(version)];
254        }
255        m
256    }
257}
258#[derive(Debug, Clone, PartialEq, Eq, Default)]
259pub struct AlterReplicaLogDirPartitionResult {
260    pub partition_index: i32,
261    pub error_code: i16,
262    pub unknown_tagged_fields: UnknownTaggedFields,
263}
264impl AlterReplicaLogDirPartitionResult {
265    /// # Panics
266    ///
267    /// Panics if a records field contains an invalid encoded record batch.
268    #[must_use]
269    pub fn to_owned(
270        &self,
271    ) -> crate::owned::alter_replica_log_dirs_response::AlterReplicaLogDirPartitionResult {
272        crate::owned::alter_replica_log_dirs_response::AlterReplicaLogDirPartitionResult {
273            partition_index: (self.partition_index),
274            error_code: (self.error_code),
275            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
276        }
277    }
278}
279impl Encode for AlterReplicaLogDirPartitionResult {
280    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
281        let flex = version >= 2;
282        if version >= 0 {
283            put_i32(buf, self.partition_index);
284        }
285        if version >= 0 {
286            put_i16(buf, self.error_code);
287        }
288        if flex {
289            let tagged = WriteTaggedFields::new();
290            tagged.write(buf, &self.unknown_tagged_fields);
291        }
292        Ok(())
293    }
294    fn encoded_len(&self, version: i16) -> usize {
295        let flex = version >= 2;
296        let mut n: usize = 0;
297        if version >= 0 {
298            n += 4;
299        }
300        if version >= 0 {
301            n += 2;
302        }
303        if flex {
304            let known_pairs: Vec<(u32, usize)> = Vec::new();
305            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
306        }
307        n
308    }
309}
310impl<'de> DecodeBorrow<'de> for AlterReplicaLogDirPartitionResult {
311    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
312        let flex = version >= 2;
313        let mut out = Self::default();
314        if version >= 0 {
315            out.partition_index = get_i32(buf)?;
316        }
317        if version >= 0 {
318            out.error_code = get_i16(buf)?;
319        }
320        if flex {
321            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
322        }
323        Ok(out)
324    }
325}
326#[cfg(test)]
327impl AlterReplicaLogDirPartitionResult {
328    #[must_use]
329    pub fn populated(version: i16) -> Self {
330        let mut m = Self::default();
331        if version >= 0 {
332            m.partition_index = 1i32;
333        }
334        if version >= 0 {
335            m.error_code = 1i16;
336        }
337        m
338    }
339}