kafka_protocol/messages/
describe_topic_partitions_request.rs

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