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