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