crabka_protocol/opt/rustwide/workdir/generated/
AddRaftVoterRequest.owned.rs1use crate::primitives::fixed::{get_bool, get_i32, get_u16, put_bool, put_i32, put_u16};
4use crate::primitives::string_bytes::{
5 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
6 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
7 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 80;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 1;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18 version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct AddRaftVoterRequest {
22 pub cluster_id: Option<String>,
23 pub timeout_ms: i32,
24 pub voter_id: i32,
25 pub voter_directory_id: crate::primitives::uuid::Uuid,
26 pub listeners: Vec<Listener>,
27 pub ack_when_committed: bool,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Default for AddRaftVoterRequest {
31 fn default() -> Self {
32 Self {
33 cluster_id: None,
34 timeout_ms: 0i32,
35 voter_id: 0i32,
36 voter_directory_id: Default::default(),
37 listeners: Vec::new(),
38 ack_when_committed: true,
39 unknown_tagged_fields: Default::default(),
40 }
41 }
42}
43impl Encode for AddRaftVoterRequest {
44 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46 return Err(ProtocolError::UnsupportedVersion {
47 api_key: API_KEY,
48 version,
49 });
50 }
51 let flex = is_flexible(version);
52 if version >= 0 {
53 if flex {
54 put_compact_nullable_string(buf, self.cluster_id.as_deref());
55 } else {
56 put_nullable_string(buf, self.cluster_id.as_deref());
57 }
58 }
59 if version >= 0 {
60 put_i32(buf, self.timeout_ms);
61 }
62 if version >= 0 {
63 put_i32(buf, self.voter_id);
64 }
65 if version >= 0 {
66 crate::primitives::uuid::put_uuid(buf, self.voter_directory_id);
67 }
68 if version >= 0 {
69 {
70 crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex);
71 for it in &self.listeners {
72 it.encode(buf, version)?;
73 }
74 }
75 }
76 if version >= 1 {
77 put_bool(buf, self.ack_when_committed);
78 }
79 if flex {
80 let tagged = WriteTaggedFields::new();
81 tagged.write(buf, &self.unknown_tagged_fields);
82 }
83 Ok(())
84 }
85 fn encoded_len(&self, version: i16) -> usize {
86 let flex = is_flexible(version);
87 let mut n: usize = 0;
88 if version >= 0 {
89 n += if flex {
90 compact_nullable_string_len(self.cluster_id.as_deref())
91 } else {
92 nullable_string_len(self.cluster_id.as_deref())
93 };
94 }
95 if version >= 0 {
96 n += 4;
97 }
98 if version >= 0 {
99 n += 4;
100 }
101 if version >= 0 {
102 n += 16;
103 }
104 if version >= 0 {
105 n += {
106 let prefix =
107 crate::primitives::array::array_len_prefix_len((self.listeners).len(), flex);
108 let body: usize = (self.listeners)
109 .iter()
110 .map(|it| it.encoded_len(version))
111 .sum();
112 prefix + body
113 };
114 }
115 if version >= 1 {
116 n += 1;
117 }
118 if flex {
119 let known_pairs: Vec<(u32, usize)> = Vec::new();
120 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
121 }
122 n
123 }
124}
125impl Decode<'_> for AddRaftVoterRequest {
126 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
127 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
128 return Err(ProtocolError::UnsupportedVersion {
129 api_key: API_KEY,
130 version,
131 });
132 }
133 let flex = is_flexible(version);
134 let mut out = Self::default();
135 if version >= 0 {
136 out.cluster_id = if flex {
137 get_compact_nullable_string_owned(buf)?
138 } else {
139 get_nullable_string_owned(buf)?
140 };
141 }
142 if version >= 0 {
143 out.timeout_ms = get_i32(buf)?;
144 }
145 if version >= 0 {
146 out.voter_id = get_i32(buf)?;
147 }
148 if version >= 0 {
149 out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?;
150 }
151 if version >= 0 {
152 out.listeners = {
153 let n = crate::primitives::array::get_array_len(buf, flex)?;
154 let mut v = Vec::with_capacity(n);
155 for _ in 0..n {
156 v.push(Listener::decode(buf, version)?);
157 }
158 v
159 };
160 }
161 if version >= 1 {
162 out.ack_when_committed = get_bool(buf)?;
163 }
164 if flex {
165 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
166 }
167 Ok(out)
168 }
169}
170#[cfg(test)]
171impl AddRaftVoterRequest {
172 #[must_use]
173 pub fn populated(version: i16) -> Self {
174 let mut m = Self::default();
175 if version >= 0 {
176 m.cluster_id = Some("x".to_string());
177 }
178 if version >= 0 {
179 m.timeout_ms = 1i32;
180 }
181 if version >= 0 {
182 m.voter_id = 1i32;
183 }
184 if version >= 0 {
185 m.voter_directory_id = crate::primitives::uuid::Uuid([1u8; 16]);
186 }
187 if version >= 0 {
188 m.listeners = vec![Listener::populated(version)];
189 }
190 if version >= 1 {
191 m.ack_when_committed = true;
192 }
193 m
194 }
195}
196#[derive(Debug, Clone, PartialEq, Eq, Default)]
197pub struct Listener {
198 pub name: String,
199 pub host: String,
200 pub port: u16,
201 pub unknown_tagged_fields: UnknownTaggedFields,
202}
203impl Encode for Listener {
204 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
205 let flex = version >= 0;
206 if version >= 0 {
207 if flex {
208 put_compact_string(buf, &self.name);
209 } else {
210 put_string(buf, &self.name);
211 }
212 }
213 if version >= 0 {
214 if flex {
215 put_compact_string(buf, &self.host);
216 } else {
217 put_string(buf, &self.host);
218 }
219 }
220 if version >= 0 {
221 put_u16(buf, self.port);
222 }
223 if flex {
224 let tagged = WriteTaggedFields::new();
225 tagged.write(buf, &self.unknown_tagged_fields);
226 }
227 Ok(())
228 }
229 fn encoded_len(&self, version: i16) -> usize {
230 let flex = version >= 0;
231 let mut n: usize = 0;
232 if version >= 0 {
233 n += if flex {
234 compact_string_len(&self.name)
235 } else {
236 string_len(&self.name)
237 };
238 }
239 if version >= 0 {
240 n += if flex {
241 compact_string_len(&self.host)
242 } else {
243 string_len(&self.host)
244 };
245 }
246 if version >= 0 {
247 n += 2;
248 }
249 if flex {
250 let known_pairs: Vec<(u32, usize)> = Vec::new();
251 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
252 }
253 n
254 }
255}
256impl Decode<'_> for Listener {
257 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
258 let flex = version >= 0;
259 let mut out = Self::default();
260 if version >= 0 {
261 out.name = if flex {
262 get_compact_string_owned(buf)?
263 } else {
264 get_string_owned(buf)?
265 };
266 }
267 if version >= 0 {
268 out.host = if flex {
269 get_compact_string_owned(buf)?
270 } else {
271 get_string_owned(buf)?
272 };
273 }
274 if version >= 0 {
275 out.port = get_u16(buf)?;
276 }
277 if flex {
278 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
279 }
280 Ok(out)
281 }
282}
283#[cfg(test)]
284impl Listener {
285 #[must_use]
286 pub fn populated(version: i16) -> Self {
287 let mut m = Self::default();
288 if version >= 0 {
289 m.name = "x".to_string();
290 }
291 if version >= 0 {
292 m.host = "x".to_string();
293 }
294 if version >= 0 {
295 m.port = 1u16;
296 }
297 m
298 }
299}
300#[must_use]
303#[allow(unused_comparisons)]
304pub fn default_json(version: i16) -> ::serde_json::Value {
305 let mut obj = ::serde_json::Map::new();
306 obj.insert("clusterId".to_string(), ::serde_json::Value::Null);
307 obj.insert("timeoutMs".to_string(), ::serde_json::json!(0));
308 obj.insert("voterId".to_string(), ::serde_json::json!(0));
309 obj.insert(
310 "voterDirectoryId".to_string(),
311 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
312 );
313 obj.insert("listeners".to_string(), ::serde_json::Value::Array(vec![]));
314 if version >= 1 {
315 obj.insert(
316 "ackWhenCommitted".to_string(),
317 ::serde_json::Value::Bool(true),
318 );
319 }
320 ::serde_json::Value::Object(obj)
321}
322impl crate::ProtocolRequest for AddRaftVoterRequest {
323 const API_KEY: i16 = API_KEY;
324 const MIN_VERSION: i16 = MIN_VERSION;
325 const MAX_VERSION: i16 = MAX_VERSION;
326 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
327 type Response = super::add_raft_voter_response::AddRaftVoterResponse;
328}