kafka_protocol/messages/
remove_raft_voter_request.rs

1//! RemoveRaftVoterRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/RemoveRaftVoterRequest.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 RemoveRaftVoterRequest {
24    ///
25    ///
26    /// Supported API versions: 0
27    pub cluster_id: Option<StrBytes>,
28
29    /// The replica id of the voter getting removed from the topic partition
30    ///
31    /// Supported API versions: 0
32    pub voter_id: i32,
33
34    /// The directory id of the voter getting removed from the topic partition
35    ///
36    /// Supported API versions: 0
37    pub voter_directory_id: Uuid,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl RemoveRaftVoterRequest {
44    /// Sets `cluster_id` to the passed value.
45    ///
46    ///
47    ///
48    /// Supported API versions: 0
49    pub fn with_cluster_id(mut self, value: Option<StrBytes>) -> Self {
50        self.cluster_id = value;
51        self
52    }
53    /// Sets `voter_id` to the passed value.
54    ///
55    /// The replica id of the voter getting removed from the topic partition
56    ///
57    /// Supported API versions: 0
58    pub fn with_voter_id(mut self, value: i32) -> Self {
59        self.voter_id = value;
60        self
61    }
62    /// Sets `voter_directory_id` to the passed value.
63    ///
64    /// The directory id of the voter getting removed from the topic partition
65    ///
66    /// Supported API versions: 0
67    pub fn with_voter_directory_id(mut self, value: Uuid) -> Self {
68        self.voter_directory_id = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "client")]
84impl Encodable for RemoveRaftVoterRequest {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version != 0 {
87            bail!("specified version not supported by this message type");
88        }
89        types::CompactString.encode(buf, &self.cluster_id)?;
90        types::Int32.encode(buf, &self.voter_id)?;
91        types::Uuid.encode(buf, &self.voter_directory_id)?;
92        let num_tagged_fields = self.unknown_tagged_fields.len();
93        if num_tagged_fields > std::u32::MAX as usize {
94            bail!(
95                "Too many tagged fields to encode ({} fields)",
96                num_tagged_fields
97            );
98        }
99        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
100
101        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
102        Ok(())
103    }
104    fn compute_size(&self, version: i16) -> Result<usize> {
105        let mut total_size = 0;
106        total_size += types::CompactString.compute_size(&self.cluster_id)?;
107        total_size += types::Int32.compute_size(&self.voter_id)?;
108        total_size += types::Uuid.compute_size(&self.voter_directory_id)?;
109        let num_tagged_fields = self.unknown_tagged_fields.len();
110        if num_tagged_fields > std::u32::MAX as usize {
111            bail!(
112                "Too many tagged fields to encode ({} fields)",
113                num_tagged_fields
114            );
115        }
116        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
117
118        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
119        Ok(total_size)
120    }
121}
122
123#[cfg(feature = "broker")]
124impl Decodable for RemoveRaftVoterRequest {
125    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
126        if version != 0 {
127            bail!("specified version not supported by this message type");
128        }
129        let cluster_id = types::CompactString.decode(buf)?;
130        let voter_id = types::Int32.decode(buf)?;
131        let voter_directory_id = types::Uuid.decode(buf)?;
132        let mut unknown_tagged_fields = BTreeMap::new();
133        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
134        for _ in 0..num_tagged_fields {
135            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
136            let size: u32 = types::UnsignedVarInt.decode(buf)?;
137            let unknown_value = buf.try_get_bytes(size as usize)?;
138            unknown_tagged_fields.insert(tag as i32, unknown_value);
139        }
140        Ok(Self {
141            cluster_id,
142            voter_id,
143            voter_directory_id,
144            unknown_tagged_fields,
145        })
146    }
147}
148
149impl Default for RemoveRaftVoterRequest {
150    fn default() -> Self {
151        Self {
152            cluster_id: Some(Default::default()),
153            voter_id: 0,
154            voter_directory_id: Uuid::nil(),
155            unknown_tagged_fields: BTreeMap::new(),
156        }
157    }
158}
159
160impl Message for RemoveRaftVoterRequest {
161    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
162    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165impl HeaderVersion for RemoveRaftVoterRequest {
166    fn header_version(version: i16) -> i16 {
167        2
168    }
169}