Skip to main content

kacrab_protocol/generated/
metadata_request.rs

1//! Generated from MetadataRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct MetadataRequestData {
17    /// The topics to fetch metadata for.
18    pub topics: Option<Vec<MetadataRequestTopic>>,
19    /// If this is true, the broker may auto-create topics that we requested which do not already
20    /// exist, if it is configured to do so.
21    pub allow_auto_topic_creation: bool,
22    /// Whether to include cluster authorized operations.
23    pub include_cluster_authorized_operations: bool,
24    /// Whether to include topic authorized operations.
25    pub include_topic_authorized_operations: bool,
26    pub _unknown_tagged_fields: Vec<RawTaggedField>,
27}
28impl Default for MetadataRequestData {
29    fn default() -> Self {
30        Self {
31            topics: None,
32            allow_auto_topic_creation: true,
33            include_cluster_authorized_operations: false,
34            include_topic_authorized_operations: false,
35            _unknown_tagged_fields: Vec::new(),
36        }
37    }
38}
39impl MetadataRequestData {
40    pub fn with_topics(mut self, value: Option<Vec<MetadataRequestTopic>>) -> Self {
41        self.topics = value;
42        self
43    }
44    pub fn with_allow_auto_topic_creation(mut self, value: bool) -> Self {
45        self.allow_auto_topic_creation = value;
46        self
47    }
48    pub fn with_include_cluster_authorized_operations(mut self, value: bool) -> Self {
49        self.include_cluster_authorized_operations = value;
50        self
51    }
52    pub fn with_include_topic_authorized_operations(mut self, value: bool) -> Self {
53        self.include_topic_authorized_operations = value;
54        self
55    }
56    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
57        if version < 0 || version > 13 {
58            return Err(UnsupportedVersion::new(3, version).into());
59        }
60        let topics;
61        let mut allow_auto_topic_creation = true;
62        let mut include_cluster_authorized_operations = false;
63        let mut include_topic_authorized_operations = false;
64        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
65        if version >= 1 {
66            if version >= 9 {
67                topics = {
68                    let len = read_compact_array_length(buf)?;
69                    if len < 0 {
70                        None
71                    } else {
72                        let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
73                        for _ in 0..len {
74                            arr.push(MetadataRequestTopic::read(buf, version)?);
75                        }
76                        Some(arr)
77                    }
78                };
79            } else {
80                topics = {
81                    let len = read_array_length(buf)?;
82                    if len < 0 {
83                        None
84                    } else {
85                        let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
86                        for _ in 0..len {
87                            arr.push(MetadataRequestTopic::read(buf, version)?);
88                        }
89                        Some(arr)
90                    }
91                };
92            }
93        } else {
94            topics = Some({
95                let len = read_array_length(buf)?;
96                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
97                for _ in 0..len {
98                    arr.push(MetadataRequestTopic::read(buf, version)?);
99                }
100                arr
101            });
102        }
103        if version >= 4 {
104            allow_auto_topic_creation = read_bool(buf)?;
105        }
106        if version >= 8 && version <= 10 {
107            include_cluster_authorized_operations = read_bool(buf)?;
108        }
109        if version >= 8 {
110            include_topic_authorized_operations = read_bool(buf)?;
111        }
112        if version >= 9 {
113            let tagged_fields = read_tagged_fields(buf)?;
114            for field in &tagged_fields {
115                match field.tag {
116                    _ => {
117                        _unknown_tagged_fields.push(field.clone());
118                    },
119                }
120            }
121        }
122        Ok(Self {
123            topics,
124            allow_auto_topic_creation,
125            include_cluster_authorized_operations,
126            include_topic_authorized_operations,
127            _unknown_tagged_fields,
128        })
129    }
130    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
131        if version < 0 || version > 13 {
132            return Err(UnsupportedVersion::new(3, version).into());
133        }
134        if version >= 1 {
135            if version >= 9 {
136                match &self.topics {
137                    None => {
138                        write_compact_array_length(buf, -1);
139                    },
140                    Some(arr) => {
141                        write_compact_array_length(buf, arr.len() as i32);
142                        for el in arr {
143                            el.write(buf, version)?;
144                        }
145                    },
146                }
147            } else {
148                match &self.topics {
149                    None => {
150                        write_array_length(buf, -1);
151                    },
152                    Some(arr) => {
153                        write_array_length(buf, arr.len() as i32);
154                        for el in arr {
155                            el.write(buf, version)?;
156                        }
157                    },
158                }
159            }
160        } else {
161            match &self.topics {
162                Some(arr) => {
163                    write_array_length(buf, arr.len() as i32);
164                    for el in arr {
165                        el.write(buf, version)?;
166                    }
167                },
168                None => {
169                    write_array_length(buf, 0);
170                },
171            }
172        }
173        if version >= 4 {
174            write_bool(buf, self.allow_auto_topic_creation);
175        } else if self.allow_auto_topic_creation != true {
176            return Err(
177                UnsupportedFieldVersion::new(3, "allow_auto_topic_creation", version).into(),
178            );
179        }
180        if version >= 8 && version <= 10 {
181            write_bool(buf, self.include_cluster_authorized_operations);
182        } else if self.include_cluster_authorized_operations != false {
183            return Err(UnsupportedFieldVersion::new(
184                3,
185                "include_cluster_authorized_operations",
186                version,
187            )
188            .into());
189        }
190        if version >= 8 {
191            write_bool(buf, self.include_topic_authorized_operations);
192        } else if self.include_topic_authorized_operations != false {
193            return Err(UnsupportedFieldVersion::new(
194                3,
195                "include_topic_authorized_operations",
196                version,
197            )
198            .into());
199        }
200        if version >= 9 {
201            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
202            all_tags.sort_by_key(|f| f.tag);
203            write_tagged_fields(buf, &all_tags)?;
204        }
205        Ok(())
206    }
207    pub fn encoded_len(&self, version: i16) -> Result<usize> {
208        if version < 0 || version > 13 {
209            return Err(UnsupportedVersion::new(3, version).into());
210        }
211        let mut len: usize = 0;
212        if version >= 1 {
213            if version >= 9 {
214                match &self.topics {
215                    None => {
216                        len += compact_array_length_len(-1);
217                    },
218                    Some(arr) => {
219                        len += compact_array_length_len(arr.len() as i32);
220                        for el in arr {
221                            len += el.encoded_len(version)?;
222                        }
223                    },
224                }
225            } else {
226                match &self.topics {
227                    None => {
228                        len += array_length_len();
229                    },
230                    Some(arr) => {
231                        len += array_length_len();
232                        for el in arr {
233                            len += el.encoded_len(version)?;
234                        }
235                    },
236                }
237            }
238        } else {
239            match &self.topics {
240                Some(arr) => {
241                    len += array_length_len();
242                    for el in arr {
243                        len += el.encoded_len(version)?;
244                    }
245                },
246                None => {
247                    len += array_length_len();
248                },
249            }
250        }
251        if version >= 4 {
252            len += 1;
253        } else if self.allow_auto_topic_creation != true {
254            return Err(
255                UnsupportedFieldVersion::new(3, "allow_auto_topic_creation", version).into(),
256            );
257        }
258        if version >= 8 && version <= 10 {
259            len += 1;
260        } else if self.include_cluster_authorized_operations != false {
261            return Err(UnsupportedFieldVersion::new(
262                3,
263                "include_cluster_authorized_operations",
264                version,
265            )
266            .into());
267        }
268        if version >= 8 {
269            len += 1;
270        } else if self.include_topic_authorized_operations != false {
271            return Err(UnsupportedFieldVersion::new(
272                3,
273                "include_topic_authorized_operations",
274                version,
275            )
276            .into());
277        }
278        if version >= 9 {
279            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
280            all_tags.sort_by_key(|f| f.tag);
281            len += tagged_fields_len(&all_tags)?;
282        }
283        Ok(len)
284    }
285}
286#[derive(Debug, Clone, PartialEq)]
287pub struct MetadataRequestTopic {
288    /// The topic id.
289    pub topic_id: KafkaUuid,
290    /// The topic name.
291    pub name: Option<KafkaString>,
292    pub _unknown_tagged_fields: Vec<RawTaggedField>,
293}
294impl Default for MetadataRequestTopic {
295    fn default() -> Self {
296        Self {
297            topic_id: KafkaUuid::ZERO,
298            name: None,
299            _unknown_tagged_fields: Vec::new(),
300        }
301    }
302}
303impl MetadataRequestTopic {
304    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
305        self.topic_id = value;
306        self
307    }
308    pub fn with_name(mut self, value: Option<KafkaString>) -> Self {
309        self.name = value;
310        self
311    }
312    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
313        let mut topic_id = KafkaUuid::ZERO;
314        let name;
315        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
316        if version >= 10 {
317            topic_id = read_uuid(buf)?;
318        }
319        if version >= 10 {
320            name = read_compact_nullable_string(buf)?;
321        } else {
322            if version >= 9 {
323                name = Some(read_compact_string(buf)?);
324            } else {
325                name = Some(read_string(buf)?);
326            }
327        }
328        if version >= 9 {
329            let tagged_fields = read_tagged_fields(buf)?;
330            for field in &tagged_fields {
331                match field.tag {
332                    _ => {
333                        _unknown_tagged_fields.push(field.clone());
334                    },
335                }
336            }
337        }
338        Ok(Self {
339            topic_id,
340            name,
341            _unknown_tagged_fields,
342        })
343    }
344    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
345        if version >= 10 {
346            write_uuid(buf, &self.topic_id);
347        } else if self.topic_id != KafkaUuid::ZERO {
348            return Err(UnsupportedFieldVersion::new(3, "topic_id", version).into());
349        }
350        if version >= 10 {
351            write_compact_nullable_string(buf, self.name.as_ref())?;
352        } else {
353            {
354                let _nn_default = KafkaString::default();
355                let _nn_val = self.name.as_ref().unwrap_or(&_nn_default);
356                if version >= 9 {
357                    write_compact_string(buf, _nn_val)?;
358                } else {
359                    write_string(buf, _nn_val)?;
360                }
361            }
362        }
363        if version >= 9 {
364            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
365            all_tags.sort_by_key(|f| f.tag);
366            write_tagged_fields(buf, &all_tags)?;
367        }
368        Ok(())
369    }
370    pub fn encoded_len(&self, version: i16) -> Result<usize> {
371        let mut len: usize = 0;
372        if version >= 10 {
373            len += 16;
374        } else if self.topic_id != KafkaUuid::ZERO {
375            return Err(UnsupportedFieldVersion::new(3, "topic_id", version).into());
376        }
377        if version >= 10 {
378            len += compact_nullable_string_len(self.name.as_ref())?;
379        } else {
380            let _nn_default = KafkaString::default();
381            let _nn_val = self.name.as_ref().unwrap_or(&_nn_default);
382            if version >= 9 {
383                len += compact_string_len(_nn_val)?;
384            } else {
385                len += string_len(_nn_val)?;
386            }
387        }
388        if version >= 9 {
389            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
390            all_tags.sort_by_key(|f| f.tag);
391            len += tagged_fields_len(&all_tags)?;
392        }
393        Ok(len)
394    }
395}