Skip to main content

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

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