Skip to main content

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

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