Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsResponse.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::fixed::{get_i16, get_i32, put_i16, put_i32},
7    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
8};
9pub const API_KEY: i16 = 73;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13#[inline]
14#[must_use]
15pub fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct AssignReplicasToDirsResponse {
20    pub throttle_time_ms: i32,
21    pub error_code: i16,
22    pub directories: Vec<DirectoryData>,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl AssignReplicasToDirsResponse {
26    /// # Panics
27    ///
28    /// Panics if a records field contains an invalid encoded record batch.
29    #[must_use]
30    pub fn to_owned(
31        &self,
32    ) -> crate::owned::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse {
33        crate::owned::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse {
34            throttle_time_ms: (self.throttle_time_ms),
35            error_code: (self.error_code),
36            directories: (self.directories)
37                .iter()
38                .map(DirectoryData::to_owned)
39                .collect(),
40            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41        }
42    }
43}
44impl Encode for AssignReplicasToDirsResponse {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion {
48                api_key: API_KEY,
49                version,
50            });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 {
54            put_i32(buf, self.throttle_time_ms);
55        }
56        if version >= 0 {
57            put_i16(buf, self.error_code);
58        }
59        if version >= 0 {
60            {
61                crate::primitives::array::put_array_len(buf, (self.directories).len(), flex);
62                for it in &self.directories {
63                    it.encode(buf, version)?;
64                }
65            };
66        }
67        if flex {
68            let tagged = WriteTaggedFields::new();
69            tagged.write(buf, &self.unknown_tagged_fields);
70        }
71        Ok(())
72    }
73    fn encoded_len(&self, version: i16) -> usize {
74        let flex = is_flexible(version);
75        let mut n: usize = 0;
76        if version >= 0 {
77            n += 4;
78        }
79        if version >= 0 {
80            n += 2;
81        }
82        if version >= 0 {
83            n += {
84                let prefix =
85                    crate::primitives::array::array_len_prefix_len((self.directories).len(), flex);
86                let body: usize = (self.directories)
87                    .iter()
88                    .map(|it| it.encoded_len(version))
89                    .sum();
90                prefix + body
91            };
92        }
93        if flex {
94            let known_pairs: Vec<(u32, usize)> = Vec::new();
95            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
96        }
97        n
98    }
99}
100impl<'de> DecodeBorrow<'de> for AssignReplicasToDirsResponse {
101    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
102        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
103            return Err(ProtocolError::UnsupportedVersion {
104                api_key: API_KEY,
105                version,
106            });
107        }
108        let flex = is_flexible(version);
109        let mut out = Self::default();
110        if version >= 0 {
111            out.throttle_time_ms = get_i32(buf)?;
112        }
113        if version >= 0 {
114            out.error_code = get_i16(buf)?;
115        }
116        if version >= 0 {
117            out.directories = {
118                let n = crate::primitives::array::get_array_len(buf, flex)?;
119                let mut v = Vec::with_capacity(n);
120                for _ in 0..n {
121                    v.push(DirectoryData::decode_borrow(buf, version)?);
122                }
123                v
124            };
125        }
126        if flex {
127            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
128        }
129        Ok(out)
130    }
131}
132#[cfg(test)]
133impl AssignReplicasToDirsResponse {
134    #[must_use]
135    pub fn populated(version: i16) -> Self {
136        let mut m = Self::default();
137        if version >= 0 {
138            m.throttle_time_ms = 1i32;
139        }
140        if version >= 0 {
141            m.error_code = 1i16;
142        }
143        if version >= 0 {
144            m.directories = vec![DirectoryData::populated(version)];
145        }
146        m
147    }
148}
149#[derive(Debug, Clone, PartialEq, Eq, Default)]
150pub struct DirectoryData {
151    pub id: crate::primitives::uuid::Uuid,
152    pub topics: Vec<TopicData>,
153    pub unknown_tagged_fields: UnknownTaggedFields,
154}
155impl DirectoryData {
156    /// # Panics
157    ///
158    /// Panics if a records field contains an invalid encoded record batch.
159    #[must_use]
160    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::DirectoryData {
161        crate::owned::assign_replicas_to_dirs_response::DirectoryData {
162            id: (self.id),
163            topics: (self.topics).iter().map(TopicData::to_owned).collect(),
164            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
165        }
166    }
167}
168impl Encode for DirectoryData {
169    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
170        let flex = version >= 0;
171        if version >= 0 {
172            crate::primitives::uuid::put_uuid(buf, self.id);
173        }
174        if version >= 0 {
175            {
176                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
177                for it in &self.topics {
178                    it.encode(buf, version)?;
179                }
180            };
181        }
182        if flex {
183            let tagged = WriteTaggedFields::new();
184            tagged.write(buf, &self.unknown_tagged_fields);
185        }
186        Ok(())
187    }
188    fn encoded_len(&self, version: i16) -> usize {
189        let flex = version >= 0;
190        let mut n: usize = 0;
191        if version >= 0 {
192            n += 16;
193        }
194        if version >= 0 {
195            n += {
196                let prefix =
197                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
198                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
199                prefix + body
200            };
201        }
202        if flex {
203            let known_pairs: Vec<(u32, usize)> = Vec::new();
204            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
205        }
206        n
207    }
208}
209impl<'de> DecodeBorrow<'de> for DirectoryData {
210    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
211        let flex = version >= 0;
212        let mut out = Self::default();
213        if version >= 0 {
214            out.id = crate::primitives::uuid::get_uuid(buf)?;
215        }
216        if version >= 0 {
217            out.topics = {
218                let n = crate::primitives::array::get_array_len(buf, flex)?;
219                let mut v = Vec::with_capacity(n);
220                for _ in 0..n {
221                    v.push(TopicData::decode_borrow(buf, version)?);
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 DirectoryData {
234    #[must_use]
235    pub fn populated(version: i16) -> Self {
236        let mut m = Self::default();
237        if version >= 0 {
238            m.id = crate::primitives::uuid::Uuid([1u8; 16]);
239        }
240        if version >= 0 {
241            m.topics = vec![TopicData::populated(version)];
242        }
243        m
244    }
245}
246#[derive(Debug, Clone, PartialEq, Eq, Default)]
247pub struct TopicData {
248    pub topic_id: crate::primitives::uuid::Uuid,
249    pub partitions: Vec<PartitionData>,
250    pub unknown_tagged_fields: UnknownTaggedFields,
251}
252impl TopicData {
253    /// # Panics
254    ///
255    /// Panics if a records field contains an invalid encoded record batch.
256    #[must_use]
257    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::TopicData {
258        crate::owned::assign_replicas_to_dirs_response::TopicData {
259            topic_id: (self.topic_id),
260            partitions: (self.partitions)
261                .iter()
262                .map(PartitionData::to_owned)
263                .collect(),
264            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
265        }
266    }
267}
268impl Encode for TopicData {
269    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
270        let flex = version >= 0;
271        if version >= 0 {
272            crate::primitives::uuid::put_uuid(buf, self.topic_id);
273        }
274        if version >= 0 {
275            {
276                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
277                for it in &self.partitions {
278                    it.encode(buf, version)?;
279                }
280            };
281        }
282        if flex {
283            let tagged = WriteTaggedFields::new();
284            tagged.write(buf, &self.unknown_tagged_fields);
285        }
286        Ok(())
287    }
288    fn encoded_len(&self, version: i16) -> usize {
289        let flex = version >= 0;
290        let mut n: usize = 0;
291        if version >= 0 {
292            n += 16;
293        }
294        if version >= 0 {
295            n += {
296                let prefix =
297                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
298                let body: usize = (self.partitions)
299                    .iter()
300                    .map(|it| it.encoded_len(version))
301                    .sum();
302                prefix + body
303            };
304        }
305        if flex {
306            let known_pairs: Vec<(u32, usize)> = Vec::new();
307            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
308        }
309        n
310    }
311}
312impl<'de> DecodeBorrow<'de> for TopicData {
313    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
314        let flex = version >= 0;
315        let mut out = Self::default();
316        if version >= 0 {
317            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
318        }
319        if version >= 0 {
320            out.partitions = {
321                let n = crate::primitives::array::get_array_len(buf, flex)?;
322                let mut v = Vec::with_capacity(n);
323                for _ in 0..n {
324                    v.push(PartitionData::decode_borrow(buf, version)?);
325                }
326                v
327            };
328        }
329        if flex {
330            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
331        }
332        Ok(out)
333    }
334}
335#[cfg(test)]
336impl TopicData {
337    #[must_use]
338    pub fn populated(version: i16) -> Self {
339        let mut m = Self::default();
340        if version >= 0 {
341            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
342        }
343        if version >= 0 {
344            m.partitions = vec![PartitionData::populated(version)];
345        }
346        m
347    }
348}
349#[derive(Debug, Clone, PartialEq, Eq, Default)]
350pub struct PartitionData {
351    pub partition_index: i32,
352    pub error_code: i16,
353    pub unknown_tagged_fields: UnknownTaggedFields,
354}
355impl PartitionData {
356    /// # Panics
357    ///
358    /// Panics if a records field contains an invalid encoded record batch.
359    #[must_use]
360    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::PartitionData {
361        crate::owned::assign_replicas_to_dirs_response::PartitionData {
362            partition_index: (self.partition_index),
363            error_code: (self.error_code),
364            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
365        }
366    }
367}
368impl Encode for PartitionData {
369    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
370        let flex = version >= 0;
371        if version >= 0 {
372            put_i32(buf, self.partition_index);
373        }
374        if version >= 0 {
375            put_i16(buf, self.error_code);
376        }
377        if flex {
378            let tagged = WriteTaggedFields::new();
379            tagged.write(buf, &self.unknown_tagged_fields);
380        }
381        Ok(())
382    }
383    fn encoded_len(&self, version: i16) -> usize {
384        let flex = version >= 0;
385        let mut n: usize = 0;
386        if version >= 0 {
387            n += 4;
388        }
389        if version >= 0 {
390            n += 2;
391        }
392        if flex {
393            let known_pairs: Vec<(u32, usize)> = Vec::new();
394            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
395        }
396        n
397    }
398}
399impl<'de> DecodeBorrow<'de> for PartitionData {
400    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
401        let flex = version >= 0;
402        let mut out = Self::default();
403        if version >= 0 {
404            out.partition_index = get_i32(buf)?;
405        }
406        if version >= 0 {
407            out.error_code = get_i16(buf)?;
408        }
409        if flex {
410            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
411        }
412        Ok(out)
413    }
414}
415#[cfg(test)]
416impl PartitionData {
417    #[must_use]
418    pub fn populated(version: i16) -> Self {
419        let mut m = Self::default();
420        if version >= 0 {
421            m.partition_index = 1i32;
422        }
423        if version >= 0 {
424            m.error_code = 1i16;
425        }
426        m
427    }
428}