Skip to main content

odradek_protocol/messages/
delete_topics_request.rs

1//! `DeleteTopicsRequest` — generated from `schemas/DeleteTopicsRequest.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 4
25}
26
27/// `DeleteTopicsRequest`, versions 1-6.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct DeleteTopicsRequest {
31    /// The name or topic ID of the topic.
32    pub topics: Vec<DeleteTopicState>,
33    /// The names of the topics to delete.
34    pub topic_names: Vec<String>,
35    /// The length of time in milliseconds to wait for the deletions to complete.
36    pub timeout_ms: i32,
37    /// Tagged fields not (yet) known to this crate, kept raw.
38    pub unknown_tagged_fields: Vec<RawTaggedField>,
39}
40
41impl Default for DeleteTopicsRequest {
42    fn default() -> Self {
43        Self {
44            topics: Vec::new(),
45            topic_names: Vec::new(),
46            timeout_ms: 0,
47            unknown_tagged_fields: Vec::new(),
48        }
49    }
50}
51
52impl DeleteTopicsRequest {
53    /// This message's api key in Kafka's registry.
54    pub const API_KEY: i16 = 20;
55    /// The lowest schema version this snapshot can speak.
56    pub const MIN_VERSION: i16 = 1;
57    /// The highest schema version this snapshot can speak.
58    pub const MAX_VERSION: i16 = 6;
59
60    /// Encode this `DeleteTopicsRequest` at `version`.
61    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
62        if version >= 6 {
63            if is_flexible(version) {
64                wire::put_compact_array_len(buf, Some(self.topics.len()));
65            } else {
66                wire::put_array_len(buf, Some(self.topics.len()))?;
67            }
68            for item in &self.topics {
69                item.encode(buf, version)?;
70            }
71        }
72        if version <= 5 {
73            if is_flexible(version) {
74                wire::put_compact_array_len(buf, Some(self.topic_names.len()));
75            } else {
76                wire::put_array_len(buf, Some(self.topic_names.len()))?;
77            }
78            for item in &self.topic_names {
79                if is_flexible(version) {
80                    wire::put_compact_string(buf, item);
81                } else {
82                    wire::put_string(buf, item)?;
83                }
84            }
85        }
86        buf.put_i32(self.timeout_ms);
87        if is_flexible(version) {
88            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
89        }
90        Ok(())
91    }
92
93    /// Decode one `DeleteTopicsRequest`, bounding allocation by the default
94    /// [`Limits`] derived from `buf`'s remaining length.
95    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
96        Self::decode_with_limits(buf, version, Limits::default())
97    }
98
99    /// Decode one `DeleteTopicsRequest` under `limits`.
100    pub fn decode_with_limits(
101        buf: &mut impl Buf,
102        version: i16,
103        limits: Limits,
104    ) -> Result<Self, DecodeError> {
105        let mut budget = limits.budget(buf.remaining());
106        Self::decode_with_budget(buf, version, &mut budget)
107    }
108
109    /// Decode one `DeleteTopicsRequest` against an existing `budget`.
110    pub fn decode_with_budget(
111        buf: &mut impl Buf,
112        version: i16,
113        budget: &mut Budget,
114    ) -> Result<Self, DecodeError> {
115        let mut this = Self::default();
116        if version >= 6 {
117            this.topics = {
118                let len = if is_flexible(version) {
119                    wire::get_compact_array_len(buf)?
120                } else {
121                    wire::get_array_len(buf)?
122                };
123                match len {
124                    None => return Err(DecodeError::InvalidLength(-1)),
125                    Some(n) => {
126                        let mut items = Vec::new();
127                        for _ in 0..n {
128                            let mark = buf.remaining();
129                            let item = DeleteTopicState::decode_with_budget(buf, version, budget)?;
130                            budget.progress(mark, buf.remaining())?;
131                            budget.push(&mut items, item)?;
132                        }
133                        items
134                    }
135                }
136            };
137        }
138        if version <= 5 {
139            this.topic_names = {
140                let len = if is_flexible(version) {
141                    wire::get_compact_array_len(buf)?
142                } else {
143                    wire::get_array_len(buf)?
144                };
145                match len {
146                    None => return Err(DecodeError::InvalidLength(-1)),
147                    Some(n) => {
148                        let mut items = Vec::new();
149                        for _ in 0..n {
150                            budget.push(
151                                &mut items,
152                                if is_flexible(version) {
153                                    wire::get_compact_string(buf)?
154                                } else {
155                                    wire::get_string(buf)?
156                                },
157                            )?;
158                        }
159                        items
160                    }
161                }
162            };
163        }
164        this.timeout_ms = wire::get_i32(buf)?;
165        if is_flexible(version) {
166            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
167        }
168        Ok(this)
169    }
170}
171
172impl crate::Message for DeleteTopicsRequest {
173    const API_KEY: i16 = 20;
174    const MIN_VERSION: i16 = 1;
175    const MAX_VERSION: i16 = 6;
176
177    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
178        DeleteTopicsRequest::encode(self, buf, version)
179    }
180    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
181        DeleteTopicsRequest::decode(buf, version)
182    }
183    fn decode_with_limits(
184        buf: &mut impl Buf,
185        version: i16,
186        limits: Limits,
187    ) -> Result<Self, DecodeError> {
188        DeleteTopicsRequest::decode_with_limits(buf, version, limits)
189    }
190}
191
192/// `DeleteTopicState` (nested in [`DeleteTopicsRequest`]).
193#[derive(Debug, Clone, PartialEq)]
194#[non_exhaustive]
195pub struct DeleteTopicState {
196    /// The topic name.
197    pub name: Option<String>,
198    /// The unique topic ID.
199    pub topic_id: [u8; 16],
200    /// Tagged fields not (yet) known to this crate, kept raw.
201    pub unknown_tagged_fields: Vec<RawTaggedField>,
202}
203
204impl Default for DeleteTopicState {
205    fn default() -> Self {
206        Self {
207            name: None,
208            topic_id: [0u8; 16],
209            unknown_tagged_fields: Vec::new(),
210        }
211    }
212}
213
214impl DeleteTopicState {
215    /// Encode this `DeleteTopicState` at `version`.
216    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
217        if version >= 6 {
218            if is_flexible(version) {
219                wire::put_compact_nullable_string(buf, self.name.as_deref());
220            } else {
221                wire::put_nullable_string(buf, self.name.as_deref())?;
222            }
223        }
224        if version >= 6 {
225            wire::put_uuid(buf, self.topic_id);
226        }
227        if is_flexible(version) {
228            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
229        }
230        Ok(())
231    }
232
233    /// Decode one `DeleteTopicState`, bounding allocation by the default
234    /// [`Limits`] derived from `buf`'s remaining length.
235    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
236        Self::decode_with_limits(buf, version, Limits::default())
237    }
238
239    /// Decode one `DeleteTopicState` under `limits`.
240    pub fn decode_with_limits(
241        buf: &mut impl Buf,
242        version: i16,
243        limits: Limits,
244    ) -> Result<Self, DecodeError> {
245        let mut budget = limits.budget(buf.remaining());
246        Self::decode_with_budget(buf, version, &mut budget)
247    }
248
249    /// Decode one `DeleteTopicState` against an existing `budget`.
250    pub fn decode_with_budget(
251        buf: &mut impl Buf,
252        version: i16,
253        budget: &mut Budget,
254    ) -> Result<Self, DecodeError> {
255        let mut this = Self::default();
256        if version >= 6 {
257            this.name = if is_flexible(version) {
258                wire::get_compact_nullable_string(buf)?
259            } else {
260                wire::get_nullable_string(buf)?
261            };
262        }
263        if version >= 6 {
264            this.topic_id = wire::get_uuid(buf)?;
265        }
266        if is_flexible(version) {
267            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
268        }
269        Ok(this)
270    }
271}