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        if version != 0 {
60            bail!("specified version not supported by this message type");
61        }
62        types::String.encode(buf, &self.group_id)?;
63        types::Array(types::Struct { version }).encode(buf, &self.topics)?;
64
65        Ok(())
66    }
67    fn compute_size(&self, version: i16) -> Result<usize> {
68        let mut total_size = 0;
69        total_size += types::String.compute_size(&self.group_id)?;
70        total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
71
72        Ok(total_size)
73    }
74}
75
76#[cfg(feature = "broker")]
77impl Decodable for OffsetDeleteRequest {
78    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
79        if version != 0 {
80            bail!("specified version not supported by this message type");
81        }
82        let group_id = types::String.decode(buf)?;
83        let topics = types::Array(types::Struct { version }).decode(buf)?;
84        Ok(Self { group_id, topics })
85    }
86}
87
88impl Default for OffsetDeleteRequest {
89    fn default() -> Self {
90        Self {
91            group_id: Default::default(),
92            topics: Default::default(),
93        }
94    }
95}
96
97impl Message for OffsetDeleteRequest {
98    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
99    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
100}
101
102/// Valid versions: 0
103#[non_exhaustive]
104#[derive(Debug, Clone, PartialEq)]
105pub struct OffsetDeleteRequestPartition {
106    /// The partition index.
107    ///
108    /// Supported API versions: 0
109    pub partition_index: i32,
110}
111
112impl OffsetDeleteRequestPartition {
113    /// Sets `partition_index` to the passed value.
114    ///
115    /// The partition index.
116    ///
117    /// Supported API versions: 0
118    pub fn with_partition_index(mut self, value: i32) -> Self {
119        self.partition_index = value;
120        self
121    }
122}
123
124#[cfg(feature = "client")]
125impl Encodable for OffsetDeleteRequestPartition {
126    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
127        if version != 0 {
128            bail!("specified version not supported by this message type");
129        }
130        types::Int32.encode(buf, &self.partition_index)?;
131
132        Ok(())
133    }
134    fn compute_size(&self, version: i16) -> Result<usize> {
135        let mut total_size = 0;
136        total_size += types::Int32.compute_size(&self.partition_index)?;
137
138        Ok(total_size)
139    }
140}
141
142#[cfg(feature = "broker")]
143impl Decodable for OffsetDeleteRequestPartition {
144    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
145        if version != 0 {
146            bail!("specified version not supported by this message type");
147        }
148        let partition_index = types::Int32.decode(buf)?;
149        Ok(Self { partition_index })
150    }
151}
152
153impl Default for OffsetDeleteRequestPartition {
154    fn default() -> Self {
155        Self { partition_index: 0 }
156    }
157}
158
159impl Message for OffsetDeleteRequestPartition {
160    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
161    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
162}
163
164/// Valid versions: 0
165#[non_exhaustive]
166#[derive(Debug, Clone, PartialEq)]
167pub struct OffsetDeleteRequestTopic {
168    /// The topic name.
169    ///
170    /// Supported API versions: 0
171    pub name: super::TopicName,
172
173    /// Each partition to delete offsets for.
174    ///
175    /// Supported API versions: 0
176    pub partitions: Vec<OffsetDeleteRequestPartition>,
177}
178
179impl OffsetDeleteRequestTopic {
180    /// Sets `name` to the passed value.
181    ///
182    /// The topic name.
183    ///
184    /// Supported API versions: 0
185    pub fn with_name(mut self, value: super::TopicName) -> Self {
186        self.name = value;
187        self
188    }
189    /// Sets `partitions` to the passed value.
190    ///
191    /// Each partition to delete offsets for.
192    ///
193    /// Supported API versions: 0
194    pub fn with_partitions(mut self, value: Vec<OffsetDeleteRequestPartition>) -> Self {
195        self.partitions = value;
196        self
197    }
198}
199
200#[cfg(feature = "client")]
201impl Encodable for OffsetDeleteRequestTopic {
202    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
203        if version != 0 {
204            bail!("specified version not supported by this message type");
205        }
206        types::String.encode(buf, &self.name)?;
207        types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
208
209        Ok(())
210    }
211    fn compute_size(&self, version: i16) -> Result<usize> {
212        let mut total_size = 0;
213        total_size += types::String.compute_size(&self.name)?;
214        total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
215
216        Ok(total_size)
217    }
218}
219
220#[cfg(feature = "broker")]
221impl Decodable for OffsetDeleteRequestTopic {
222    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
223        if version != 0 {
224            bail!("specified version not supported by this message type");
225        }
226        let name = types::String.decode(buf)?;
227        let partitions = types::Array(types::Struct { version }).decode(buf)?;
228        Ok(Self { name, partitions })
229    }
230}
231
232impl Default for OffsetDeleteRequestTopic {
233    fn default() -> Self {
234        Self {
235            name: Default::default(),
236            partitions: Default::default(),
237        }
238    }
239}
240
241impl Message for OffsetDeleteRequestTopic {
242    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
243    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
244}
245
246impl HeaderVersion for OffsetDeleteRequest {
247    fn header_version(version: i16) -> i16 {
248        1
249    }
250}