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