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