Skip to main content

kacrab_protocol/generated/
describe_producers_response.rs

1//! Generated from DescribeProducersResponse.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct DescribeProducersResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// Each topic in the response.
21    pub topics: Vec<TopicResponse>,
22    pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for DescribeProducersResponseData {
25    fn default() -> Self {
26        Self {
27            throttle_time_ms: 0_i32,
28            topics: Vec::new(),
29            _unknown_tagged_fields: Vec::new(),
30        }
31    }
32}
33impl DescribeProducersResponseData {
34    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35        self.throttle_time_ms = value;
36        self
37    }
38    pub fn with_topics(mut self, value: Vec<TopicResponse>) -> Self {
39        self.topics = value;
40        self
41    }
42    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43        if version < 0 || version > 0 {
44            return Err(UnsupportedVersion::new(61, version).into());
45        }
46        let throttle_time_ms;
47        let topics;
48        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49        throttle_time_ms = read_i32(buf)?;
50        topics = {
51            let len = read_compact_array_length(buf)?;
52            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
53            for _ in 0..len {
54                arr.push(TopicResponse::read(buf, version)?);
55            }
56            arr
57        };
58        let tagged_fields = read_tagged_fields(buf)?;
59        for field in &tagged_fields {
60            match field.tag {
61                _ => {
62                    _unknown_tagged_fields.push(field.clone());
63                },
64            }
65        }
66        Ok(Self {
67            throttle_time_ms,
68            topics,
69            _unknown_tagged_fields,
70        })
71    }
72    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
73        if version < 0 || version > 0 {
74            return Err(UnsupportedVersion::new(61, version).into());
75        }
76        write_i32(buf, self.throttle_time_ms);
77        write_compact_array_length(buf, self.topics.len() as i32);
78        for el in &self.topics {
79            el.write(buf, version)?;
80        }
81        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
82        all_tags.sort_by_key(|f| f.tag);
83        write_tagged_fields(buf, &all_tags)?;
84        Ok(())
85    }
86    pub fn encoded_len(&self, version: i16) -> Result<usize> {
87        if version < 0 || version > 0 {
88            return Err(UnsupportedVersion::new(61, version).into());
89        }
90        let mut len: usize = 0;
91        len += 4;
92        len += compact_array_length_len(self.topics.len() as i32);
93        for el in &self.topics {
94            len += el.encoded_len(version)?;
95        }
96        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
97        all_tags.sort_by_key(|f| f.tag);
98        len += tagged_fields_len(&all_tags)?;
99        Ok(len)
100    }
101}
102#[derive(Debug, Clone, PartialEq)]
103pub struct TopicResponse {
104    /// The topic name.
105    pub name: KafkaString,
106    /// Each partition in the response.
107    pub partitions: Vec<PartitionResponse>,
108    pub _unknown_tagged_fields: Vec<RawTaggedField>,
109}
110impl Default for TopicResponse {
111    fn default() -> Self {
112        Self {
113            name: KafkaString::default(),
114            partitions: Vec::new(),
115            _unknown_tagged_fields: Vec::new(),
116        }
117    }
118}
119impl TopicResponse {
120    pub fn with_name(mut self, value: KafkaString) -> Self {
121        self.name = value;
122        self
123    }
124    pub fn with_partitions(mut self, value: Vec<PartitionResponse>) -> Self {
125        self.partitions = value;
126        self
127    }
128    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
129        let name;
130        let partitions;
131        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
132        name = read_compact_string(buf)?;
133        partitions = {
134            let len = read_compact_array_length(buf)?;
135            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
136            for _ in 0..len {
137                arr.push(PartitionResponse::read(buf, version)?);
138            }
139            arr
140        };
141        let tagged_fields = read_tagged_fields(buf)?;
142        for field in &tagged_fields {
143            match field.tag {
144                _ => {
145                    _unknown_tagged_fields.push(field.clone());
146                },
147            }
148        }
149        Ok(Self {
150            name,
151            partitions,
152            _unknown_tagged_fields,
153        })
154    }
155    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
156        write_compact_string(buf, &self.name)?;
157        write_compact_array_length(buf, self.partitions.len() as i32);
158        for el in &self.partitions {
159            el.write(buf, version)?;
160        }
161        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
162        all_tags.sort_by_key(|f| f.tag);
163        write_tagged_fields(buf, &all_tags)?;
164        Ok(())
165    }
166    pub fn encoded_len(&self, version: i16) -> Result<usize> {
167        let mut len: usize = 0;
168        len += compact_string_len(&self.name)?;
169        len += compact_array_length_len(self.partitions.len() as i32);
170        for el in &self.partitions {
171            len += el.encoded_len(version)?;
172        }
173        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
174        all_tags.sort_by_key(|f| f.tag);
175        len += tagged_fields_len(&all_tags)?;
176        Ok(len)
177    }
178}
179#[derive(Debug, Clone, PartialEq)]
180pub struct PartitionResponse {
181    /// The partition index.
182    pub partition_index: i32,
183    /// The partition error code, or 0 if there was no error.
184    pub error_code: i16,
185    /// The partition error message, which may be null if no additional details are available.
186    pub error_message: Option<KafkaString>,
187    /// The active producers for the partition.
188    pub active_producers: Vec<ProducerState>,
189    pub _unknown_tagged_fields: Vec<RawTaggedField>,
190}
191impl Default for PartitionResponse {
192    fn default() -> Self {
193        Self {
194            partition_index: 0_i32,
195            error_code: 0_i16,
196            error_message: None,
197            active_producers: Vec::new(),
198            _unknown_tagged_fields: Vec::new(),
199        }
200    }
201}
202impl PartitionResponse {
203    pub fn with_partition_index(mut self, value: i32) -> Self {
204        self.partition_index = value;
205        self
206    }
207    pub fn with_error_code(mut self, value: i16) -> Self {
208        self.error_code = value;
209        self
210    }
211    pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
212        self.error_message = value;
213        self
214    }
215    pub fn with_active_producers(mut self, value: Vec<ProducerState>) -> Self {
216        self.active_producers = value;
217        self
218    }
219    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
220        let partition_index;
221        let error_code;
222        let error_message;
223        let active_producers;
224        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
225        partition_index = read_i32(buf)?;
226        error_code = read_i16(buf)?;
227        error_message = read_compact_nullable_string(buf)?;
228        active_producers = {
229            let len = read_compact_array_length(buf)?;
230            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
231            for _ in 0..len {
232                arr.push(ProducerState::read(buf, version)?);
233            }
234            arr
235        };
236        let tagged_fields = read_tagged_fields(buf)?;
237        for field in &tagged_fields {
238            match field.tag {
239                _ => {
240                    _unknown_tagged_fields.push(field.clone());
241                },
242            }
243        }
244        Ok(Self {
245            partition_index,
246            error_code,
247            error_message,
248            active_producers,
249            _unknown_tagged_fields,
250        })
251    }
252    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
253        write_i32(buf, self.partition_index);
254        write_i16(buf, self.error_code);
255        write_compact_nullable_string(buf, self.error_message.as_ref())?;
256        write_compact_array_length(buf, self.active_producers.len() as i32);
257        for el in &self.active_producers {
258            el.write(buf, version)?;
259        }
260        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
261        all_tags.sort_by_key(|f| f.tag);
262        write_tagged_fields(buf, &all_tags)?;
263        Ok(())
264    }
265    pub fn encoded_len(&self, version: i16) -> Result<usize> {
266        let mut len: usize = 0;
267        len += 4;
268        len += 2;
269        len += compact_nullable_string_len(self.error_message.as_ref())?;
270        len += compact_array_length_len(self.active_producers.len() as i32);
271        for el in &self.active_producers {
272            len += el.encoded_len(version)?;
273        }
274        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
275        all_tags.sort_by_key(|f| f.tag);
276        len += tagged_fields_len(&all_tags)?;
277        Ok(len)
278    }
279}
280#[derive(Debug, Clone, PartialEq)]
281pub struct ProducerState {
282    /// The producer id.
283    pub producer_id: i64,
284    /// The producer epoch.
285    pub producer_epoch: i32,
286    /// The last sequence number sent by the producer.
287    pub last_sequence: i32,
288    /// The last timestamp sent by the producer.
289    pub last_timestamp: i64,
290    /// The current epoch of the producer group.
291    pub coordinator_epoch: i32,
292    /// The current transaction start offset of the producer.
293    pub current_txn_start_offset: i64,
294    pub _unknown_tagged_fields: Vec<RawTaggedField>,
295}
296impl Default for ProducerState {
297    fn default() -> Self {
298        Self {
299            producer_id: 0_i64,
300            producer_epoch: 0_i32,
301            last_sequence: -1i32,
302            last_timestamp: -1i64,
303            coordinator_epoch: 0_i32,
304            current_txn_start_offset: -1i64,
305            _unknown_tagged_fields: Vec::new(),
306        }
307    }
308}
309impl ProducerState {
310    pub fn with_producer_id(mut self, value: i64) -> Self {
311        self.producer_id = value;
312        self
313    }
314    pub fn with_producer_epoch(mut self, value: i32) -> Self {
315        self.producer_epoch = value;
316        self
317    }
318    pub fn with_last_sequence(mut self, value: i32) -> Self {
319        self.last_sequence = value;
320        self
321    }
322    pub fn with_last_timestamp(mut self, value: i64) -> Self {
323        self.last_timestamp = value;
324        self
325    }
326    pub fn with_coordinator_epoch(mut self, value: i32) -> Self {
327        self.coordinator_epoch = value;
328        self
329    }
330    pub fn with_current_txn_start_offset(mut self, value: i64) -> Self {
331        self.current_txn_start_offset = value;
332        self
333    }
334    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
335        let producer_id;
336        let producer_epoch;
337        let last_sequence;
338        let last_timestamp;
339        let coordinator_epoch;
340        let current_txn_start_offset;
341        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
342        producer_id = read_i64(buf)?;
343        producer_epoch = read_i32(buf)?;
344        last_sequence = read_i32(buf)?;
345        last_timestamp = read_i64(buf)?;
346        coordinator_epoch = read_i32(buf)?;
347        current_txn_start_offset = read_i64(buf)?;
348        let tagged_fields = read_tagged_fields(buf)?;
349        for field in &tagged_fields {
350            match field.tag {
351                _ => {
352                    _unknown_tagged_fields.push(field.clone());
353                },
354            }
355        }
356        Ok(Self {
357            producer_id,
358            producer_epoch,
359            last_sequence,
360            last_timestamp,
361            coordinator_epoch,
362            current_txn_start_offset,
363            _unknown_tagged_fields,
364        })
365    }
366    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
367        write_i64(buf, self.producer_id);
368        write_i32(buf, self.producer_epoch);
369        write_i32(buf, self.last_sequence);
370        write_i64(buf, self.last_timestamp);
371        write_i32(buf, self.coordinator_epoch);
372        write_i64(buf, self.current_txn_start_offset);
373        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
374        all_tags.sort_by_key(|f| f.tag);
375        write_tagged_fields(buf, &all_tags)?;
376        Ok(())
377    }
378    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
379        let mut len: usize = 0;
380        len += 8;
381        len += 4;
382        len += 4;
383        len += 8;
384        len += 4;
385        len += 8;
386        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
387        all_tags.sort_by_key(|f| f.tag);
388        len += tagged_fields_len(&all_tags)?;
389        Ok(len)
390    }
391}