kacrab_protocol/generated/
alter_partition_request.rs1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct AlterPartitionRequestData {
17 pub broker_id: i32,
19 pub broker_epoch: i64,
21 pub topics: Vec<TopicData>,
23 pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for AlterPartitionRequestData {
26 fn default() -> Self {
27 Self {
28 broker_id: 0_i32,
29 broker_epoch: -1i64,
30 topics: Vec::new(),
31 _unknown_tagged_fields: Vec::new(),
32 }
33 }
34}
35impl AlterPartitionRequestData {
36 pub fn with_broker_id(mut self, value: i32) -> Self {
37 self.broker_id = value;
38 self
39 }
40 pub fn with_broker_epoch(mut self, value: i64) -> Self {
41 self.broker_epoch = value;
42 self
43 }
44 pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
45 self.topics = value;
46 self
47 }
48 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49 if version < 2 || version > 3 {
50 return Err(UnsupportedVersion::new(56, version).into());
51 }
52 let broker_id;
53 let broker_epoch;
54 let topics;
55 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56 broker_id = read_i32(buf)?;
57 broker_epoch = read_i64(buf)?;
58 topics = {
59 let len = read_compact_array_length(buf)?;
60 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
61 for _ in 0..len {
62 arr.push(TopicData::read(buf, version)?);
63 }
64 arr
65 };
66 let tagged_fields = read_tagged_fields(buf)?;
67 for field in &tagged_fields {
68 match field.tag {
69 _ => {
70 _unknown_tagged_fields.push(field.clone());
71 },
72 }
73 }
74 Ok(Self {
75 broker_id,
76 broker_epoch,
77 topics,
78 _unknown_tagged_fields,
79 })
80 }
81 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
82 if version < 2 || version > 3 {
83 return Err(UnsupportedVersion::new(56, version).into());
84 }
85 write_i32(buf, self.broker_id);
86 write_i64(buf, self.broker_epoch);
87 write_compact_array_length(buf, self.topics.len() as i32);
88 for el in &self.topics {
89 el.write(buf, version)?;
90 }
91 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
92 all_tags.sort_by_key(|f| f.tag);
93 write_tagged_fields(buf, &all_tags)?;
94 Ok(())
95 }
96 pub fn encoded_len(&self, version: i16) -> Result<usize> {
97 if version < 2 || version > 3 {
98 return Err(UnsupportedVersion::new(56, version).into());
99 }
100 let mut len: usize = 0;
101 len += 4;
102 len += 8;
103 len += compact_array_length_len(self.topics.len() as i32);
104 for el in &self.topics {
105 len += el.encoded_len(version)?;
106 }
107 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
108 all_tags.sort_by_key(|f| f.tag);
109 len += tagged_fields_len(&all_tags)?;
110 Ok(len)
111 }
112}
113#[derive(Debug, Clone, PartialEq)]
114pub struct TopicData {
115 pub topic_id: KafkaUuid,
117 pub partitions: Vec<PartitionData>,
119 pub _unknown_tagged_fields: Vec<RawTaggedField>,
120}
121impl Default for TopicData {
122 fn default() -> Self {
123 Self {
124 topic_id: KafkaUuid::ZERO,
125 partitions: Vec::new(),
126 _unknown_tagged_fields: Vec::new(),
127 }
128 }
129}
130impl TopicData {
131 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
132 self.topic_id = value;
133 self
134 }
135 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
136 self.partitions = value;
137 self
138 }
139 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
140 let topic_id;
141 let partitions;
142 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
143 topic_id = read_uuid(buf)?;
144 partitions = {
145 let len = read_compact_array_length(buf)?;
146 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
147 for _ in 0..len {
148 arr.push(PartitionData::read(buf, version)?);
149 }
150 arr
151 };
152 let tagged_fields = read_tagged_fields(buf)?;
153 for field in &tagged_fields {
154 match field.tag {
155 _ => {
156 _unknown_tagged_fields.push(field.clone());
157 },
158 }
159 }
160 Ok(Self {
161 topic_id,
162 partitions,
163 _unknown_tagged_fields,
164 })
165 }
166 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
167 write_uuid(buf, &self.topic_id);
168 write_compact_array_length(buf, self.partitions.len() as i32);
169 for el in &self.partitions {
170 el.write(buf, version)?;
171 }
172 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
173 all_tags.sort_by_key(|f| f.tag);
174 write_tagged_fields(buf, &all_tags)?;
175 Ok(())
176 }
177 pub fn encoded_len(&self, version: i16) -> Result<usize> {
178 let mut len: usize = 0;
179 len += 16;
180 len += compact_array_length_len(self.partitions.len() as i32);
181 for el in &self.partitions {
182 len += el.encoded_len(version)?;
183 }
184 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
185 all_tags.sort_by_key(|f| f.tag);
186 len += tagged_fields_len(&all_tags)?;
187 Ok(len)
188 }
189}
190#[derive(Debug, Clone, PartialEq)]
191pub struct PartitionData {
192 pub partition_index: i32,
194 pub leader_epoch: i32,
196 pub new_isr: Vec<i32>,
198 pub new_isr_with_epochs: Vec<BrokerState>,
200 pub leader_recovery_state: i8,
202 pub partition_epoch: i32,
204 pub _unknown_tagged_fields: Vec<RawTaggedField>,
205}
206impl Default for PartitionData {
207 fn default() -> Self {
208 Self {
209 partition_index: 0_i32,
210 leader_epoch: 0_i32,
211 new_isr: Vec::new(),
212 new_isr_with_epochs: Vec::new(),
213 leader_recovery_state: 0i8,
214 partition_epoch: 0_i32,
215 _unknown_tagged_fields: Vec::new(),
216 }
217 }
218}
219impl PartitionData {
220 pub fn with_partition_index(mut self, value: i32) -> Self {
221 self.partition_index = value;
222 self
223 }
224 pub fn with_leader_epoch(mut self, value: i32) -> Self {
225 self.leader_epoch = value;
226 self
227 }
228 pub fn with_new_isr(mut self, value: Vec<i32>) -> Self {
229 self.new_isr = value;
230 self
231 }
232 pub fn with_new_isr_with_epochs(mut self, value: Vec<BrokerState>) -> Self {
233 self.new_isr_with_epochs = value;
234 self
235 }
236 pub fn with_leader_recovery_state(mut self, value: i8) -> Self {
237 self.leader_recovery_state = value;
238 self
239 }
240 pub fn with_partition_epoch(mut self, value: i32) -> Self {
241 self.partition_epoch = value;
242 self
243 }
244 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
245 let partition_index;
246 let leader_epoch;
247 let mut new_isr = Vec::new();
248 let mut new_isr_with_epochs = Vec::new();
249 let leader_recovery_state;
250 let partition_epoch;
251 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
252 partition_index = read_i32(buf)?;
253 leader_epoch = read_i32(buf)?;
254 if version <= 2 {
255 new_isr = {
256 let len = read_compact_array_length(buf)?;
257 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
258 for _ in 0..len {
259 arr.push(read_i32(buf)?);
260 }
261 arr
262 };
263 }
264 if version >= 3 {
265 new_isr_with_epochs = {
266 let len = read_compact_array_length(buf)?;
267 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
268 for _ in 0..len {
269 arr.push(BrokerState::read(buf, version)?);
270 }
271 arr
272 };
273 }
274 leader_recovery_state = read_i8(buf)?;
275 partition_epoch = read_i32(buf)?;
276 let tagged_fields = read_tagged_fields(buf)?;
277 for field in &tagged_fields {
278 match field.tag {
279 _ => {
280 _unknown_tagged_fields.push(field.clone());
281 },
282 }
283 }
284 Ok(Self {
285 partition_index,
286 leader_epoch,
287 new_isr,
288 new_isr_with_epochs,
289 leader_recovery_state,
290 partition_epoch,
291 _unknown_tagged_fields,
292 })
293 }
294 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
295 write_i32(buf, self.partition_index);
296 write_i32(buf, self.leader_epoch);
297 if version <= 2 {
298 write_compact_array_length(buf, self.new_isr.len() as i32);
299 for el in &self.new_isr {
300 write_i32(buf, *el);
301 }
302 } else if self.new_isr != Vec::new() {
303 return Err(UnsupportedFieldVersion::new(56, "new_isr", version).into());
304 }
305 if version >= 3 {
306 write_compact_array_length(buf, self.new_isr_with_epochs.len() as i32);
307 for el in &self.new_isr_with_epochs {
308 el.write(buf, version)?;
309 }
310 } else if self.new_isr_with_epochs != Vec::new() {
311 return Err(UnsupportedFieldVersion::new(56, "new_isr_with_epochs", version).into());
312 }
313 write_i8(buf, self.leader_recovery_state);
314 write_i32(buf, self.partition_epoch);
315 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
316 all_tags.sort_by_key(|f| f.tag);
317 write_tagged_fields(buf, &all_tags)?;
318 Ok(())
319 }
320 pub fn encoded_len(&self, version: i16) -> Result<usize> {
321 let mut len: usize = 0;
322 len += 4;
323 len += 4;
324 if version <= 2 {
325 len += compact_array_length_len(self.new_isr.len() as i32);
326 len += self.new_isr.len() * 4usize;
327 } else if self.new_isr != Vec::new() {
328 return Err(UnsupportedFieldVersion::new(56, "new_isr", version).into());
329 }
330 if version >= 3 {
331 len += compact_array_length_len(self.new_isr_with_epochs.len() as i32);
332 for el in &self.new_isr_with_epochs {
333 len += el.encoded_len(version)?;
334 }
335 } else if self.new_isr_with_epochs != Vec::new() {
336 return Err(UnsupportedFieldVersion::new(56, "new_isr_with_epochs", version).into());
337 }
338 len += 1;
339 len += 4;
340 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
341 all_tags.sort_by_key(|f| f.tag);
342 len += tagged_fields_len(&all_tags)?;
343 Ok(len)
344 }
345}
346#[derive(Debug, Clone, PartialEq)]
347pub struct BrokerState {
348 pub broker_id: i32,
350 pub broker_epoch: i64,
352 pub _unknown_tagged_fields: Vec<RawTaggedField>,
353}
354impl Default for BrokerState {
355 fn default() -> Self {
356 Self {
357 broker_id: 0_i32,
358 broker_epoch: -1i64,
359 _unknown_tagged_fields: Vec::new(),
360 }
361 }
362}
363impl BrokerState {
364 pub fn with_broker_id(mut self, value: i32) -> Self {
365 self.broker_id = value;
366 self
367 }
368 pub fn with_broker_epoch(mut self, value: i64) -> Self {
369 self.broker_epoch = value;
370 self
371 }
372 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
373 let broker_id;
374 let broker_epoch;
375 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
376 broker_id = read_i32(buf)?;
377 broker_epoch = read_i64(buf)?;
378 let tagged_fields = read_tagged_fields(buf)?;
379 for field in &tagged_fields {
380 match field.tag {
381 _ => {
382 _unknown_tagged_fields.push(field.clone());
383 },
384 }
385 }
386 Ok(Self {
387 broker_id,
388 broker_epoch,
389 _unknown_tagged_fields,
390 })
391 }
392 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
393 write_i32(buf, self.broker_id);
394 write_i64(buf, self.broker_epoch);
395 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
396 all_tags.sort_by_key(|f| f.tag);
397 write_tagged_fields(buf, &all_tags)?;
398 Ok(())
399 }
400 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
401 let mut len: usize = 0;
402 len += 4;
403 len += 8;
404 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
405 all_tags.sort_by_key(|f| f.tag);
406 len += tagged_fields_len(&all_tags)?;
407 Ok(len)
408 }
409}