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