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