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