kafka_protocol/messages/
delete_topics_response.rs

1//! DeleteTopicsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DeleteTopicsResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 0-6
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DeletableTopicResult {
24    /// The topic name
25    ///
26    /// Supported API versions: 0-6
27    pub name: Option<super::TopicName>,
28
29    /// the unique topic ID
30    ///
31    /// Supported API versions: 6
32    pub topic_id: Uuid,
33
34    /// The deletion error, or 0 if the deletion succeeded.
35    ///
36    /// Supported API versions: 0-6
37    pub error_code: i16,
38
39    /// The error message, or null if there was no error.
40    ///
41    /// Supported API versions: 5-6
42    pub error_message: Option<StrBytes>,
43
44    /// Other tagged fields
45    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
46}
47
48impl DeletableTopicResult {
49    /// Sets `name` to the passed value.
50    ///
51    /// The topic name
52    ///
53    /// Supported API versions: 0-6
54    pub fn with_name(mut self, value: Option<super::TopicName>) -> Self {
55        self.name = value;
56        self
57    }
58    /// Sets `topic_id` to the passed value.
59    ///
60    /// the unique topic ID
61    ///
62    /// Supported API versions: 6
63    pub fn with_topic_id(mut self, value: Uuid) -> Self {
64        self.topic_id = value;
65        self
66    }
67    /// Sets `error_code` to the passed value.
68    ///
69    /// The deletion error, or 0 if the deletion succeeded.
70    ///
71    /// Supported API versions: 0-6
72    pub fn with_error_code(mut self, value: i16) -> Self {
73        self.error_code = value;
74        self
75    }
76    /// Sets `error_message` to the passed value.
77    ///
78    /// The error message, or null if there was no error.
79    ///
80    /// Supported API versions: 5-6
81    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
82        self.error_message = value;
83        self
84    }
85    /// Sets unknown_tagged_fields to the passed value.
86    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
87        self.unknown_tagged_fields = value;
88        self
89    }
90    /// Inserts an entry into unknown_tagged_fields.
91    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
92        self.unknown_tagged_fields.insert(key, value);
93        self
94    }
95}
96
97#[cfg(feature = "broker")]
98impl Encodable for DeletableTopicResult {
99    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
100        if version < 0 || version > 6 {
101            bail!("specified version not supported by this message type");
102        }
103        if version >= 4 {
104            types::CompactString.encode(buf, &self.name)?;
105        } else {
106            types::String.encode(buf, &self.name)?;
107        }
108        if version >= 6 {
109            types::Uuid.encode(buf, &self.topic_id)?;
110        }
111        types::Int16.encode(buf, &self.error_code)?;
112        if version >= 5 {
113            types::CompactString.encode(buf, &self.error_message)?;
114        }
115        if version >= 4 {
116            let num_tagged_fields = self.unknown_tagged_fields.len();
117            if num_tagged_fields > std::u32::MAX as usize {
118                bail!(
119                    "Too many tagged fields to encode ({} fields)",
120                    num_tagged_fields
121                );
122            }
123            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
124
125            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
126        }
127        Ok(())
128    }
129    fn compute_size(&self, version: i16) -> Result<usize> {
130        let mut total_size = 0;
131        if version >= 4 {
132            total_size += types::CompactString.compute_size(&self.name)?;
133        } else {
134            total_size += types::String.compute_size(&self.name)?;
135        }
136        if version >= 6 {
137            total_size += types::Uuid.compute_size(&self.topic_id)?;
138        }
139        total_size += types::Int16.compute_size(&self.error_code)?;
140        if version >= 5 {
141            total_size += types::CompactString.compute_size(&self.error_message)?;
142        }
143        if version >= 4 {
144            let num_tagged_fields = self.unknown_tagged_fields.len();
145            if num_tagged_fields > std::u32::MAX as usize {
146                bail!(
147                    "Too many tagged fields to encode ({} fields)",
148                    num_tagged_fields
149                );
150            }
151            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
152
153            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
154        }
155        Ok(total_size)
156    }
157}
158
159#[cfg(feature = "client")]
160impl Decodable for DeletableTopicResult {
161    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
162        if version < 0 || version > 6 {
163            bail!("specified version not supported by this message type");
164        }
165        let name = if version >= 4 {
166            types::CompactString.decode(buf)?
167        } else {
168            types::String.decode(buf)?
169        };
170        let topic_id = if version >= 6 {
171            types::Uuid.decode(buf)?
172        } else {
173            Uuid::nil()
174        };
175        let error_code = types::Int16.decode(buf)?;
176        let error_message = if version >= 5 {
177            types::CompactString.decode(buf)?
178        } else {
179            None
180        };
181        let mut unknown_tagged_fields = BTreeMap::new();
182        if version >= 4 {
183            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
184            for _ in 0..num_tagged_fields {
185                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
186                let size: u32 = types::UnsignedVarInt.decode(buf)?;
187                let unknown_value = buf.try_get_bytes(size as usize)?;
188                unknown_tagged_fields.insert(tag as i32, unknown_value);
189            }
190        }
191        Ok(Self {
192            name,
193            topic_id,
194            error_code,
195            error_message,
196            unknown_tagged_fields,
197        })
198    }
199}
200
201impl Default for DeletableTopicResult {
202    fn default() -> Self {
203        Self {
204            name: Some(Default::default()),
205            topic_id: Uuid::nil(),
206            error_code: 0,
207            error_message: None,
208            unknown_tagged_fields: BTreeMap::new(),
209        }
210    }
211}
212
213impl Message for DeletableTopicResult {
214    const VERSIONS: VersionRange = VersionRange { min: 0, max: 6 };
215    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
216}
217
218/// Valid versions: 0-6
219#[non_exhaustive]
220#[derive(Debug, Clone, PartialEq)]
221pub struct DeleteTopicsResponse {
222    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
223    ///
224    /// Supported API versions: 1-6
225    pub throttle_time_ms: i32,
226
227    /// The results for each topic we tried to delete.
228    ///
229    /// Supported API versions: 0-6
230    pub responses: Vec<DeletableTopicResult>,
231
232    /// Other tagged fields
233    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
234}
235
236impl DeleteTopicsResponse {
237    /// Sets `throttle_time_ms` to the passed value.
238    ///
239    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
240    ///
241    /// Supported API versions: 1-6
242    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
243        self.throttle_time_ms = value;
244        self
245    }
246    /// Sets `responses` to the passed value.
247    ///
248    /// The results for each topic we tried to delete.
249    ///
250    /// Supported API versions: 0-6
251    pub fn with_responses(mut self, value: Vec<DeletableTopicResult>) -> Self {
252        self.responses = value;
253        self
254    }
255    /// Sets unknown_tagged_fields to the passed value.
256    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
257        self.unknown_tagged_fields = value;
258        self
259    }
260    /// Inserts an entry into unknown_tagged_fields.
261    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
262        self.unknown_tagged_fields.insert(key, value);
263        self
264    }
265}
266
267#[cfg(feature = "broker")]
268impl Encodable for DeleteTopicsResponse {
269    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
270        if version < 0 || version > 6 {
271            bail!("specified version not supported by this message type");
272        }
273        if version >= 1 {
274            types::Int32.encode(buf, &self.throttle_time_ms)?;
275        }
276        if version >= 4 {
277            types::CompactArray(types::Struct { version }).encode(buf, &self.responses)?;
278        } else {
279            types::Array(types::Struct { version }).encode(buf, &self.responses)?;
280        }
281        if version >= 4 {
282            let num_tagged_fields = self.unknown_tagged_fields.len();
283            if num_tagged_fields > std::u32::MAX as usize {
284                bail!(
285                    "Too many tagged fields to encode ({} fields)",
286                    num_tagged_fields
287                );
288            }
289            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
290
291            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
292        }
293        Ok(())
294    }
295    fn compute_size(&self, version: i16) -> Result<usize> {
296        let mut total_size = 0;
297        if version >= 1 {
298            total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
299        }
300        if version >= 4 {
301            total_size +=
302                types::CompactArray(types::Struct { version }).compute_size(&self.responses)?;
303        } else {
304            total_size += types::Array(types::Struct { version }).compute_size(&self.responses)?;
305        }
306        if version >= 4 {
307            let num_tagged_fields = self.unknown_tagged_fields.len();
308            if num_tagged_fields > std::u32::MAX as usize {
309                bail!(
310                    "Too many tagged fields to encode ({} fields)",
311                    num_tagged_fields
312                );
313            }
314            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
315
316            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
317        }
318        Ok(total_size)
319    }
320}
321
322#[cfg(feature = "client")]
323impl Decodable for DeleteTopicsResponse {
324    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
325        if version < 0 || version > 6 {
326            bail!("specified version not supported by this message type");
327        }
328        let throttle_time_ms = if version >= 1 {
329            types::Int32.decode(buf)?
330        } else {
331            0
332        };
333        let responses = if version >= 4 {
334            types::CompactArray(types::Struct { version }).decode(buf)?
335        } else {
336            types::Array(types::Struct { version }).decode(buf)?
337        };
338        let mut unknown_tagged_fields = BTreeMap::new();
339        if version >= 4 {
340            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
341            for _ in 0..num_tagged_fields {
342                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
343                let size: u32 = types::UnsignedVarInt.decode(buf)?;
344                let unknown_value = buf.try_get_bytes(size as usize)?;
345                unknown_tagged_fields.insert(tag as i32, unknown_value);
346            }
347        }
348        Ok(Self {
349            throttle_time_ms,
350            responses,
351            unknown_tagged_fields,
352        })
353    }
354}
355
356impl Default for DeleteTopicsResponse {
357    fn default() -> Self {
358        Self {
359            throttle_time_ms: 0,
360            responses: Default::default(),
361            unknown_tagged_fields: BTreeMap::new(),
362        }
363    }
364}
365
366impl Message for DeleteTopicsResponse {
367    const VERSIONS: VersionRange = VersionRange { min: 0, max: 6 };
368    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
369}
370
371impl HeaderVersion for DeleteTopicsResponse {
372    fn header_version(version: i16) -> i16 {
373        if version >= 4 {
374            1
375        } else {
376            0
377        }
378    }
379}