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