kafka_protocol/messages/
offset_delete_request.rs

1//! OffsetDeleteRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/OffsetDeleteRequest.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
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct OffsetDeleteRequest {
24    /// The unique group identifier.
25    ///
26    /// Supported API versions: 0
27    pub group_id: super::GroupId,
28
29    /// The topics to delete offsets for
30    ///
31    /// Supported API versions: 0
32    pub topics: Vec<OffsetDeleteRequestTopic>,
33}
34
35impl OffsetDeleteRequest {
36    /// Sets `group_id` to the passed value.
37    ///
38    /// The unique group identifier.
39    ///
40    /// Supported API versions: 0
41    pub fn with_group_id(mut self, value: super::GroupId) -> Self {
42        self.group_id = value;
43        self
44    }
45    /// Sets `topics` to the passed value.
46    ///
47    /// The topics to delete offsets for
48    ///
49    /// Supported API versions: 0
50    pub fn with_topics(mut self, value: Vec<OffsetDeleteRequestTopic>) -> Self {
51        self.topics = value;
52        self
53    }
54}
55
56#[cfg(feature = "client")]
57impl Encodable for OffsetDeleteRequest {
58    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
59        types::String.encode(buf, &self.group_id)?;
60        types::Array(types::Struct { version }).encode(buf, &self.topics)?;
61
62        Ok(())
63    }
64    fn compute_size(&self, version: i16) -> Result<usize> {
65        let mut total_size = 0;
66        total_size += types::String.compute_size(&self.group_id)?;
67        total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
68
69        Ok(total_size)
70    }
71}
72
73#[cfg(feature = "broker")]
74impl Decodable for OffsetDeleteRequest {
75    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
76        let group_id = types::String.decode(buf)?;
77        let topics = types::Array(types::Struct { version }).decode(buf)?;
78        Ok(Self { group_id, topics })
79    }
80}
81
82impl Default for OffsetDeleteRequest {
83    fn default() -> Self {
84        Self {
85            group_id: Default::default(),
86            topics: Default::default(),
87        }
88    }
89}
90
91impl Message for OffsetDeleteRequest {
92    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
93    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
94}
95
96/// Valid versions: 0
97#[non_exhaustive]
98#[derive(Debug, Clone, PartialEq)]
99pub struct OffsetDeleteRequestPartition {
100    /// The partition index.
101    ///
102    /// Supported API versions: 0
103    pub partition_index: i32,
104}
105
106impl OffsetDeleteRequestPartition {
107    /// Sets `partition_index` to the passed value.
108    ///
109    /// The partition index.
110    ///
111    /// Supported API versions: 0
112    pub fn with_partition_index(mut self, value: i32) -> Self {
113        self.partition_index = value;
114        self
115    }
116}
117
118#[cfg(feature = "client")]
119impl Encodable for OffsetDeleteRequestPartition {
120    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
121        types::Int32.encode(buf, &self.partition_index)?;
122
123        Ok(())
124    }
125    fn compute_size(&self, version: i16) -> Result<usize> {
126        let mut total_size = 0;
127        total_size += types::Int32.compute_size(&self.partition_index)?;
128
129        Ok(total_size)
130    }
131}
132
133#[cfg(feature = "broker")]
134impl Decodable for OffsetDeleteRequestPartition {
135    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
136        let partition_index = types::Int32.decode(buf)?;
137        Ok(Self { partition_index })
138    }
139}
140
141impl Default for OffsetDeleteRequestPartition {
142    fn default() -> Self {
143        Self { partition_index: 0 }
144    }
145}
146
147impl Message for OffsetDeleteRequestPartition {
148    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
149    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
150}
151
152/// Valid versions: 0
153#[non_exhaustive]
154#[derive(Debug, Clone, PartialEq)]
155pub struct OffsetDeleteRequestTopic {
156    /// The topic name.
157    ///
158    /// Supported API versions: 0
159    pub name: super::TopicName,
160
161    /// Each partition to delete offsets for.
162    ///
163    /// Supported API versions: 0
164    pub partitions: Vec<OffsetDeleteRequestPartition>,
165}
166
167impl OffsetDeleteRequestTopic {
168    /// Sets `name` to the passed value.
169    ///
170    /// The topic name.
171    ///
172    /// Supported API versions: 0
173    pub fn with_name(mut self, value: super::TopicName) -> Self {
174        self.name = value;
175        self
176    }
177    /// Sets `partitions` to the passed value.
178    ///
179    /// Each partition to delete offsets for.
180    ///
181    /// Supported API versions: 0
182    pub fn with_partitions(mut self, value: Vec<OffsetDeleteRequestPartition>) -> Self {
183        self.partitions = value;
184        self
185    }
186}
187
188#[cfg(feature = "client")]
189impl Encodable for OffsetDeleteRequestTopic {
190    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
191        types::String.encode(buf, &self.name)?;
192        types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
193
194        Ok(())
195    }
196    fn compute_size(&self, version: i16) -> Result<usize> {
197        let mut total_size = 0;
198        total_size += types::String.compute_size(&self.name)?;
199        total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
200
201        Ok(total_size)
202    }
203}
204
205#[cfg(feature = "broker")]
206impl Decodable for OffsetDeleteRequestTopic {
207    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
208        let name = types::String.decode(buf)?;
209        let partitions = types::Array(types::Struct { version }).decode(buf)?;
210        Ok(Self { name, partitions })
211    }
212}
213
214impl Default for OffsetDeleteRequestTopic {
215    fn default() -> Self {
216        Self {
217            name: Default::default(),
218            partitions: Default::default(),
219        }
220    }
221}
222
223impl Message for OffsetDeleteRequestTopic {
224    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
225    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
226}
227
228impl HeaderVersion for OffsetDeleteRequest {
229    fn header_version(version: i16) -> i16 {
230        1
231    }
232}