Skip to main content

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

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