crabka_protocol/opt/rustwide/workdir/generated/
VoteRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i32, get_i64, put_bool, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 52;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct VoteRequest {
25 pub cluster_id: Option<String>,
26 pub voter_id: i32,
27 pub topics: Vec<TopicData>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Default for VoteRequest {
32 fn default() -> Self {
33 Self {
34 cluster_id: None,
35 voter_id: -1i32,
36 topics: Vec::new(),
37 unknown_tagged_fields: Default::default(),
38 }
39 }
40}
41
42impl Encode for VoteRequest {
43 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
44 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
46 }
47 let flex = is_flexible(version);
48 if version >= 0 { if flex { put_compact_nullable_string(buf, self.cluster_id.as_deref()) } else { put_nullable_string(buf, self.cluster_id.as_deref()) } }
49 if version >= 1 { put_i32(buf, self.voter_id) }
50 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
51 if flex {
52 let tagged = WriteTaggedFields::new();
53 tagged.write(buf, &self.unknown_tagged_fields);
54 }
55 Ok(())
56 }
57 fn encoded_len(&self, version: i16) -> usize {
58 let flex = is_flexible(version);
59 let mut n: usize = 0;
60 if version >= 0 { n += if flex { compact_nullable_string_len(self.cluster_id.as_deref()) } else { nullable_string_len(self.cluster_id.as_deref()) }; }
61 if version >= 1 { n += 4; }
62 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
63 if flex {
64 let known_pairs: Vec<(u32, usize)> = Vec::new();
65 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
66 }
67 n
68 }
69}
70
71impl<'de> Decode<'de> for VoteRequest {
72 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
73 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
74 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
75 }
76 let flex = is_flexible(version);
77 let mut out = Self::default();
78 if version >= 0 { out.cluster_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
79 if version >= 1 { out.voter_id = get_i32(buf)?; }
80 if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicData::decode(buf, version)?); } v }; }
81 if flex {
82 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
83 Ok(false)
84 })?;
85 }
86 Ok(out)
87 }
88}
89
90#[derive(Debug, Clone, PartialEq, Eq, Default)]
91pub struct TopicData {
92 pub topic_name: String,
93 pub partitions: Vec<PartitionData>,
94 pub unknown_tagged_fields: UnknownTaggedFields,
95}
96
97impl Encode for TopicData {
98 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
99 let flex = version >= 0;
100 if version >= 0 { if flex { put_compact_string(buf, &self.topic_name) } else { put_string(buf, &self.topic_name) } }
101 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
102 if flex {
103 let tagged = WriteTaggedFields::new();
104 tagged.write(buf, &self.unknown_tagged_fields);
105 }
106 Ok(())
107 }
108 fn encoded_len(&self, version: i16) -> usize {
109 let flex = version >= 0;
110 let mut n: usize = 0;
111 if version >= 0 { n += if flex { compact_string_len(&self.topic_name) } else { string_len(&self.topic_name) }; }
112 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
113 if flex {
114 let known_pairs: Vec<(u32, usize)> = Vec::new();
115 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
116 }
117 n
118 }
119}
120
121impl<'de> Decode<'de> for TopicData {
122 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
123 let flex = version >= 0;
124 let mut out = Self::default();
125 if version >= 0 { out.topic_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
126 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionData::decode(buf, version)?); } v }; }
127 if flex {
128 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
129 Ok(false)
130 })?;
131 }
132 Ok(out)
133 }
134}
135
136#[derive(Debug, Clone, PartialEq, Eq, Default)]
137pub struct PartitionData {
138 pub partition_index: i32,
139 pub replica_epoch: i32,
140 pub replica_id: i32,
141 pub replica_directory_id: crate::primitives::uuid::Uuid,
142 pub voter_directory_id: crate::primitives::uuid::Uuid,
143 pub last_offset_epoch: i32,
144 pub last_offset: i64,
145 pub pre_vote: bool,
146 pub unknown_tagged_fields: UnknownTaggedFields,
147}
148
149impl Encode for PartitionData {
150 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
151 let flex = version >= 0;
152 if version >= 0 { put_i32(buf, self.partition_index) }
153 if version >= 0 { put_i32(buf, self.replica_epoch) }
154 if version >= 0 { put_i32(buf, self.replica_id) }
155 if version >= 1 { crate::primitives::uuid::put_uuid(buf, self.replica_directory_id) }
156 if version >= 1 { crate::primitives::uuid::put_uuid(buf, self.voter_directory_id) }
157 if version >= 0 { put_i32(buf, self.last_offset_epoch) }
158 if version >= 0 { put_i64(buf, self.last_offset) }
159 if version >= 2 { put_bool(buf, self.pre_vote) }
160 if flex {
161 let tagged = WriteTaggedFields::new();
162 tagged.write(buf, &self.unknown_tagged_fields);
163 }
164 Ok(())
165 }
166 fn encoded_len(&self, version: i16) -> usize {
167 let flex = version >= 0;
168 let mut n: usize = 0;
169 if version >= 0 { n += 4; }
170 if version >= 0 { n += 4; }
171 if version >= 0 { n += 4; }
172 if version >= 1 { n += 16; }
173 if version >= 1 { n += 16; }
174 if version >= 0 { n += 4; }
175 if version >= 0 { n += 8; }
176 if version >= 2 { n += 1; }
177 if flex {
178 let known_pairs: Vec<(u32, usize)> = Vec::new();
179 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180 }
181 n
182 }
183}
184
185impl<'de> Decode<'de> for PartitionData {
186 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
187 let flex = version >= 0;
188 let mut out = Self::default();
189 if version >= 0 { out.partition_index = get_i32(buf)?; }
190 if version >= 0 { out.replica_epoch = get_i32(buf)?; }
191 if version >= 0 { out.replica_id = get_i32(buf)?; }
192 if version >= 1 { out.replica_directory_id = crate::primitives::uuid::get_uuid(buf)?; }
193 if version >= 1 { out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?; }
194 if version >= 0 { out.last_offset_epoch = get_i32(buf)?; }
195 if version >= 0 { out.last_offset = get_i64(buf)?; }
196 if version >= 2 { out.pre_vote = get_bool(buf)?; }
197 if flex {
198 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
199 Ok(false)
200 })?;
201 }
202 Ok(out)
203 }
204}
205
206#[must_use]
209#[allow(unused_comparisons)]
210pub fn default_json(version: i16) -> ::serde_json::Value {
211 let mut obj = ::serde_json::Map::new();
212 obj.insert("clusterId".to_string(), ::serde_json::Value::Null);
213 if version >= 1 {
214 obj.insert("voterId".to_string(), ::serde_json::json!(-1));
215 }
216 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
217 ::serde_json::Value::Object(obj)
218}
219
220impl crate::ProtocolRequest for VoteRequest {
221 const API_KEY: i16 = API_KEY;
222 const MIN_VERSION: i16 = MIN_VERSION;
223 const MAX_VERSION: i16 = MAX_VERSION;
224 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
225 type Response = super::vote_response::VoteResponse;
226}