krabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 owned::alter_replica_log_dirs_request,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i32, put_i32},
10 string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
11 string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
12 },
13 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
14};
15pub const API_KEY: i16 = 34;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 2;
18pub const LATEST_STABLE_VERSION: i16 = 2;
19pub const FLEXIBLE_MIN: i16 = 2;
20#[inline]
21#[must_use]
22pub fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct AlterReplicaLogDirsRequest<'a> {
27 pub dirs: Vec<AlterReplicaLogDir<'a>>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl AlterReplicaLogDirsRequest<'_> {
31 #[must_use]
32 pub fn to_owned(&self) -> alter_replica_log_dirs_request::AlterReplicaLogDirsRequest {
33 alter_replica_log_dirs_request::AlterReplicaLogDirsRequest {
34 dirs: (self.dirs)
35 .iter()
36 .map(AlterReplicaLogDir::to_owned)
37 .collect(),
38 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
39 }
40 }
41}
42impl Encode for AlterReplicaLogDirsRequest<'_> {
43 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
44 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45 return Err(ProtocolError::UnsupportedVersion {
46 api_key: API_KEY,
47 version,
48 });
49 }
50 let flex = is_flexible(version);
51 if version >= 0 {
52 {
53 put_array_len(buf, (self.dirs).len(), flex)?;
54 for it in &self.dirs {
55 it.encode(buf, version)?;
56 }
57 }
58 }
59 if flex {
60 let tagged = WriteTaggedFields::new();
61 tagged.write(buf, &self.unknown_tagged_fields)?;
62 }
63 Ok(())
64 }
65 fn encoded_len(&self, version: i16) -> usize {
66 let flex = is_flexible(version);
67 let mut n: usize = 0;
68 if version >= 0 {
69 n += {
70 let prefix = 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 = 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 #[must_use]
127 pub fn to_owned(&self) -> alter_replica_log_dirs_request::AlterReplicaLogDir {
128 alter_replica_log_dirs_request::AlterReplicaLogDir {
129 path: (self.path).to_owned(),
130 topics: (self.topics)
131 .iter()
132 .map(AlterReplicaLogDirTopic::to_owned)
133 .collect(),
134 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
135 }
136 }
137}
138impl Encode for AlterReplicaLogDir<'_> {
139 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
140 let flex = version >= 2;
141 if version >= 0 {
142 if flex {
143 put_compact_string(buf, self.path)?;
144 } else {
145 put_string(buf, self.path)?;
146 }
147 }
148 if version >= 0 {
149 {
150 put_array_len(buf, (self.topics).len(), flex)?;
151 for it in &self.topics {
152 it.encode(buf, version)?;
153 }
154 }
155 }
156 if flex {
157 let tagged = WriteTaggedFields::new();
158 tagged.write(buf, &self.unknown_tagged_fields)?;
159 }
160 Ok(())
161 }
162 fn encoded_len(&self, version: i16) -> usize {
163 let flex = version >= 2;
164 let mut n: usize = 0;
165 if version >= 0 {
166 n += if flex {
167 compact_string_len(self.path)
168 } else {
169 string_len(self.path)
170 };
171 }
172 if version >= 0 {
173 n += {
174 let prefix = 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 = 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 #[must_use]
235 pub fn to_owned(&self) -> alter_replica_log_dirs_request::AlterReplicaLogDirTopic {
236 alter_replica_log_dirs_request::AlterReplicaLogDirTopic {
237 name: (self.name).to_owned(),
238 partitions: (self.partitions).clone(),
239 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
240 }
241 }
242}
243impl Encode for AlterReplicaLogDirTopic<'_> {
244 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
245 let flex = version >= 2;
246 if version >= 0 {
247 if flex {
248 put_compact_string(buf, self.name)?;
249 } else {
250 put_string(buf, self.name)?;
251 }
252 }
253 if version >= 0 {
254 {
255 put_array_len(buf, (self.partitions).len(), flex)?;
256 for it in &self.partitions {
257 put_i32(buf, *it);
258 }
259 }
260 }
261 if flex {
262 let tagged = WriteTaggedFields::new();
263 tagged.write(buf, &self.unknown_tagged_fields)?;
264 }
265 Ok(())
266 }
267 fn encoded_len(&self, version: i16) -> usize {
268 let flex = version >= 2;
269 let mut n: usize = 0;
270 if version >= 0 {
271 n += if flex {
272 compact_string_len(self.name)
273 } else {
274 string_len(self.name)
275 };
276 }
277 if version >= 0 {
278 n += {
279 let prefix = array_len_prefix_len((self.partitions).len(), flex);
280 let body: usize = (self.partitions).iter().map(|_| 4).sum();
281 prefix + body
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<'de> DecodeBorrow<'de> for AlterReplicaLogDirTopic<'de> {
292 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
293 let flex = version >= 2;
294 let mut out = Self::default();
295 if version >= 0 {
296 out.name = if flex {
297 get_compact_string_borrowed(buf)?
298 } else {
299 get_string_borrowed(buf)?
300 };
301 }
302 if version >= 0 {
303 out.partitions = {
304 let n = get_array_len(buf, flex)?;
305 let mut v = Vec::with_capacity(n);
306 for _ in 0..n {
307 v.push(get_i32(buf)?);
308 }
309 v
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 AlterReplicaLogDirTopic<'_> {
320 #[must_use]
321 pub fn populated(version: i16) -> Self {
322 let mut m = Self::default();
323 if version >= 0 {
324 m.name = "x";
325 }
326 if version >= 0 {
327 m.partitions = vec![1i32];
328 }
329 m
330 }
331}