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