kafka_protocol/messages/
delete_records_response.rs

1//! DeleteRecordsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DeleteRecordsResponse.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-2
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DeleteRecordsPartitionResult {
24    /// The partition index.
25    ///
26    /// Supported API versions: 0-2
27    pub partition_index: i32,
28
29    /// The partition low water mark.
30    ///
31    /// Supported API versions: 0-2
32    pub low_watermark: i64,
33
34    /// The deletion error code, or 0 if the deletion succeeded.
35    ///
36    /// Supported API versions: 0-2
37    pub error_code: i16,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl DeleteRecordsPartitionResult {
44    /// Sets `partition_index` to the passed value.
45    ///
46    /// The partition index.
47    ///
48    /// Supported API versions: 0-2
49    pub fn with_partition_index(mut self, value: i32) -> Self {
50        self.partition_index = value;
51        self
52    }
53    /// Sets `low_watermark` to the passed value.
54    ///
55    /// The partition low water mark.
56    ///
57    /// Supported API versions: 0-2
58    pub fn with_low_watermark(mut self, value: i64) -> Self {
59        self.low_watermark = value;
60        self
61    }
62    /// Sets `error_code` to the passed value.
63    ///
64    /// The deletion error code, or 0 if the deletion succeeded.
65    ///
66    /// Supported API versions: 0-2
67    pub fn with_error_code(mut self, value: i16) -> Self {
68        self.error_code = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for DeleteRecordsPartitionResult {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        types::Int32.encode(buf, &self.partition_index)?;
87        types::Int64.encode(buf, &self.low_watermark)?;
88        types::Int16.encode(buf, &self.error_code)?;
89        if version >= 2 {
90            let num_tagged_fields = self.unknown_tagged_fields.len();
91            if num_tagged_fields > std::u32::MAX as usize {
92                bail!(
93                    "Too many tagged fields to encode ({} fields)",
94                    num_tagged_fields
95                );
96            }
97            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
98
99            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
100        }
101        Ok(())
102    }
103    fn compute_size(&self, version: i16) -> Result<usize> {
104        let mut total_size = 0;
105        total_size += types::Int32.compute_size(&self.partition_index)?;
106        total_size += types::Int64.compute_size(&self.low_watermark)?;
107        total_size += types::Int16.compute_size(&self.error_code)?;
108        if version >= 2 {
109            let num_tagged_fields = self.unknown_tagged_fields.len();
110            if num_tagged_fields > std::u32::MAX as usize {
111                bail!(
112                    "Too many tagged fields to encode ({} fields)",
113                    num_tagged_fields
114                );
115            }
116            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
117
118            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
119        }
120        Ok(total_size)
121    }
122}
123
124#[cfg(feature = "client")]
125impl Decodable for DeleteRecordsPartitionResult {
126    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
127        let partition_index = types::Int32.decode(buf)?;
128        let low_watermark = types::Int64.decode(buf)?;
129        let error_code = types::Int16.decode(buf)?;
130        let mut unknown_tagged_fields = BTreeMap::new();
131        if version >= 2 {
132            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
133            for _ in 0..num_tagged_fields {
134                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
135                let size: u32 = types::UnsignedVarInt.decode(buf)?;
136                let unknown_value = buf.try_get_bytes(size as usize)?;
137                unknown_tagged_fields.insert(tag as i32, unknown_value);
138            }
139        }
140        Ok(Self {
141            partition_index,
142            low_watermark,
143            error_code,
144            unknown_tagged_fields,
145        })
146    }
147}
148
149impl Default for DeleteRecordsPartitionResult {
150    fn default() -> Self {
151        Self {
152            partition_index: 0,
153            low_watermark: 0,
154            error_code: 0,
155            unknown_tagged_fields: BTreeMap::new(),
156        }
157    }
158}
159
160impl Message for DeleteRecordsPartitionResult {
161    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
162    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165/// Valid versions: 0-2
166#[non_exhaustive]
167#[derive(Debug, Clone, PartialEq)]
168pub struct DeleteRecordsResponse {
169    /// 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.
170    ///
171    /// Supported API versions: 0-2
172    pub throttle_time_ms: i32,
173
174    /// Each topic that we wanted to delete records from.
175    ///
176    /// Supported API versions: 0-2
177    pub topics: Vec<DeleteRecordsTopicResult>,
178
179    /// Other tagged fields
180    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
181}
182
183impl DeleteRecordsResponse {
184    /// Sets `throttle_time_ms` to the passed value.
185    ///
186    /// 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.
187    ///
188    /// Supported API versions: 0-2
189    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
190        self.throttle_time_ms = value;
191        self
192    }
193    /// Sets `topics` to the passed value.
194    ///
195    /// Each topic that we wanted to delete records from.
196    ///
197    /// Supported API versions: 0-2
198    pub fn with_topics(mut self, value: Vec<DeleteRecordsTopicResult>) -> Self {
199        self.topics = value;
200        self
201    }
202    /// Sets unknown_tagged_fields to the passed value.
203    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
204        self.unknown_tagged_fields = value;
205        self
206    }
207    /// Inserts an entry into unknown_tagged_fields.
208    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
209        self.unknown_tagged_fields.insert(key, value);
210        self
211    }
212}
213
214#[cfg(feature = "broker")]
215impl Encodable for DeleteRecordsResponse {
216    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
217        types::Int32.encode(buf, &self.throttle_time_ms)?;
218        if version >= 2 {
219            types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
220        } else {
221            types::Array(types::Struct { version }).encode(buf, &self.topics)?;
222        }
223        if version >= 2 {
224            let num_tagged_fields = self.unknown_tagged_fields.len();
225            if num_tagged_fields > std::u32::MAX as usize {
226                bail!(
227                    "Too many tagged fields to encode ({} fields)",
228                    num_tagged_fields
229                );
230            }
231            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
232
233            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
234        }
235        Ok(())
236    }
237    fn compute_size(&self, version: i16) -> Result<usize> {
238        let mut total_size = 0;
239        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
240        if version >= 2 {
241            total_size +=
242                types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
243        } else {
244            total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
245        }
246        if version >= 2 {
247            let num_tagged_fields = self.unknown_tagged_fields.len();
248            if num_tagged_fields > std::u32::MAX as usize {
249                bail!(
250                    "Too many tagged fields to encode ({} fields)",
251                    num_tagged_fields
252                );
253            }
254            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
255
256            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
257        }
258        Ok(total_size)
259    }
260}
261
262#[cfg(feature = "client")]
263impl Decodable for DeleteRecordsResponse {
264    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
265        let throttle_time_ms = types::Int32.decode(buf)?;
266        let topics = if version >= 2 {
267            types::CompactArray(types::Struct { version }).decode(buf)?
268        } else {
269            types::Array(types::Struct { version }).decode(buf)?
270        };
271        let mut unknown_tagged_fields = BTreeMap::new();
272        if version >= 2 {
273            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
274            for _ in 0..num_tagged_fields {
275                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
276                let size: u32 = types::UnsignedVarInt.decode(buf)?;
277                let unknown_value = buf.try_get_bytes(size as usize)?;
278                unknown_tagged_fields.insert(tag as i32, unknown_value);
279            }
280        }
281        Ok(Self {
282            throttle_time_ms,
283            topics,
284            unknown_tagged_fields,
285        })
286    }
287}
288
289impl Default for DeleteRecordsResponse {
290    fn default() -> Self {
291        Self {
292            throttle_time_ms: 0,
293            topics: Default::default(),
294            unknown_tagged_fields: BTreeMap::new(),
295        }
296    }
297}
298
299impl Message for DeleteRecordsResponse {
300    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
301    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
302}
303
304/// Valid versions: 0-2
305#[non_exhaustive]
306#[derive(Debug, Clone, PartialEq)]
307pub struct DeleteRecordsTopicResult {
308    /// The topic name.
309    ///
310    /// Supported API versions: 0-2
311    pub name: super::TopicName,
312
313    /// Each partition that we wanted to delete records from.
314    ///
315    /// Supported API versions: 0-2
316    pub partitions: Vec<DeleteRecordsPartitionResult>,
317
318    /// Other tagged fields
319    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
320}
321
322impl DeleteRecordsTopicResult {
323    /// Sets `name` to the passed value.
324    ///
325    /// The topic name.
326    ///
327    /// Supported API versions: 0-2
328    pub fn with_name(mut self, value: super::TopicName) -> Self {
329        self.name = value;
330        self
331    }
332    /// Sets `partitions` to the passed value.
333    ///
334    /// Each partition that we wanted to delete records from.
335    ///
336    /// Supported API versions: 0-2
337    pub fn with_partitions(mut self, value: Vec<DeleteRecordsPartitionResult>) -> Self {
338        self.partitions = value;
339        self
340    }
341    /// Sets unknown_tagged_fields to the passed value.
342    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
343        self.unknown_tagged_fields = value;
344        self
345    }
346    /// Inserts an entry into unknown_tagged_fields.
347    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
348        self.unknown_tagged_fields.insert(key, value);
349        self
350    }
351}
352
353#[cfg(feature = "broker")]
354impl Encodable for DeleteRecordsTopicResult {
355    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
356        if version >= 2 {
357            types::CompactString.encode(buf, &self.name)?;
358        } else {
359            types::String.encode(buf, &self.name)?;
360        }
361        if version >= 2 {
362            types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
363        } else {
364            types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
365        }
366        if version >= 2 {
367            let num_tagged_fields = self.unknown_tagged_fields.len();
368            if num_tagged_fields > std::u32::MAX as usize {
369                bail!(
370                    "Too many tagged fields to encode ({} fields)",
371                    num_tagged_fields
372                );
373            }
374            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
375
376            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
377        }
378        Ok(())
379    }
380    fn compute_size(&self, version: i16) -> Result<usize> {
381        let mut total_size = 0;
382        if version >= 2 {
383            total_size += types::CompactString.compute_size(&self.name)?;
384        } else {
385            total_size += types::String.compute_size(&self.name)?;
386        }
387        if version >= 2 {
388            total_size +=
389                types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
390        } else {
391            total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
392        }
393        if version >= 2 {
394            let num_tagged_fields = self.unknown_tagged_fields.len();
395            if num_tagged_fields > std::u32::MAX as usize {
396                bail!(
397                    "Too many tagged fields to encode ({} fields)",
398                    num_tagged_fields
399                );
400            }
401            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
402
403            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
404        }
405        Ok(total_size)
406    }
407}
408
409#[cfg(feature = "client")]
410impl Decodable for DeleteRecordsTopicResult {
411    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
412        let name = if version >= 2 {
413            types::CompactString.decode(buf)?
414        } else {
415            types::String.decode(buf)?
416        };
417        let partitions = if version >= 2 {
418            types::CompactArray(types::Struct { version }).decode(buf)?
419        } else {
420            types::Array(types::Struct { version }).decode(buf)?
421        };
422        let mut unknown_tagged_fields = BTreeMap::new();
423        if version >= 2 {
424            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
425            for _ in 0..num_tagged_fields {
426                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
427                let size: u32 = types::UnsignedVarInt.decode(buf)?;
428                let unknown_value = buf.try_get_bytes(size as usize)?;
429                unknown_tagged_fields.insert(tag as i32, unknown_value);
430            }
431        }
432        Ok(Self {
433            name,
434            partitions,
435            unknown_tagged_fields,
436        })
437    }
438}
439
440impl Default for DeleteRecordsTopicResult {
441    fn default() -> Self {
442        Self {
443            name: Default::default(),
444            partitions: Default::default(),
445            unknown_tagged_fields: BTreeMap::new(),
446        }
447    }
448}
449
450impl Message for DeleteRecordsTopicResult {
451    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
452    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
453}
454
455impl HeaderVersion for DeleteRecordsResponse {
456    fn header_version(version: i16) -> i16 {
457        if version >= 2 {
458            1
459        } else {
460            0
461        }
462    }
463}