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