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