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