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