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