kafka_protocol/messages/
update_raft_voter_request.rs

1//! UpdateRaftVoterRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/UpdateRaftVoterRequest.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 KRaftVersionFeature {
24    /// The minimum supported KRaft protocol version
25    ///
26    /// Supported API versions: 0
27    pub min_supported_version: i16,
28
29    /// The maximum supported KRaft protocol version
30    ///
31    /// Supported API versions: 0
32    pub max_supported_version: i16,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl KRaftVersionFeature {
39    /// Sets `min_supported_version` to the passed value.
40    ///
41    /// The minimum supported KRaft protocol version
42    ///
43    /// Supported API versions: 0
44    pub fn with_min_supported_version(mut self, value: i16) -> Self {
45        self.min_supported_version = value;
46        self
47    }
48    /// Sets `max_supported_version` to the passed value.
49    ///
50    /// The maximum supported KRaft protocol version
51    ///
52    /// Supported API versions: 0
53    pub fn with_max_supported_version(mut self, value: i16) -> Self {
54        self.max_supported_version = 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 KRaftVersionFeature {
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::Int16.encode(buf, &self.min_supported_version)?;
76        types::Int16.encode(buf, &self.max_supported_version)?;
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::Int16.compute_size(&self.min_supported_version)?;
92        total_size += types::Int16.compute_size(&self.max_supported_version)?;
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 KRaftVersionFeature {
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 min_supported_version = types::Int16.decode(buf)?;
114        let max_supported_version = types::Int16.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            min_supported_version,
125            max_supported_version,
126            unknown_tagged_fields,
127        })
128    }
129}
130
131impl Default for KRaftVersionFeature {
132    fn default() -> Self {
133        Self {
134            min_supported_version: 0,
135            max_supported_version: 0,
136            unknown_tagged_fields: BTreeMap::new(),
137        }
138    }
139}
140
141impl Message for KRaftVersionFeature {
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 Listener {
150    /// The name of the endpoint
151    ///
152    /// Supported API versions: 0
153    pub name: StrBytes,
154
155    /// The hostname
156    ///
157    /// Supported API versions: 0
158    pub host: StrBytes,
159
160    /// The port
161    ///
162    /// Supported API versions: 0
163    pub port: u16,
164
165    /// Other tagged fields
166    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
167}
168
169impl Listener {
170    /// Sets `name` to the passed value.
171    ///
172    /// The name of the endpoint
173    ///
174    /// Supported API versions: 0
175    pub fn with_name(mut self, value: StrBytes) -> Self {
176        self.name = value;
177        self
178    }
179    /// Sets `host` to the passed value.
180    ///
181    /// The hostname
182    ///
183    /// Supported API versions: 0
184    pub fn with_host(mut self, value: StrBytes) -> Self {
185        self.host = value;
186        self
187    }
188    /// Sets `port` to the passed value.
189    ///
190    /// The port
191    ///
192    /// Supported API versions: 0
193    pub fn with_port(mut self, value: u16) -> Self {
194        self.port = 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 Listener {
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::CompactString.encode(buf, &self.name)?;
216        types::CompactString.encode(buf, &self.host)?;
217        types::UInt16.encode(buf, &self.port)?;
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::CompactString.compute_size(&self.name)?;
233        total_size += types::CompactString.compute_size(&self.host)?;
234        total_size += types::UInt16.compute_size(&self.port)?;
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 Listener {
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 name = types::CompactString.decode(buf)?;
256        let host = types::CompactString.decode(buf)?;
257        let port = types::UInt16.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            name,
268            host,
269            port,
270            unknown_tagged_fields,
271        })
272    }
273}
274
275impl Default for Listener {
276    fn default() -> Self {
277        Self {
278            name: Default::default(),
279            host: Default::default(),
280            port: 0,
281            unknown_tagged_fields: BTreeMap::new(),
282        }
283    }
284}
285
286impl Message for Listener {
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 UpdateRaftVoterRequest {
295    ///
296    ///
297    /// Supported API versions: 0
298    pub cluster_id: Option<StrBytes>,
299
300    /// The current leader epoch of the partition, -1 for unknown leader epoch
301    ///
302    /// Supported API versions: 0
303    pub current_leader_epoch: i32,
304
305    /// The replica id of the voter getting updated in the topic partition
306    ///
307    /// Supported API versions: 0
308    pub voter_id: i32,
309
310    /// The directory id of the voter getting updated in the topic partition
311    ///
312    /// Supported API versions: 0
313    pub voter_directory_id: Uuid,
314
315    /// The endpoint that can be used to communicate with the leader
316    ///
317    /// Supported API versions: 0
318    pub listeners: Vec<Listener>,
319
320    /// The range of versions of the protocol that the replica supports
321    ///
322    /// Supported API versions: 0
323    pub k_raft_version_feature: KRaftVersionFeature,
324
325    /// Other tagged fields
326    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
327}
328
329impl UpdateRaftVoterRequest {
330    /// Sets `cluster_id` to the passed value.
331    ///
332    ///
333    ///
334    /// Supported API versions: 0
335    pub fn with_cluster_id(mut self, value: Option<StrBytes>) -> Self {
336        self.cluster_id = value;
337        self
338    }
339    /// Sets `current_leader_epoch` to the passed value.
340    ///
341    /// The current leader epoch of the partition, -1 for unknown leader epoch
342    ///
343    /// Supported API versions: 0
344    pub fn with_current_leader_epoch(mut self, value: i32) -> Self {
345        self.current_leader_epoch = value;
346        self
347    }
348    /// Sets `voter_id` to the passed value.
349    ///
350    /// The replica id of the voter getting updated in the topic partition
351    ///
352    /// Supported API versions: 0
353    pub fn with_voter_id(mut self, value: i32) -> Self {
354        self.voter_id = value;
355        self
356    }
357    /// Sets `voter_directory_id` to the passed value.
358    ///
359    /// The directory id of the voter getting updated in the topic partition
360    ///
361    /// Supported API versions: 0
362    pub fn with_voter_directory_id(mut self, value: Uuid) -> Self {
363        self.voter_directory_id = value;
364        self
365    }
366    /// Sets `listeners` to the passed value.
367    ///
368    /// The endpoint that can be used to communicate with the leader
369    ///
370    /// Supported API versions: 0
371    pub fn with_listeners(mut self, value: Vec<Listener>) -> Self {
372        self.listeners = value;
373        self
374    }
375    /// Sets `k_raft_version_feature` to the passed value.
376    ///
377    /// The range of versions of the protocol that the replica supports
378    ///
379    /// Supported API versions: 0
380    pub fn with_k_raft_version_feature(mut self, value: KRaftVersionFeature) -> Self {
381        self.k_raft_version_feature = value;
382        self
383    }
384    /// Sets unknown_tagged_fields to the passed value.
385    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
386        self.unknown_tagged_fields = value;
387        self
388    }
389    /// Inserts an entry into unknown_tagged_fields.
390    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
391        self.unknown_tagged_fields.insert(key, value);
392        self
393    }
394}
395
396#[cfg(feature = "client")]
397impl Encodable for UpdateRaftVoterRequest {
398    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
399        if version != 0 {
400            bail!("specified version not supported by this message type");
401        }
402        types::CompactString.encode(buf, &self.cluster_id)?;
403        types::Int32.encode(buf, &self.current_leader_epoch)?;
404        types::Int32.encode(buf, &self.voter_id)?;
405        types::Uuid.encode(buf, &self.voter_directory_id)?;
406        types::CompactArray(types::Struct { version }).encode(buf, &self.listeners)?;
407        types::Struct { version }.encode(buf, &self.k_raft_version_feature)?;
408        let num_tagged_fields = self.unknown_tagged_fields.len();
409        if num_tagged_fields > std::u32::MAX as usize {
410            bail!(
411                "Too many tagged fields to encode ({} fields)",
412                num_tagged_fields
413            );
414        }
415        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
416
417        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
418        Ok(())
419    }
420    fn compute_size(&self, version: i16) -> Result<usize> {
421        let mut total_size = 0;
422        total_size += types::CompactString.compute_size(&self.cluster_id)?;
423        total_size += types::Int32.compute_size(&self.current_leader_epoch)?;
424        total_size += types::Int32.compute_size(&self.voter_id)?;
425        total_size += types::Uuid.compute_size(&self.voter_directory_id)?;
426        total_size +=
427            types::CompactArray(types::Struct { version }).compute_size(&self.listeners)?;
428        total_size += types::Struct { version }.compute_size(&self.k_raft_version_feature)?;
429        let num_tagged_fields = self.unknown_tagged_fields.len();
430        if num_tagged_fields > std::u32::MAX as usize {
431            bail!(
432                "Too many tagged fields to encode ({} fields)",
433                num_tagged_fields
434            );
435        }
436        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
437
438        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
439        Ok(total_size)
440    }
441}
442
443#[cfg(feature = "broker")]
444impl Decodable for UpdateRaftVoterRequest {
445    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
446        if version != 0 {
447            bail!("specified version not supported by this message type");
448        }
449        let cluster_id = types::CompactString.decode(buf)?;
450        let current_leader_epoch = types::Int32.decode(buf)?;
451        let voter_id = types::Int32.decode(buf)?;
452        let voter_directory_id = types::Uuid.decode(buf)?;
453        let listeners = types::CompactArray(types::Struct { version }).decode(buf)?;
454        let k_raft_version_feature = types::Struct { version }.decode(buf)?;
455        let mut unknown_tagged_fields = BTreeMap::new();
456        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
457        for _ in 0..num_tagged_fields {
458            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
459            let size: u32 = types::UnsignedVarInt.decode(buf)?;
460            let unknown_value = buf.try_get_bytes(size as usize)?;
461            unknown_tagged_fields.insert(tag as i32, unknown_value);
462        }
463        Ok(Self {
464            cluster_id,
465            current_leader_epoch,
466            voter_id,
467            voter_directory_id,
468            listeners,
469            k_raft_version_feature,
470            unknown_tagged_fields,
471        })
472    }
473}
474
475impl Default for UpdateRaftVoterRequest {
476    fn default() -> Self {
477        Self {
478            cluster_id: Some(Default::default()),
479            current_leader_epoch: 0,
480            voter_id: 0,
481            voter_directory_id: Uuid::nil(),
482            listeners: Default::default(),
483            k_raft_version_feature: Default::default(),
484            unknown_tagged_fields: BTreeMap::new(),
485        }
486    }
487}
488
489impl Message for UpdateRaftVoterRequest {
490    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
491    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
492}
493
494impl HeaderVersion for UpdateRaftVoterRequest {
495    fn header_version(version: i16) -> i16 {
496        2
497    }
498}