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