kacrab_protocol/generated/
offset_commit_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 OffsetCommitResponseData {
17 pub throttle_time_ms: i32,
20 pub topics: Vec<OffsetCommitResponseTopic>,
22 pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for OffsetCommitResponseData {
25 fn default() -> Self {
26 Self {
27 throttle_time_ms: 0_i32,
28 topics: Vec::new(),
29 _unknown_tagged_fields: Vec::new(),
30 }
31 }
32}
33impl OffsetCommitResponseData {
34 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35 self.throttle_time_ms = value;
36 self
37 }
38 pub fn with_topics(mut self, value: Vec<OffsetCommitResponseTopic>) -> Self {
39 self.topics = value;
40 self
41 }
42 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43 if version < 2 || version > 10 {
44 return Err(UnsupportedVersion::new(8, version).into());
45 }
46 let mut throttle_time_ms = 0_i32;
47 let topics;
48 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49 if version >= 3 {
50 throttle_time_ms = read_i32(buf)?;
51 }
52 if version >= 8 {
53 topics = {
54 let len = read_compact_array_length(buf)?;
55 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
56 for _ in 0..len {
57 arr.push(OffsetCommitResponseTopic::read(buf, version)?);
58 }
59 arr
60 };
61 } else {
62 topics = {
63 let len = read_array_length(buf)?;
64 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
65 for _ in 0..len {
66 arr.push(OffsetCommitResponseTopic::read(buf, version)?);
67 }
68 arr
69 };
70 }
71 if version >= 8 {
72 let tagged_fields = read_tagged_fields(buf)?;
73 for field in &tagged_fields {
74 match field.tag {
75 _ => {
76 _unknown_tagged_fields.push(field.clone());
77 },
78 }
79 }
80 }
81 Ok(Self {
82 throttle_time_ms,
83 topics,
84 _unknown_tagged_fields,
85 })
86 }
87 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
88 if version < 2 || version > 10 {
89 return Err(UnsupportedVersion::new(8, version).into());
90 }
91 if version >= 3 {
92 write_i32(buf, self.throttle_time_ms);
93 } else if self.throttle_time_ms != 0_i32 {
94 return Err(UnsupportedFieldVersion::new(8, "throttle_time_ms", version).into());
95 }
96 if version >= 8 {
97 write_compact_array_length(buf, self.topics.len() as i32);
98 for el in &self.topics {
99 el.write(buf, version)?;
100 }
101 } else {
102 write_array_length(buf, self.topics.len() as i32);
103 for el in &self.topics {
104 el.write(buf, version)?;
105 }
106 }
107 if version >= 8 {
108 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
109 all_tags.sort_by_key(|f| f.tag);
110 write_tagged_fields(buf, &all_tags)?;
111 }
112 Ok(())
113 }
114 pub fn encoded_len(&self, version: i16) -> Result<usize> {
115 if version < 2 || version > 10 {
116 return Err(UnsupportedVersion::new(8, version).into());
117 }
118 let mut len: usize = 0;
119 if version >= 3 {
120 len += 4;
121 } else if self.throttle_time_ms != 0_i32 {
122 return Err(UnsupportedFieldVersion::new(8, "throttle_time_ms", version).into());
123 }
124 if version >= 8 {
125 len += compact_array_length_len(self.topics.len() as i32);
126 for el in &self.topics {
127 len += el.encoded_len(version)?;
128 }
129 } else {
130 len += array_length_len();
131 for el in &self.topics {
132 len += el.encoded_len(version)?;
133 }
134 }
135 if version >= 8 {
136 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
137 all_tags.sort_by_key(|f| f.tag);
138 len += tagged_fields_len(&all_tags)?;
139 }
140 Ok(len)
141 }
142}
143#[derive(Debug, Clone, PartialEq)]
144pub struct OffsetCommitResponseTopic {
145 pub name: KafkaString,
147 pub topic_id: KafkaUuid,
149 pub partitions: Vec<OffsetCommitResponsePartition>,
151 pub _unknown_tagged_fields: Vec<RawTaggedField>,
152}
153impl Default for OffsetCommitResponseTopic {
154 fn default() -> Self {
155 Self {
156 name: KafkaString::default(),
157 topic_id: KafkaUuid::ZERO,
158 partitions: Vec::new(),
159 _unknown_tagged_fields: Vec::new(),
160 }
161 }
162}
163impl OffsetCommitResponseTopic {
164 pub fn with_name(mut self, value: KafkaString) -> Self {
165 self.name = value;
166 self
167 }
168 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
169 self.topic_id = value;
170 self
171 }
172 pub fn with_partitions(mut self, value: Vec<OffsetCommitResponsePartition>) -> Self {
173 self.partitions = value;
174 self
175 }
176 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
177 let mut name = KafkaString::default();
178 let mut topic_id = KafkaUuid::ZERO;
179 let partitions;
180 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
181 if version <= 9 {
182 if version >= 8 {
183 name = read_compact_string(buf)?;
184 } else {
185 name = read_string(buf)?;
186 }
187 }
188 if version >= 10 {
189 topic_id = read_uuid(buf)?;
190 }
191 if version >= 8 {
192 partitions = {
193 let len = read_compact_array_length(buf)?;
194 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
195 for _ in 0..len {
196 arr.push(OffsetCommitResponsePartition::read(buf, version)?);
197 }
198 arr
199 };
200 } else {
201 partitions = {
202 let len = read_array_length(buf)?;
203 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
204 for _ in 0..len {
205 arr.push(OffsetCommitResponsePartition::read(buf, version)?);
206 }
207 arr
208 };
209 }
210 if version >= 8 {
211 let tagged_fields = read_tagged_fields(buf)?;
212 for field in &tagged_fields {
213 match field.tag {
214 _ => {
215 _unknown_tagged_fields.push(field.clone());
216 },
217 }
218 }
219 }
220 Ok(Self {
221 name,
222 topic_id,
223 partitions,
224 _unknown_tagged_fields,
225 })
226 }
227 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
228 if version <= 9 {
229 if version >= 8 {
230 write_compact_string(buf, &self.name)?;
231 } else {
232 write_string(buf, &self.name)?;
233 }
234 } else if self.name != KafkaString::default() {
235 return Err(UnsupportedFieldVersion::new(8, "name", version).into());
236 }
237 if version >= 10 {
238 write_uuid(buf, &self.topic_id);
239 } else if self.topic_id != KafkaUuid::ZERO {
240 return Err(UnsupportedFieldVersion::new(8, "topic_id", version).into());
241 }
242 if version >= 8 {
243 write_compact_array_length(buf, self.partitions.len() as i32);
244 for el in &self.partitions {
245 el.write(buf, version)?;
246 }
247 } else {
248 write_array_length(buf, self.partitions.len() as i32);
249 for el in &self.partitions {
250 el.write(buf, version)?;
251 }
252 }
253 if version >= 8 {
254 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
255 all_tags.sort_by_key(|f| f.tag);
256 write_tagged_fields(buf, &all_tags)?;
257 }
258 Ok(())
259 }
260 pub fn encoded_len(&self, version: i16) -> Result<usize> {
261 let mut len: usize = 0;
262 if version <= 9 {
263 if version >= 8 {
264 len += compact_string_len(&self.name)?;
265 } else {
266 len += string_len(&self.name)?;
267 }
268 } else if self.name != KafkaString::default() {
269 return Err(UnsupportedFieldVersion::new(8, "name", version).into());
270 }
271 if version >= 10 {
272 len += 16;
273 } else if self.topic_id != KafkaUuid::ZERO {
274 return Err(UnsupportedFieldVersion::new(8, "topic_id", version).into());
275 }
276 if version >= 8 {
277 len += compact_array_length_len(self.partitions.len() as i32);
278 for el in &self.partitions {
279 len += el.encoded_len(version)?;
280 }
281 } else {
282 len += array_length_len();
283 for el in &self.partitions {
284 len += el.encoded_len(version)?;
285 }
286 }
287 if version >= 8 {
288 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
289 all_tags.sort_by_key(|f| f.tag);
290 len += tagged_fields_len(&all_tags)?;
291 }
292 Ok(len)
293 }
294}
295#[derive(Debug, Clone, PartialEq)]
296pub struct OffsetCommitResponsePartition {
297 pub partition_index: i32,
299 pub error_code: i16,
301 pub _unknown_tagged_fields: Vec<RawTaggedField>,
302}
303impl Default for OffsetCommitResponsePartition {
304 fn default() -> Self {
305 Self {
306 partition_index: 0_i32,
307 error_code: 0_i16,
308 _unknown_tagged_fields: Vec::new(),
309 }
310 }
311}
312impl OffsetCommitResponsePartition {
313 pub fn with_partition_index(mut self, value: i32) -> Self {
314 self.partition_index = value;
315 self
316 }
317 pub fn with_error_code(mut self, value: i16) -> Self {
318 self.error_code = value;
319 self
320 }
321 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
322 let partition_index;
323 let error_code;
324 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
325 partition_index = read_i32(buf)?;
326 error_code = read_i16(buf)?;
327 if version >= 8 {
328 let tagged_fields = read_tagged_fields(buf)?;
329 for field in &tagged_fields {
330 match field.tag {
331 _ => {
332 _unknown_tagged_fields.push(field.clone());
333 },
334 }
335 }
336 }
337 Ok(Self {
338 partition_index,
339 error_code,
340 _unknown_tagged_fields,
341 })
342 }
343 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
344 write_i32(buf, self.partition_index);
345 write_i16(buf, self.error_code);
346 if version >= 8 {
347 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
348 all_tags.sort_by_key(|f| f.tag);
349 write_tagged_fields(buf, &all_tags)?;
350 }
351 Ok(())
352 }
353 pub fn encoded_len(&self, version: i16) -> Result<usize> {
354 let mut len: usize = 0;
355 len += 4;
356 len += 2;
357 if version >= 8 {
358 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
359 all_tags.sort_by_key(|f| f.tag);
360 len += tagged_fields_len(&all_tags)?;
361 }
362 Ok(len)
363 }
364}