Skip to main content

kacrab_protocol/generated/
share_acknowledge_response.rs

1//! Generated from ShareAcknowledgeResponse.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 ShareAcknowledgeResponseData {
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    /// The top level response error code.
21    pub error_code: i16,
22    /// The top-level error message, or null if there was no error.
23    pub error_message: Option<KafkaString>,
24    /// The time in milliseconds for which the acquired records are locked.
25    pub acquisition_lock_timeout_ms: i32,
26    /// The response topics.
27    pub responses: Vec<ShareAcknowledgeTopicResponse>,
28    /// Endpoints for all current leaders enumerated in PartitionData with error
29    /// NOT_LEADER_OR_FOLLOWER.
30    pub node_endpoints: Vec<NodeEndpoint>,
31    pub _unknown_tagged_fields: Vec<RawTaggedField>,
32}
33impl Default for ShareAcknowledgeResponseData {
34    fn default() -> Self {
35        Self {
36            throttle_time_ms: 0_i32,
37            error_code: 0_i16,
38            error_message: None,
39            acquisition_lock_timeout_ms: 0_i32,
40            responses: Vec::new(),
41            node_endpoints: Vec::new(),
42            _unknown_tagged_fields: Vec::new(),
43        }
44    }
45}
46impl ShareAcknowledgeResponseData {
47    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
48        self.throttle_time_ms = value;
49        self
50    }
51    pub fn with_error_code(mut self, value: i16) -> Self {
52        self.error_code = value;
53        self
54    }
55    pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
56        self.error_message = value;
57        self
58    }
59    pub fn with_acquisition_lock_timeout_ms(mut self, value: i32) -> Self {
60        self.acquisition_lock_timeout_ms = value;
61        self
62    }
63    pub fn with_responses(mut self, value: Vec<ShareAcknowledgeTopicResponse>) -> Self {
64        self.responses = value;
65        self
66    }
67    pub fn with_node_endpoints(mut self, value: Vec<NodeEndpoint>) -> Self {
68        self.node_endpoints = value;
69        self
70    }
71    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
72        if version < 1 || version > 2 {
73            return Err(UnsupportedVersion::new(79, version).into());
74        }
75        let throttle_time_ms;
76        let error_code;
77        let error_message;
78        let mut acquisition_lock_timeout_ms = 0_i32;
79        let responses;
80        let node_endpoints;
81        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
82        throttle_time_ms = read_i32(buf)?;
83        error_code = read_i16(buf)?;
84        error_message = read_compact_nullable_string(buf)?;
85        if version >= 2 {
86            acquisition_lock_timeout_ms = read_i32(buf)?;
87        }
88        responses = {
89            let len = read_compact_array_length(buf)?;
90            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
91            for _ in 0..len {
92                arr.push(ShareAcknowledgeTopicResponse::read(buf, version)?);
93            }
94            arr
95        };
96        node_endpoints = {
97            let len = read_compact_array_length(buf)?;
98            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
99            for _ in 0..len {
100                arr.push(NodeEndpoint::read(buf, version)?);
101            }
102            arr
103        };
104        let tagged_fields = read_tagged_fields(buf)?;
105        for field in &tagged_fields {
106            match field.tag {
107                _ => {
108                    _unknown_tagged_fields.push(field.clone());
109                },
110            }
111        }
112        Ok(Self {
113            throttle_time_ms,
114            error_code,
115            error_message,
116            acquisition_lock_timeout_ms,
117            responses,
118            node_endpoints,
119            _unknown_tagged_fields,
120        })
121    }
122    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
123        if version < 1 || version > 2 {
124            return Err(UnsupportedVersion::new(79, version).into());
125        }
126        write_i32(buf, self.throttle_time_ms);
127        write_i16(buf, self.error_code);
128        write_compact_nullable_string(buf, self.error_message.as_ref())?;
129        if version >= 2 {
130            write_i32(buf, self.acquisition_lock_timeout_ms);
131        } else if self.acquisition_lock_timeout_ms != 0_i32 {
132            return Err(
133                UnsupportedFieldVersion::new(79, "acquisition_lock_timeout_ms", version).into(),
134            );
135        }
136        write_compact_array_length(buf, self.responses.len() as i32);
137        for el in &self.responses {
138            el.write(buf, version)?;
139        }
140        write_compact_array_length(buf, self.node_endpoints.len() as i32);
141        for el in &self.node_endpoints {
142            el.write(buf, version)?;
143        }
144        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
145        all_tags.sort_by_key(|f| f.tag);
146        write_tagged_fields(buf, &all_tags)?;
147        Ok(())
148    }
149    pub fn encoded_len(&self, version: i16) -> Result<usize> {
150        if version < 1 || version > 2 {
151            return Err(UnsupportedVersion::new(79, version).into());
152        }
153        let mut len: usize = 0;
154        len += 4;
155        len += 2;
156        len += compact_nullable_string_len(self.error_message.as_ref())?;
157        if version >= 2 {
158            len += 4;
159        } else if self.acquisition_lock_timeout_ms != 0_i32 {
160            return Err(
161                UnsupportedFieldVersion::new(79, "acquisition_lock_timeout_ms", version).into(),
162            );
163        }
164        len += compact_array_length_len(self.responses.len() as i32);
165        for el in &self.responses {
166            len += el.encoded_len(version)?;
167        }
168        len += compact_array_length_len(self.node_endpoints.len() as i32);
169        for el in &self.node_endpoints {
170            len += el.encoded_len(version)?;
171        }
172        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
173        all_tags.sort_by_key(|f| f.tag);
174        len += tagged_fields_len(&all_tags)?;
175        Ok(len)
176    }
177}
178#[derive(Debug, Clone, PartialEq)]
179pub struct ShareAcknowledgeTopicResponse {
180    /// The unique topic ID.
181    pub topic_id: KafkaUuid,
182    /// The topic partitions.
183    pub partitions: Vec<PartitionData>,
184    pub _unknown_tagged_fields: Vec<RawTaggedField>,
185}
186impl Default for ShareAcknowledgeTopicResponse {
187    fn default() -> Self {
188        Self {
189            topic_id: KafkaUuid::ZERO,
190            partitions: Vec::new(),
191            _unknown_tagged_fields: Vec::new(),
192        }
193    }
194}
195impl ShareAcknowledgeTopicResponse {
196    pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
197        self.topic_id = value;
198        self
199    }
200    pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
201        self.partitions = value;
202        self
203    }
204    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
205        let topic_id;
206        let partitions;
207        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
208        topic_id = read_uuid(buf)?;
209        partitions = {
210            let len = read_compact_array_length(buf)?;
211            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
212            for _ in 0..len {
213                arr.push(PartitionData::read(buf, version)?);
214            }
215            arr
216        };
217        let tagged_fields = read_tagged_fields(buf)?;
218        for field in &tagged_fields {
219            match field.tag {
220                _ => {
221                    _unknown_tagged_fields.push(field.clone());
222                },
223            }
224        }
225        Ok(Self {
226            topic_id,
227            partitions,
228            _unknown_tagged_fields,
229        })
230    }
231    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
232        write_uuid(buf, &self.topic_id);
233        write_compact_array_length(buf, self.partitions.len() as i32);
234        for el in &self.partitions {
235            el.write(buf, version)?;
236        }
237        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
238        all_tags.sort_by_key(|f| f.tag);
239        write_tagged_fields(buf, &all_tags)?;
240        Ok(())
241    }
242    pub fn encoded_len(&self, version: i16) -> Result<usize> {
243        let mut len: usize = 0;
244        len += 16;
245        len += compact_array_length_len(self.partitions.len() as i32);
246        for el in &self.partitions {
247            len += el.encoded_len(version)?;
248        }
249        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
250        all_tags.sort_by_key(|f| f.tag);
251        len += tagged_fields_len(&all_tags)?;
252        Ok(len)
253    }
254}
255#[derive(Debug, Clone, PartialEq)]
256pub struct PartitionData {
257    /// The partition index.
258    pub partition_index: i32,
259    /// The error code, or 0 if there was no error.
260    pub error_code: i16,
261    /// The error message, or null if there was no error.
262    pub error_message: Option<KafkaString>,
263    /// The current leader of the partition.
264    pub current_leader: LeaderIdAndEpoch,
265    pub _unknown_tagged_fields: Vec<RawTaggedField>,
266}
267impl Default for PartitionData {
268    fn default() -> Self {
269        Self {
270            partition_index: 0_i32,
271            error_code: 0_i16,
272            error_message: None,
273            current_leader: LeaderIdAndEpoch::default(),
274            _unknown_tagged_fields: Vec::new(),
275        }
276    }
277}
278impl PartitionData {
279    pub fn with_partition_index(mut self, value: i32) -> Self {
280        self.partition_index = value;
281        self
282    }
283    pub fn with_error_code(mut self, value: i16) -> Self {
284        self.error_code = value;
285        self
286    }
287    pub fn with_error_message(mut self, value: Option<KafkaString>) -> Self {
288        self.error_message = value;
289        self
290    }
291    pub fn with_current_leader(mut self, value: LeaderIdAndEpoch) -> Self {
292        self.current_leader = value;
293        self
294    }
295    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
296        let partition_index;
297        let error_code;
298        let error_message;
299        let current_leader;
300        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
301        partition_index = read_i32(buf)?;
302        error_code = read_i16(buf)?;
303        error_message = read_compact_nullable_string(buf)?;
304        current_leader = LeaderIdAndEpoch::read(buf, version)?;
305        let tagged_fields = read_tagged_fields(buf)?;
306        for field in &tagged_fields {
307            match field.tag {
308                _ => {
309                    _unknown_tagged_fields.push(field.clone());
310                },
311            }
312        }
313        Ok(Self {
314            partition_index,
315            error_code,
316            error_message,
317            current_leader,
318            _unknown_tagged_fields,
319        })
320    }
321    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
322        write_i32(buf, self.partition_index);
323        write_i16(buf, self.error_code);
324        write_compact_nullable_string(buf, self.error_message.as_ref())?;
325        self.current_leader.write(buf, version)?;
326        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
327        all_tags.sort_by_key(|f| f.tag);
328        write_tagged_fields(buf, &all_tags)?;
329        Ok(())
330    }
331    pub fn encoded_len(&self, version: i16) -> Result<usize> {
332        let mut len: usize = 0;
333        len += 4;
334        len += 2;
335        len += compact_nullable_string_len(self.error_message.as_ref())?;
336        len += self.current_leader.encoded_len(version)?;
337        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
338        all_tags.sort_by_key(|f| f.tag);
339        len += tagged_fields_len(&all_tags)?;
340        Ok(len)
341    }
342}
343#[derive(Debug, Clone, PartialEq)]
344pub struct LeaderIdAndEpoch {
345    /// The ID of the current leader or -1 if the leader is unknown.
346    pub leader_id: i32,
347    /// The latest known leader epoch.
348    pub leader_epoch: i32,
349    pub _unknown_tagged_fields: Vec<RawTaggedField>,
350}
351impl Default for LeaderIdAndEpoch {
352    fn default() -> Self {
353        Self {
354            leader_id: 0_i32,
355            leader_epoch: 0_i32,
356            _unknown_tagged_fields: Vec::new(),
357        }
358    }
359}
360impl LeaderIdAndEpoch {
361    pub fn with_leader_id(mut self, value: i32) -> Self {
362        self.leader_id = value;
363        self
364    }
365    pub fn with_leader_epoch(mut self, value: i32) -> Self {
366        self.leader_epoch = value;
367        self
368    }
369    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
370        let leader_id;
371        let leader_epoch;
372        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
373        leader_id = read_i32(buf)?;
374        leader_epoch = read_i32(buf)?;
375        let tagged_fields = read_tagged_fields(buf)?;
376        for field in &tagged_fields {
377            match field.tag {
378                _ => {
379                    _unknown_tagged_fields.push(field.clone());
380                },
381            }
382        }
383        Ok(Self {
384            leader_id,
385            leader_epoch,
386            _unknown_tagged_fields,
387        })
388    }
389    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
390        write_i32(buf, self.leader_id);
391        write_i32(buf, self.leader_epoch);
392        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
393        all_tags.sort_by_key(|f| f.tag);
394        write_tagged_fields(buf, &all_tags)?;
395        Ok(())
396    }
397    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
398        let mut len: usize = 0;
399        len += 4;
400        len += 4;
401        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
402        all_tags.sort_by_key(|f| f.tag);
403        len += tagged_fields_len(&all_tags)?;
404        Ok(len)
405    }
406}
407#[derive(Debug, Clone, PartialEq)]
408pub struct NodeEndpoint {
409    /// The ID of the associated node.
410    pub node_id: i32,
411    /// The node's hostname.
412    pub host: KafkaString,
413    /// The node's port.
414    pub port: i32,
415    /// The rack of the node, or null if it has not been assigned to a rack.
416    pub rack: Option<KafkaString>,
417    pub _unknown_tagged_fields: Vec<RawTaggedField>,
418}
419impl Default for NodeEndpoint {
420    fn default() -> Self {
421        Self {
422            node_id: 0_i32,
423            host: KafkaString::default(),
424            port: 0_i32,
425            rack: None,
426            _unknown_tagged_fields: Vec::new(),
427        }
428    }
429}
430impl NodeEndpoint {
431    pub fn with_node_id(mut self, value: i32) -> Self {
432        self.node_id = value;
433        self
434    }
435    pub fn with_host(mut self, value: KafkaString) -> Self {
436        self.host = value;
437        self
438    }
439    pub fn with_port(mut self, value: i32) -> Self {
440        self.port = value;
441        self
442    }
443    pub fn with_rack(mut self, value: Option<KafkaString>) -> Self {
444        self.rack = value;
445        self
446    }
447    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
448        let node_id;
449        let host;
450        let port;
451        let rack;
452        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
453        node_id = read_i32(buf)?;
454        host = read_compact_string(buf)?;
455        port = read_i32(buf)?;
456        rack = read_compact_nullable_string(buf)?;
457        let tagged_fields = read_tagged_fields(buf)?;
458        for field in &tagged_fields {
459            match field.tag {
460                _ => {
461                    _unknown_tagged_fields.push(field.clone());
462                },
463            }
464        }
465        Ok(Self {
466            node_id,
467            host,
468            port,
469            rack,
470            _unknown_tagged_fields,
471        })
472    }
473    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
474        write_i32(buf, self.node_id);
475        write_compact_string(buf, &self.host)?;
476        write_i32(buf, self.port);
477        write_compact_nullable_string(buf, self.rack.as_ref())?;
478        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
479        all_tags.sort_by_key(|f| f.tag);
480        write_tagged_fields(buf, &all_tags)?;
481        Ok(())
482    }
483    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
484        let mut len: usize = 0;
485        len += 4;
486        len += compact_string_len(&self.host)?;
487        len += 4;
488        len += compact_nullable_string_len(self.rack.as_ref())?;
489        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
490        all_tags.sort_by_key(|f| f.tag);
491        len += tagged_fields_len(&all_tags)?;
492        Ok(len)
493    }
494}