crabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, get_i64, put_i32, put_i64};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, 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)]
20pub struct AssignReplicasToDirsRequest {
21 pub broker_id: i32,
22 pub broker_epoch: i64,
23 pub directories: Vec<DirectoryData>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for AssignReplicasToDirsRequest {
27 fn default() -> Self {
28 Self {
29 broker_id: 0i32,
30 broker_epoch: -1i64,
31 directories: Vec::new(),
32 unknown_tagged_fields: Default::default(),
33 }
34 }
35}
36impl Encode for AssignReplicasToDirsRequest {
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.broker_id);
47 }
48 if version >= 0 {
49 put_i64(buf, self.broker_epoch);
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 += 8;
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 Decode<'_> for AssignReplicasToDirsRequest {
93 fn decode<B: Buf>(buf: &mut B, 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.broker_id = get_i32(buf)?;
104 }
105 if version >= 0 {
106 out.broker_epoch = get_i64(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(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 AssignReplicasToDirsRequest {
126 #[must_use]
127 pub fn populated(version: i16) -> Self {
128 let mut m = Self::default();
129 if version >= 0 {
130 m.broker_id = 1i32;
131 }
132 if version >= 0 {
133 m.broker_epoch = 1i64;
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 Encode for DirectoryData {
148 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
149 let flex = version >= 0;
150 if version >= 0 {
151 crate::primitives::uuid::put_uuid(buf, self.id);
152 }
153 if version >= 0 {
154 {
155 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
156 for it in &self.topics {
157 it.encode(buf, version)?;
158 }
159 }
160 }
161 if flex {
162 let tagged = WriteTaggedFields::new();
163 tagged.write(buf, &self.unknown_tagged_fields);
164 }
165 Ok(())
166 }
167 fn encoded_len(&self, version: i16) -> usize {
168 let flex = version >= 0;
169 let mut n: usize = 0;
170 if version >= 0 {
171 n += 16;
172 }
173 if version >= 0 {
174 n += {
175 let prefix =
176 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
177 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
178 prefix + body
179 };
180 }
181 if flex {
182 let known_pairs: Vec<(u32, usize)> = Vec::new();
183 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
184 }
185 n
186 }
187}
188impl Decode<'_> for DirectoryData {
189 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
190 let flex = version >= 0;
191 let mut out = Self::default();
192 if version >= 0 {
193 out.id = crate::primitives::uuid::get_uuid(buf)?;
194 }
195 if version >= 0 {
196 out.topics = {
197 let n = crate::primitives::array::get_array_len(buf, flex)?;
198 let mut v = Vec::with_capacity(n);
199 for _ in 0..n {
200 v.push(TopicData::decode(buf, version)?);
201 }
202 v
203 };
204 }
205 if flex {
206 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
207 }
208 Ok(out)
209 }
210}
211#[cfg(test)]
212impl DirectoryData {
213 #[must_use]
214 pub fn populated(version: i16) -> Self {
215 let mut m = Self::default();
216 if version >= 0 {
217 m.id = crate::primitives::uuid::Uuid([1u8; 16]);
218 }
219 if version >= 0 {
220 m.topics = vec![TopicData::populated(version)];
221 }
222 m
223 }
224}
225#[derive(Debug, Clone, PartialEq, Eq, Default)]
226pub struct TopicData {
227 pub topic_id: crate::primitives::uuid::Uuid,
228 pub partitions: Vec<PartitionData>,
229 pub unknown_tagged_fields: UnknownTaggedFields,
230}
231impl Encode for TopicData {
232 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
233 let flex = version >= 0;
234 if version >= 0 {
235 crate::primitives::uuid::put_uuid(buf, self.topic_id);
236 }
237 if version >= 0 {
238 {
239 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
240 for it in &self.partitions {
241 it.encode(buf, version)?;
242 }
243 }
244 }
245 if flex {
246 let tagged = WriteTaggedFields::new();
247 tagged.write(buf, &self.unknown_tagged_fields);
248 }
249 Ok(())
250 }
251 fn encoded_len(&self, version: i16) -> usize {
252 let flex = version >= 0;
253 let mut n: usize = 0;
254 if version >= 0 {
255 n += 16;
256 }
257 if version >= 0 {
258 n += {
259 let prefix =
260 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
261 let body: usize = (self.partitions)
262 .iter()
263 .map(|it| it.encoded_len(version))
264 .sum();
265 prefix + body
266 };
267 }
268 if flex {
269 let known_pairs: Vec<(u32, usize)> = Vec::new();
270 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
271 }
272 n
273 }
274}
275impl Decode<'_> for TopicData {
276 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
277 let flex = version >= 0;
278 let mut out = Self::default();
279 if version >= 0 {
280 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
281 }
282 if version >= 0 {
283 out.partitions = {
284 let n = crate::primitives::array::get_array_len(buf, flex)?;
285 let mut v = Vec::with_capacity(n);
286 for _ in 0..n {
287 v.push(PartitionData::decode(buf, version)?);
288 }
289 v
290 };
291 }
292 if flex {
293 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
294 }
295 Ok(out)
296 }
297}
298#[cfg(test)]
299impl TopicData {
300 #[must_use]
301 pub fn populated(version: i16) -> Self {
302 let mut m = Self::default();
303 if version >= 0 {
304 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
305 }
306 if version >= 0 {
307 m.partitions = vec![PartitionData::populated(version)];
308 }
309 m
310 }
311}
312#[derive(Debug, Clone, PartialEq, Eq, Default)]
313pub struct PartitionData {
314 pub partition_index: i32,
315 pub unknown_tagged_fields: UnknownTaggedFields,
316}
317impl Encode for PartitionData {
318 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
319 let flex = version >= 0;
320 if version >= 0 {
321 put_i32(buf, self.partition_index);
322 }
323 if flex {
324 let tagged = WriteTaggedFields::new();
325 tagged.write(buf, &self.unknown_tagged_fields);
326 }
327 Ok(())
328 }
329 fn encoded_len(&self, version: i16) -> usize {
330 let flex = version >= 0;
331 let mut n: usize = 0;
332 if version >= 0 {
333 n += 4;
334 }
335 if flex {
336 let known_pairs: Vec<(u32, usize)> = Vec::new();
337 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
338 }
339 n
340 }
341}
342impl Decode<'_> for PartitionData {
343 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
344 let flex = version >= 0;
345 let mut out = Self::default();
346 if version >= 0 {
347 out.partition_index = get_i32(buf)?;
348 }
349 if flex {
350 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
351 }
352 Ok(out)
353 }
354}
355#[cfg(test)]
356impl PartitionData {
357 #[must_use]
358 pub fn populated(version: i16) -> Self {
359 let mut m = Self::default();
360 if version >= 0 {
361 m.partition_index = 1i32;
362 }
363 m
364 }
365}
366
367#[must_use]
370#[allow(unused_comparisons)]
371pub fn default_json(version: i16) -> ::serde_json::Value {
372 let mut obj = ::serde_json::Map::new();
373 obj.insert("brokerId".to_string(), ::serde_json::json!(0));
374 obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
375 obj.insert(
376 "directories".to_string(),
377 ::serde_json::Value::Array(vec![]),
378 );
379 ::serde_json::Value::Object(obj)
380}
381
382impl crate::ProtocolRequest for AssignReplicasToDirsRequest {
383 const API_KEY: i16 = API_KEY;
384 const MIN_VERSION: i16 = MIN_VERSION;
385 const MAX_VERSION: i16 = MAX_VERSION;
386 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
387 type Response = super::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse;
388}