Skip to main content

kacrab_protocol/generated/
delete_topics_request.rs

1//! Generated from DeleteTopicsRequest.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 DeleteTopicsRequestData {
17    /// The name or topic ID of the topic.
18    pub topics: Vec<DeleteTopicState>,
19    /// The names of the topics to delete.
20    pub topic_names: Vec<KafkaString>,
21    /// The length of time in milliseconds to wait for the deletions to complete.
22    pub timeout_ms: i32,
23    pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for DeleteTopicsRequestData {
26    fn default() -> Self {
27        Self {
28            topics: Vec::new(),
29            topic_names: Vec::new(),
30            timeout_ms: 0_i32,
31            _unknown_tagged_fields: Vec::new(),
32        }
33    }
34}
35impl DeleteTopicsRequestData {
36    pub fn with_topics(mut self, value: Vec<DeleteTopicState>) -> Self {
37        self.topics = value;
38        self
39    }
40    pub fn with_topic_names(mut self, value: Vec<KafkaString>) -> Self {
41        self.topic_names = value;
42        self
43    }
44    pub fn with_timeout_ms(mut self, value: i32) -> Self {
45        self.timeout_ms = value;
46        self
47    }
48    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49        if version < 1 || version > 6 {
50            return Err(UnsupportedVersion::new(20, version).into());
51        }
52        let mut topics = Vec::new();
53        let mut topic_names = Vec::new();
54        let timeout_ms;
55        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56        if version >= 6 {
57            topics = {
58                let len = read_compact_array_length(buf)?;
59                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
60                for _ in 0..len {
61                    arr.push(DeleteTopicState::read(buf, version)?);
62                }
63                arr
64            };
65        }
66        if version <= 5 {
67            if version >= 4 {
68                topic_names = {
69                    let len = read_compact_array_length(buf)?;
70                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
71                    for _ in 0..len {
72                        arr.push(read_compact_string(buf)?);
73                    }
74                    arr
75                };
76            } else {
77                topic_names = {
78                    let len = read_array_length(buf)?;
79                    let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
80                    for _ in 0..len {
81                        arr.push(read_string(buf)?);
82                    }
83                    arr
84                };
85            }
86        }
87        timeout_ms = read_i32(buf)?;
88        if version >= 4 {
89            let tagged_fields = read_tagged_fields(buf)?;
90            for field in &tagged_fields {
91                match field.tag {
92                    _ => {
93                        _unknown_tagged_fields.push(field.clone());
94                    },
95                }
96            }
97        }
98        Ok(Self {
99            topics,
100            topic_names,
101            timeout_ms,
102            _unknown_tagged_fields,
103        })
104    }
105    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
106        if version < 1 || version > 6 {
107            return Err(UnsupportedVersion::new(20, version).into());
108        }
109        if version >= 6 {
110            write_compact_array_length(buf, self.topics.len() as i32);
111            for el in &self.topics {
112                el.write(buf, version)?;
113            }
114        } else if self.topics != Vec::new() {
115            return Err(UnsupportedFieldVersion::new(20, "topics", version).into());
116        }
117        if version <= 5 {
118            if version >= 4 {
119                write_compact_array_length(buf, self.topic_names.len() as i32);
120                for el in &self.topic_names {
121                    write_compact_string(buf, el)?;
122                }
123            } else {
124                write_array_length(buf, self.topic_names.len() as i32);
125                for el in &self.topic_names {
126                    write_string(buf, el)?;
127                }
128            }
129        } else if self.topic_names != Vec::new() {
130            return Err(UnsupportedFieldVersion::new(20, "topic_names", version).into());
131        }
132        write_i32(buf, self.timeout_ms);
133        if version >= 4 {
134            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
135            all_tags.sort_by_key(|f| f.tag);
136            write_tagged_fields(buf, &all_tags)?;
137        }
138        Ok(())
139    }
140    pub fn encoded_len(&self, version: i16) -> Result<usize> {
141        if version < 1 || version > 6 {
142            return Err(UnsupportedVersion::new(20, version).into());
143        }
144        let mut len: usize = 0;
145        if version >= 6 {
146            len += compact_array_length_len(self.topics.len() as i32);
147            for el in &self.topics {
148                len += el.encoded_len(version)?;
149            }
150        } else if self.topics != Vec::new() {
151            return Err(UnsupportedFieldVersion::new(20, "topics", version).into());
152        }
153        if version <= 5 {
154            if version >= 4 {
155                len += compact_array_length_len(self.topic_names.len() as i32);
156                for el in &self.topic_names {
157                    len += compact_string_len(el)?;
158                }
159            } else {
160                len += array_length_len();
161                for el in &self.topic_names {
162                    len += string_len(el)?;
163                }
164            }
165        } else if self.topic_names != Vec::new() {
166            return Err(UnsupportedFieldVersion::new(20, "topic_names", version).into());
167        }
168        len += 4;
169        if version >= 4 {
170            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
171            all_tags.sort_by_key(|f| f.tag);
172            len += tagged_fields_len(&all_tags)?;
173        }
174        Ok(len)
175    }
176}
177#[derive(Debug, Clone, PartialEq)]
178pub struct DeleteTopicState {
179    /// The topic name.
180    pub name: Option<KafkaString>,
181    /// The unique topic ID.
182    pub topic_id: KafkaUuid,
183    pub _unknown_tagged_fields: Vec<RawTaggedField>,
184}
185impl Default for DeleteTopicState {
186    fn default() -> Self {
187        Self {
188            name: None,
189            topic_id: KafkaUuid::ZERO,
190            _unknown_tagged_fields: Vec::new(),
191        }
192    }
193}
194impl DeleteTopicState {
195    pub fn with_name(mut self, value: Option<KafkaString>) -> Self {
196        self.name = value;
197        self
198    }
199    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
200        self.topic_id = value;
201        self
202    }
203    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
204        let name;
205        let topic_id;
206        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
207        name = read_compact_nullable_string(buf)?;
208        topic_id = read_uuid(buf)?;
209        let tagged_fields = read_tagged_fields(buf)?;
210        for field in &tagged_fields {
211            match field.tag {
212                _ => {
213                    _unknown_tagged_fields.push(field.clone());
214                },
215            }
216        }
217        Ok(Self {
218            name,
219            topic_id,
220            _unknown_tagged_fields,
221        })
222    }
223    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
224        write_compact_nullable_string(buf, self.name.as_ref())?;
225        write_uuid(buf, &self.topic_id);
226        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
227        all_tags.sort_by_key(|f| f.tag);
228        write_tagged_fields(buf, &all_tags)?;
229        Ok(())
230    }
231    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
232        let mut len: usize = 0;
233        len += compact_nullable_string_len(self.name.as_ref())?;
234        len += 16;
235        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
236        all_tags.sort_by_key(|f| f.tag);
237        len += tagged_fields_len(&all_tags)?;
238        Ok(len)
239    }
240}