krabka_protocol/opt/rustwide/workdir/generated/
IncrementalAlterConfigsRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_bool, get_i8, put_bool, put_i8},
8 string_bytes::{
9 compact_nullable_string_len, compact_string_len, nullable_string_len,
10 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11 string_len,
12 },
13 string_bytes_borrowed::{
14 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15 get_nullable_string_borrowed, get_string_borrowed,
16 },
17 },
18 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 44;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 1;
23pub const LATEST_STABLE_VERSION: i16 = 1;
24pub const FLEXIBLE_MIN: i16 = 1;
25#[inline]
26#[must_use]
27pub fn is_flexible(version: i16) -> bool {
28 version >= FLEXIBLE_MIN
29}
30#[derive(Debug, Clone, PartialEq, Eq, Default)]
31pub struct IncrementalAlterConfigsRequest<'a> {
32 pub resources: Vec<AlterConfigsResource<'a>>,
33 pub validate_only: bool,
34 pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl IncrementalAlterConfigsRequest<'_> {
37 #[must_use]
41 pub fn to_owned(
42 &self,
43 ) -> crate::owned::incremental_alter_configs_request::IncrementalAlterConfigsRequest {
44 crate::owned::incremental_alter_configs_request::IncrementalAlterConfigsRequest {
45 resources: (self.resources)
46 .iter()
47 .map(AlterConfigsResource::to_owned)
48 .collect(),
49 validate_only: (self.validate_only),
50 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
51 }
52 }
53}
54impl Encode for IncrementalAlterConfigsRequest<'_> {
55 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
56 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
57 return Err(ProtocolError::UnsupportedVersion {
58 api_key: API_KEY,
59 version,
60 });
61 }
62 let flex = is_flexible(version);
63 if version >= 0 {
64 {
65 crate::primitives::array::put_array_len(buf, (self.resources).len(), flex);
66 for it in &self.resources {
67 it.encode(buf, version)?;
68 }
69 };
70 }
71 if version >= 0 {
72 put_bool(buf, self.validate_only);
73 }
74 if flex {
75 let tagged = WriteTaggedFields::new();
76 tagged.write(buf, &self.unknown_tagged_fields);
77 }
78 Ok(())
79 }
80 fn encoded_len(&self, version: i16) -> usize {
81 let flex = is_flexible(version);
82 let mut n: usize = 0;
83 if version >= 0 {
84 n += {
85 let prefix =
86 crate::primitives::array::array_len_prefix_len((self.resources).len(), flex);
87 let body: usize = (self.resources)
88 .iter()
89 .map(|it| it.encoded_len(version))
90 .sum();
91 prefix + body
92 };
93 }
94 if version >= 0 {
95 n += 1;
96 }
97 if flex {
98 let known_pairs: Vec<(u32, usize)> = Vec::new();
99 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
100 }
101 n
102 }
103}
104impl<'de> DecodeBorrow<'de> for IncrementalAlterConfigsRequest<'de> {
105 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
106 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
107 return Err(ProtocolError::UnsupportedVersion {
108 api_key: API_KEY,
109 version,
110 });
111 }
112 let flex = is_flexible(version);
113 let mut out = Self::default();
114 if version >= 0 {
115 out.resources = {
116 let n = crate::primitives::array::get_array_len(buf, flex)?;
117 let mut v = Vec::with_capacity(n);
118 for _ in 0..n {
119 v.push(AlterConfigsResource::decode_borrow(buf, version)?);
120 }
121 v
122 };
123 }
124 if version >= 0 {
125 out.validate_only = get_bool(buf)?;
126 }
127 if flex {
128 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
129 }
130 Ok(out)
131 }
132}
133#[cfg(test)]
134impl IncrementalAlterConfigsRequest<'_> {
135 #[must_use]
136 pub fn populated(version: i16) -> Self {
137 let mut m = Self::default();
138 if version >= 0 {
139 m.resources = vec![AlterConfigsResource::populated(version)];
140 }
141 if version >= 0 {
142 m.validate_only = true;
143 }
144 m
145 }
146}
147#[derive(Debug, Clone, PartialEq, Eq, Default)]
148pub struct AlterConfigsResource<'a> {
149 pub resource_type: i8,
150 pub resource_name: &'a str,
151 pub configs: Vec<AlterableConfig<'a>>,
152 pub unknown_tagged_fields: UnknownTaggedFields,
153}
154impl AlterConfigsResource<'_> {
155 #[must_use]
159 pub fn to_owned(
160 &self,
161 ) -> crate::owned::incremental_alter_configs_request::AlterConfigsResource {
162 crate::owned::incremental_alter_configs_request::AlterConfigsResource {
163 resource_type: (self.resource_type),
164 resource_name: (self.resource_name).to_string(),
165 configs: (self.configs)
166 .iter()
167 .map(AlterableConfig::to_owned)
168 .collect(),
169 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
170 }
171 }
172}
173impl Encode for AlterConfigsResource<'_> {
174 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
175 let flex = version >= 1;
176 if version >= 0 {
177 put_i8(buf, self.resource_type);
178 }
179 if version >= 0 {
180 if flex {
181 let () = put_compact_string(buf, self.resource_name);
182 } else {
183 let () = put_string(buf, self.resource_name);
184 }
185 }
186 if version >= 0 {
187 {
188 crate::primitives::array::put_array_len(buf, (self.configs).len(), flex);
189 for it in &self.configs {
190 it.encode(buf, version)?;
191 }
192 };
193 }
194 if flex {
195 let tagged = WriteTaggedFields::new();
196 tagged.write(buf, &self.unknown_tagged_fields);
197 }
198 Ok(())
199 }
200 fn encoded_len(&self, version: i16) -> usize {
201 let flex = version >= 1;
202 let mut n: usize = 0;
203 if version >= 0 {
204 n += 1;
205 }
206 if version >= 0 {
207 n += if flex {
208 compact_string_len(self.resource_name)
209 } else {
210 string_len(self.resource_name)
211 };
212 }
213 if version >= 0 {
214 n += {
215 let prefix =
216 crate::primitives::array::array_len_prefix_len((self.configs).len(), flex);
217 let body: usize = (self.configs)
218 .iter()
219 .map(|it| it.encoded_len(version))
220 .sum();
221 prefix + body
222 };
223 }
224 if flex {
225 let known_pairs: Vec<(u32, usize)> = Vec::new();
226 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
227 }
228 n
229 }
230}
231impl<'de> DecodeBorrow<'de> for AlterConfigsResource<'de> {
232 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
233 let flex = version >= 1;
234 let mut out = Self::default();
235 if version >= 0 {
236 out.resource_type = get_i8(buf)?;
237 }
238 if version >= 0 {
239 out.resource_name = if flex {
240 get_compact_string_borrowed(buf)?
241 } else {
242 get_string_borrowed(buf)?
243 };
244 }
245 if version >= 0 {
246 out.configs = {
247 let n = crate::primitives::array::get_array_len(buf, flex)?;
248 let mut v = Vec::with_capacity(n);
249 for _ in 0..n {
250 v.push(AlterableConfig::decode_borrow(buf, version)?);
251 }
252 v
253 };
254 }
255 if flex {
256 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
257 }
258 Ok(out)
259 }
260}
261#[cfg(test)]
262impl AlterConfigsResource<'_> {
263 #[must_use]
264 pub fn populated(version: i16) -> Self {
265 let mut m = Self::default();
266 if version >= 0 {
267 m.resource_type = 1i8;
268 }
269 if version >= 0 {
270 m.resource_name = "x";
271 }
272 if version >= 0 {
273 m.configs = vec![AlterableConfig::populated(version)];
274 }
275 m
276 }
277}
278#[derive(Debug, Clone, PartialEq, Eq)]
279pub struct AlterableConfig<'a> {
280 pub name: &'a str,
281 pub config_operation: i8,
282 pub value: Option<&'a str>,
283 pub unknown_tagged_fields: UnknownTaggedFields,
284}
285impl Default for AlterableConfig<'_> {
286 fn default() -> Self {
287 Self {
288 name: "",
289 config_operation: 0i8,
290 value: Some(""),
291 unknown_tagged_fields: UnknownTaggedFields::default(),
292 }
293 }
294}
295impl AlterableConfig<'_> {
296 #[must_use]
300 pub fn to_owned(&self) -> crate::owned::incremental_alter_configs_request::AlterableConfig {
301 crate::owned::incremental_alter_configs_request::AlterableConfig {
302 name: (self.name).to_string(),
303 config_operation: (self.config_operation),
304 value: (self.value).map(std::string::ToString::to_string),
305 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
306 }
307 }
308}
309impl Encode for AlterableConfig<'_> {
310 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
311 let flex = version >= 1;
312 if version >= 0 {
313 if flex {
314 let () = put_compact_string(buf, self.name);
315 } else {
316 let () = put_string(buf, self.name);
317 }
318 }
319 if version >= 0 {
320 put_i8(buf, self.config_operation);
321 }
322 if version >= 0 {
323 if flex {
324 let () = put_compact_nullable_string(buf, self.value);
325 } else {
326 let () = put_nullable_string(buf, self.value);
327 }
328 }
329 if flex {
330 let tagged = WriteTaggedFields::new();
331 tagged.write(buf, &self.unknown_tagged_fields);
332 }
333 Ok(())
334 }
335 fn encoded_len(&self, version: i16) -> usize {
336 let flex = version >= 1;
337 let mut n: usize = 0;
338 if version >= 0 {
339 n += if flex {
340 compact_string_len(self.name)
341 } else {
342 string_len(self.name)
343 };
344 }
345 if version >= 0 {
346 n += 1;
347 }
348 if version >= 0 {
349 n += if flex {
350 compact_nullable_string_len(self.value)
351 } else {
352 nullable_string_len(self.value)
353 };
354 }
355 if flex {
356 let known_pairs: Vec<(u32, usize)> = Vec::new();
357 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
358 }
359 n
360 }
361}
362impl<'de> DecodeBorrow<'de> for AlterableConfig<'de> {
363 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
364 let flex = version >= 1;
365 let mut out = Self::default();
366 if version >= 0 {
367 out.name = if flex {
368 get_compact_string_borrowed(buf)?
369 } else {
370 get_string_borrowed(buf)?
371 };
372 }
373 if version >= 0 {
374 out.config_operation = get_i8(buf)?;
375 }
376 if version >= 0 {
377 out.value = if flex {
378 get_compact_nullable_string_borrowed(buf)?
379 } else {
380 get_nullable_string_borrowed(buf)?
381 };
382 }
383 if flex {
384 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
385 }
386 Ok(out)
387 }
388}
389#[cfg(test)]
390impl AlterableConfig<'_> {
391 #[must_use]
392 pub fn populated(version: i16) -> Self {
393 let mut m = Self::default();
394 if version >= 0 {
395 m.name = "x";
396 }
397 if version >= 0 {
398 m.config_operation = 1i8;
399 }
400 if version >= 0 {
401 m.value = Some("x");
402 }
403 m
404 }
405}