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