crabka_protocol/opt/rustwide/workdir/generated/
AlterConfigsRequest.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 = 33;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 2;
15pub const FLEXIBLE_MIN: i16 = 2;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18 version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct AlterConfigsRequest {
22 pub resources: Vec<AlterConfigsResource>,
23 pub validate_only: bool,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for AlterConfigsRequest {
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 AlterConfigsRequest {
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 AlterConfigsRequest {
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 >= 2;
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 >= 2;
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 >= 2;
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 value: Option<String>,
235 pub unknown_tagged_fields: UnknownTaggedFields,
236}
237impl Encode for AlterableConfig {
238 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
239 let flex = version >= 2;
240 if version >= 0 {
241 if flex {
242 put_compact_string(buf, &self.name);
243 } else {
244 put_string(buf, &self.name);
245 }
246 }
247 if version >= 0 {
248 if flex {
249 put_compact_nullable_string(buf, self.value.as_deref());
250 } else {
251 put_nullable_string(buf, self.value.as_deref());
252 }
253 }
254 if flex {
255 let tagged = WriteTaggedFields::new();
256 tagged.write(buf, &self.unknown_tagged_fields);
257 }
258 Ok(())
259 }
260 fn encoded_len(&self, version: i16) -> usize {
261 let flex = version >= 2;
262 let mut n: usize = 0;
263 if version >= 0 {
264 n += if flex {
265 compact_string_len(&self.name)
266 } else {
267 string_len(&self.name)
268 };
269 }
270 if version >= 0 {
271 n += if flex {
272 compact_nullable_string_len(self.value.as_deref())
273 } else {
274 nullable_string_len(self.value.as_deref())
275 };
276 }
277 if flex {
278 let known_pairs: Vec<(u32, usize)> = Vec::new();
279 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
280 }
281 n
282 }
283}
284impl Decode<'_> for AlterableConfig {
285 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
286 let flex = version >= 2;
287 let mut out = Self::default();
288 if version >= 0 {
289 out.name = if flex {
290 get_compact_string_owned(buf)?
291 } else {
292 get_string_owned(buf)?
293 };
294 }
295 if version >= 0 {
296 out.value = if flex {
297 get_compact_nullable_string_owned(buf)?
298 } else {
299 get_nullable_string_owned(buf)?
300 };
301 }
302 if flex {
303 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
304 }
305 Ok(out)
306 }
307}
308#[cfg(test)]
309impl AlterableConfig {
310 #[must_use]
311 pub fn populated(version: i16) -> Self {
312 let mut m = Self::default();
313 if version >= 0 {
314 m.name = "x".to_string();
315 }
316 if version >= 0 {
317 m.value = Some("x".to_string());
318 }
319 m
320 }
321}
322#[must_use]
325#[allow(unused_comparisons)]
326pub fn default_json(version: i16) -> ::serde_json::Value {
327 let mut obj = ::serde_json::Map::new();
328 obj.insert("resources".to_string(), ::serde_json::Value::Array(vec![]));
329 obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
330 ::serde_json::Value::Object(obj)
331}
332impl crate::ProtocolRequest for AlterConfigsRequest {
333 const API_KEY: i16 = API_KEY;
334 const MIN_VERSION: i16 = MIN_VERSION;
335 const MAX_VERSION: i16 = MAX_VERSION;
336 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
337 type Response = super::alter_configs_response::AlterConfigsResponse;
338}