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