krabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::fixed::{get_i32, get_i64, put_i32, put_i64},
7 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
8};
9pub const API_KEY: i16 = 73;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const LATEST_STABLE_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15#[must_use]
16pub fn is_flexible(version: i16) -> bool {
17 version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct AssignReplicasToDirsRequest {
21 pub broker_id: i32,
22 pub broker_epoch: i64,
23 pub directories: Vec<DirectoryData>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for AssignReplicasToDirsRequest {
27 fn default() -> Self {
28 Self {
29 broker_id: 0i32,
30 broker_epoch: -1i64,
31 directories: Vec::new(),
32 unknown_tagged_fields: UnknownTaggedFields::default(),
33 }
34 }
35}
36impl AssignReplicasToDirsRequest {
37 #[must_use]
41 pub fn to_owned(
42 &self,
43 ) -> crate::owned::assign_replicas_to_dirs_request::AssignReplicasToDirsRequest {
44 crate::owned::assign_replicas_to_dirs_request::AssignReplicasToDirsRequest {
45 broker_id: (self.broker_id),
46 broker_epoch: (self.broker_epoch),
47 directories: (self.directories)
48 .iter()
49 .map(DirectoryData::to_owned)
50 .collect(),
51 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52 }
53 }
54}
55impl Encode for AssignReplicasToDirsRequest {
56 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
57 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58 return Err(ProtocolError::UnsupportedVersion {
59 api_key: API_KEY,
60 version,
61 });
62 }
63 let flex = is_flexible(version);
64 if version >= 0 {
65 put_i32(buf, self.broker_id);
66 }
67 if version >= 0 {
68 put_i64(buf, self.broker_epoch);
69 }
70 if version >= 0 {
71 {
72 crate::primitives::array::put_array_len(buf, (self.directories).len(), flex);
73 for it in &self.directories {
74 it.encode(buf, version)?;
75 }
76 };
77 }
78 if flex {
79 let tagged = WriteTaggedFields::new();
80 tagged.write(buf, &self.unknown_tagged_fields);
81 }
82 Ok(())
83 }
84 fn encoded_len(&self, version: i16) -> usize {
85 let flex = is_flexible(version);
86 let mut n: usize = 0;
87 if version >= 0 {
88 n += 4;
89 }
90 if version >= 0 {
91 n += 8;
92 }
93 if version >= 0 {
94 n += {
95 let prefix =
96 crate::primitives::array::array_len_prefix_len((self.directories).len(), flex);
97 let body: usize = (self.directories)
98 .iter()
99 .map(|it| it.encoded_len(version))
100 .sum();
101 prefix + body
102 };
103 }
104 if flex {
105 let known_pairs: Vec<(u32, usize)> = Vec::new();
106 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107 }
108 n
109 }
110}
111impl<'de> DecodeBorrow<'de> for AssignReplicasToDirsRequest {
112 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
113 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
114 return Err(ProtocolError::UnsupportedVersion {
115 api_key: API_KEY,
116 version,
117 });
118 }
119 let flex = is_flexible(version);
120 let mut out = Self::default();
121 if version >= 0 {
122 out.broker_id = get_i32(buf)?;
123 }
124 if version >= 0 {
125 out.broker_epoch = get_i64(buf)?;
126 }
127 if version >= 0 {
128 out.directories = {
129 let n = crate::primitives::array::get_array_len(buf, flex)?;
130 let mut v = Vec::with_capacity(n);
131 for _ in 0..n {
132 v.push(DirectoryData::decode_borrow(buf, version)?);
133 }
134 v
135 };
136 }
137 if flex {
138 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
139 }
140 Ok(out)
141 }
142}
143#[cfg(test)]
144impl AssignReplicasToDirsRequest {
145 #[must_use]
146 pub fn populated(version: i16) -> Self {
147 let mut m = Self::default();
148 if version >= 0 {
149 m.broker_id = 1i32;
150 }
151 if version >= 0 {
152 m.broker_epoch = 1i64;
153 }
154 if version >= 0 {
155 m.directories = vec![DirectoryData::populated(version)];
156 }
157 m
158 }
159}
160#[derive(Debug, Clone, PartialEq, Eq, Default)]
161pub struct DirectoryData {
162 pub id: crate::primitives::uuid::Uuid,
163 pub topics: Vec<TopicData>,
164 pub unknown_tagged_fields: UnknownTaggedFields,
165}
166impl DirectoryData {
167 #[must_use]
171 pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_request::DirectoryData {
172 crate::owned::assign_replicas_to_dirs_request::DirectoryData {
173 id: (self.id),
174 topics: (self.topics).iter().map(TopicData::to_owned).collect(),
175 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
176 }
177 }
178}
179impl Encode for DirectoryData {
180 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
181 let flex = version >= 0;
182 if version >= 0 {
183 crate::primitives::uuid::put_uuid(buf, self.id);
184 }
185 if version >= 0 {
186 {
187 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
188 for it in &self.topics {
189 it.encode(buf, version)?;
190 }
191 };
192 }
193 if flex {
194 let tagged = WriteTaggedFields::new();
195 tagged.write(buf, &self.unknown_tagged_fields);
196 }
197 Ok(())
198 }
199 fn encoded_len(&self, version: i16) -> usize {
200 let flex = version >= 0;
201 let mut n: usize = 0;
202 if version >= 0 {
203 n += 16;
204 }
205 if version >= 0 {
206 n += {
207 let prefix =
208 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
209 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
210 prefix + body
211 };
212 }
213 if flex {
214 let known_pairs: Vec<(u32, usize)> = Vec::new();
215 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
216 }
217 n
218 }
219}
220impl<'de> DecodeBorrow<'de> for DirectoryData {
221 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
222 let flex = version >= 0;
223 let mut out = Self::default();
224 if version >= 0 {
225 out.id = crate::primitives::uuid::get_uuid(buf)?;
226 }
227 if version >= 0 {
228 out.topics = {
229 let n = crate::primitives::array::get_array_len(buf, flex)?;
230 let mut v = Vec::with_capacity(n);
231 for _ in 0..n {
232 v.push(TopicData::decode_borrow(buf, version)?);
233 }
234 v
235 };
236 }
237 if flex {
238 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
239 }
240 Ok(out)
241 }
242}
243#[cfg(test)]
244impl DirectoryData {
245 #[must_use]
246 pub fn populated(version: i16) -> Self {
247 let mut m = Self::default();
248 if version >= 0 {
249 m.id = crate::primitives::uuid::Uuid([1u8; 16]);
250 }
251 if version >= 0 {
252 m.topics = vec![TopicData::populated(version)];
253 }
254 m
255 }
256}
257#[derive(Debug, Clone, PartialEq, Eq, Default)]
258pub struct TopicData {
259 pub topic_id: crate::primitives::uuid::Uuid,
260 pub partitions: Vec<PartitionData>,
261 pub unknown_tagged_fields: UnknownTaggedFields,
262}
263impl TopicData {
264 #[must_use]
268 pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_request::TopicData {
269 crate::owned::assign_replicas_to_dirs_request::TopicData {
270 topic_id: (self.topic_id),
271 partitions: (self.partitions)
272 .iter()
273 .map(PartitionData::to_owned)
274 .collect(),
275 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
276 }
277 }
278}
279impl Encode for TopicData {
280 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
281 let flex = version >= 0;
282 if version >= 0 {
283 crate::primitives::uuid::put_uuid(buf, self.topic_id);
284 }
285 if version >= 0 {
286 {
287 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
288 for it in &self.partitions {
289 it.encode(buf, version)?;
290 }
291 };
292 }
293 if flex {
294 let tagged = WriteTaggedFields::new();
295 tagged.write(buf, &self.unknown_tagged_fields);
296 }
297 Ok(())
298 }
299 fn encoded_len(&self, version: i16) -> usize {
300 let flex = version >= 0;
301 let mut n: usize = 0;
302 if version >= 0 {
303 n += 16;
304 }
305 if version >= 0 {
306 n += {
307 let prefix =
308 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
309 let body: usize = (self.partitions)
310 .iter()
311 .map(|it| it.encoded_len(version))
312 .sum();
313 prefix + body
314 };
315 }
316 if flex {
317 let known_pairs: Vec<(u32, usize)> = Vec::new();
318 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
319 }
320 n
321 }
322}
323impl<'de> DecodeBorrow<'de> for TopicData {
324 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
325 let flex = version >= 0;
326 let mut out = Self::default();
327 if version >= 0 {
328 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
329 }
330 if version >= 0 {
331 out.partitions = {
332 let n = crate::primitives::array::get_array_len(buf, flex)?;
333 let mut v = Vec::with_capacity(n);
334 for _ in 0..n {
335 v.push(PartitionData::decode_borrow(buf, version)?);
336 }
337 v
338 };
339 }
340 if flex {
341 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
342 }
343 Ok(out)
344 }
345}
346#[cfg(test)]
347impl TopicData {
348 #[must_use]
349 pub fn populated(version: i16) -> Self {
350 let mut m = Self::default();
351 if version >= 0 {
352 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
353 }
354 if version >= 0 {
355 m.partitions = vec![PartitionData::populated(version)];
356 }
357 m
358 }
359}
360#[derive(Debug, Clone, PartialEq, Eq, Default)]
361pub struct PartitionData {
362 pub partition_index: i32,
363 pub unknown_tagged_fields: UnknownTaggedFields,
364}
365impl PartitionData {
366 #[must_use]
370 pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_request::PartitionData {
371 crate::owned::assign_replicas_to_dirs_request::PartitionData {
372 partition_index: (self.partition_index),
373 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
374 }
375 }
376}
377impl Encode for PartitionData {
378 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
379 let flex = version >= 0;
380 if version >= 0 {
381 put_i32(buf, self.partition_index);
382 }
383 if flex {
384 let tagged = WriteTaggedFields::new();
385 tagged.write(buf, &self.unknown_tagged_fields);
386 }
387 Ok(())
388 }
389 fn encoded_len(&self, version: i16) -> usize {
390 let flex = version >= 0;
391 let mut n: usize = 0;
392 if version >= 0 {
393 n += 4;
394 }
395 if flex {
396 let known_pairs: Vec<(u32, usize)> = Vec::new();
397 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
398 }
399 n
400 }
401}
402impl<'de> DecodeBorrow<'de> for PartitionData {
403 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
404 let flex = version >= 0;
405 let mut out = Self::default();
406 if version >= 0 {
407 out.partition_index = get_i32(buf)?;
408 }
409 if flex {
410 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
411 }
412 Ok(out)
413 }
414}
415#[cfg(test)]
416impl PartitionData {
417 #[must_use]
418 pub fn populated(version: i16) -> Self {
419 let mut m = Self::default();
420 if version >= 0 {
421 m.partition_index = 1i32;
422 }
423 m
424 }
425}