kacrab_protocol/generated/
alter_partition_response.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 AlterPartitionResponseData {
17 pub throttle_time_ms: i32,
20 pub error_code: i16,
22 pub topics: Vec<TopicData>,
24 pub _unknown_tagged_fields: Vec<RawTaggedField>,
25}
26impl Default for AlterPartitionResponseData {
27 fn default() -> Self {
28 Self {
29 throttle_time_ms: 0_i32,
30 error_code: 0_i16,
31 topics: Vec::new(),
32 _unknown_tagged_fields: Vec::new(),
33 }
34 }
35}
36impl AlterPartitionResponseData {
37 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
38 self.throttle_time_ms = value;
39 self
40 }
41 pub fn with_error_code(mut self, value: i16) -> Self {
42 self.error_code = value;
43 self
44 }
45 pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
46 self.topics = value;
47 self
48 }
49 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
50 if version < 2 || version > 3 {
51 return Err(UnsupportedVersion::new(56, version).into());
52 }
53 let throttle_time_ms;
54 let error_code;
55 let topics;
56 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
57 throttle_time_ms = read_i32(buf)?;
58 error_code = read_i16(buf)?;
59 topics = {
60 let len = read_compact_array_length(buf)?;
61 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
62 for _ in 0..len {
63 arr.push(TopicData::read(buf, version)?);
64 }
65 arr
66 };
67 let tagged_fields = read_tagged_fields(buf)?;
68 for field in &tagged_fields {
69 match field.tag {
70 _ => {
71 _unknown_tagged_fields.push(field.clone());
72 },
73 }
74 }
75 Ok(Self {
76 throttle_time_ms,
77 error_code,
78 topics,
79 _unknown_tagged_fields,
80 })
81 }
82 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
83 if version < 2 || version > 3 {
84 return Err(UnsupportedVersion::new(56, version).into());
85 }
86 write_i32(buf, self.throttle_time_ms);
87 write_i16(buf, self.error_code);
88 write_compact_array_length(buf, self.topics.len() as i32);
89 for el in &self.topics {
90 el.write(buf, version)?;
91 }
92 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
93 all_tags.sort_by_key(|f| f.tag);
94 write_tagged_fields(buf, &all_tags)?;
95 Ok(())
96 }
97 pub fn encoded_len(&self, version: i16) -> Result<usize> {
98 if version < 2 || version > 3 {
99 return Err(UnsupportedVersion::new(56, version).into());
100 }
101 let mut len: usize = 0;
102 len += 4;
103 len += 2;
104 len += compact_array_length_len(self.topics.len() as i32);
105 for el in &self.topics {
106 len += el.encoded_len(version)?;
107 }
108 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
109 all_tags.sort_by_key(|f| f.tag);
110 len += tagged_fields_len(&all_tags)?;
111 Ok(len)
112 }
113}
114#[derive(Debug, Clone, PartialEq)]
115pub struct TopicData {
116 pub topic_id: KafkaUuid,
118 pub partitions: Vec<PartitionData>,
120 pub _unknown_tagged_fields: Vec<RawTaggedField>,
121}
122impl Default for TopicData {
123 fn default() -> Self {
124 Self {
125 topic_id: KafkaUuid::ZERO,
126 partitions: Vec::new(),
127 _unknown_tagged_fields: Vec::new(),
128 }
129 }
130}
131impl TopicData {
132 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
133 self.topic_id = value;
134 self
135 }
136 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
137 self.partitions = value;
138 self
139 }
140 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
141 let topic_id;
142 let partitions;
143 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
144 topic_id = read_uuid(buf)?;
145 partitions = {
146 let len = read_compact_array_length(buf)?;
147 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
148 for _ in 0..len {
149 arr.push(PartitionData::read(buf, version)?);
150 }
151 arr
152 };
153 let tagged_fields = read_tagged_fields(buf)?;
154 for field in &tagged_fields {
155 match field.tag {
156 _ => {
157 _unknown_tagged_fields.push(field.clone());
158 },
159 }
160 }
161 Ok(Self {
162 topic_id,
163 partitions,
164 _unknown_tagged_fields,
165 })
166 }
167 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
168 write_uuid(buf, &self.topic_id);
169 write_compact_array_length(buf, self.partitions.len() as i32);
170 for el in &self.partitions {
171 el.write(buf, version)?;
172 }
173 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
174 all_tags.sort_by_key(|f| f.tag);
175 write_tagged_fields(buf, &all_tags)?;
176 Ok(())
177 }
178 pub fn encoded_len(&self, version: i16) -> Result<usize> {
179 let mut len: usize = 0;
180 len += 16;
181 len += compact_array_length_len(self.partitions.len() as i32);
182 for el in &self.partitions {
183 len += el.encoded_len(version)?;
184 }
185 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
186 all_tags.sort_by_key(|f| f.tag);
187 len += tagged_fields_len(&all_tags)?;
188 Ok(len)
189 }
190}
191#[derive(Debug, Clone, PartialEq)]
192pub struct PartitionData {
193 pub partition_index: i32,
195 pub error_code: i16,
197 pub leader_id: i32,
199 pub leader_epoch: i32,
201 pub isr: Vec<i32>,
203 pub leader_recovery_state: i8,
205 pub partition_epoch: i32,
207 pub _unknown_tagged_fields: Vec<RawTaggedField>,
208}
209impl Default for PartitionData {
210 fn default() -> Self {
211 Self {
212 partition_index: 0_i32,
213 error_code: 0_i16,
214 leader_id: 0_i32,
215 leader_epoch: 0_i32,
216 isr: Vec::new(),
217 leader_recovery_state: 0i8,
218 partition_epoch: 0_i32,
219 _unknown_tagged_fields: Vec::new(),
220 }
221 }
222}
223impl PartitionData {
224 pub fn with_partition_index(mut self, value: i32) -> Self {
225 self.partition_index = value;
226 self
227 }
228 pub fn with_error_code(mut self, value: i16) -> Self {
229 self.error_code = value;
230 self
231 }
232 pub fn with_leader_id(mut self, value: i32) -> Self {
233 self.leader_id = value;
234 self
235 }
236 pub fn with_leader_epoch(mut self, value: i32) -> Self {
237 self.leader_epoch = value;
238 self
239 }
240 pub fn with_isr(mut self, value: Vec<i32>) -> Self {
241 self.isr = value;
242 self
243 }
244 pub fn with_leader_recovery_state(mut self, value: i8) -> Self {
245 self.leader_recovery_state = value;
246 self
247 }
248 pub fn with_partition_epoch(mut self, value: i32) -> Self {
249 self.partition_epoch = value;
250 self
251 }
252 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
253 let partition_index;
254 let error_code;
255 let leader_id;
256 let leader_epoch;
257 let isr;
258 let leader_recovery_state;
259 let partition_epoch;
260 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
261 partition_index = read_i32(buf)?;
262 error_code = read_i16(buf)?;
263 leader_id = read_i32(buf)?;
264 leader_epoch = read_i32(buf)?;
265 isr = {
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(read_i32(buf)?);
270 }
271 arr
272 };
273 leader_recovery_state = read_i8(buf)?;
274 partition_epoch = read_i32(buf)?;
275 let tagged_fields = read_tagged_fields(buf)?;
276 for field in &tagged_fields {
277 match field.tag {
278 _ => {
279 _unknown_tagged_fields.push(field.clone());
280 },
281 }
282 }
283 Ok(Self {
284 partition_index,
285 error_code,
286 leader_id,
287 leader_epoch,
288 isr,
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_i16(buf, self.error_code);
297 write_i32(buf, self.leader_id);
298 write_i32(buf, self.leader_epoch);
299 write_compact_array_length(buf, self.isr.len() as i32);
300 for el in &self.isr {
301 write_i32(buf, *el);
302 }
303 write_i8(buf, self.leader_recovery_state);
304 write_i32(buf, self.partition_epoch);
305 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
306 all_tags.sort_by_key(|f| f.tag);
307 write_tagged_fields(buf, &all_tags)?;
308 Ok(())
309 }
310 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
311 let mut len: usize = 0;
312 len += 4;
313 len += 2;
314 len += 4;
315 len += 4;
316 len += compact_array_length_len(self.isr.len() as i32);
317 len += self.isr.len() * 4usize;
318 len += 1;
319 len += 4;
320 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
321 all_tags.sort_by_key(|f| f.tag);
322 len += tagged_fields_len(&all_tags)?;
323 Ok(len)
324 }
325}