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