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