1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct DeleteRecordsPartitionResult {
24 pub partition_index: i32,
28
29 pub low_watermark: i64,
33
34 pub error_code: i16,
38
39 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl DeleteRecordsPartitionResult {
44 pub fn with_partition_index(mut self, value: i32) -> Self {
50 self.partition_index = value;
51 self
52 }
53 pub fn with_low_watermark(mut self, value: i64) -> Self {
59 self.low_watermark = value;
60 self
61 }
62 pub fn with_error_code(mut self, value: i16) -> Self {
68 self.error_code = value;
69 self
70 }
71 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73 self.unknown_tagged_fields = value;
74 self
75 }
76 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78 self.unknown_tagged_fields.insert(key, value);
79 self
80 }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for DeleteRecordsPartitionResult {
85 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86 if version < 0 || version > 2 {
87 bail!("specified version not supported by this message type");
88 }
89 types::Int32.encode(buf, &self.partition_index)?;
90 types::Int64.encode(buf, &self.low_watermark)?;
91 types::Int16.encode(buf, &self.error_code)?;
92 if version >= 2 {
93 let num_tagged_fields = self.unknown_tagged_fields.len();
94 if num_tagged_fields > std::u32::MAX as usize {
95 bail!(
96 "Too many tagged fields to encode ({} fields)",
97 num_tagged_fields
98 );
99 }
100 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
101
102 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
103 }
104 Ok(())
105 }
106 fn compute_size(&self, version: i16) -> Result<usize> {
107 let mut total_size = 0;
108 total_size += types::Int32.compute_size(&self.partition_index)?;
109 total_size += types::Int64.compute_size(&self.low_watermark)?;
110 total_size += types::Int16.compute_size(&self.error_code)?;
111 if version >= 2 {
112 let num_tagged_fields = self.unknown_tagged_fields.len();
113 if num_tagged_fields > std::u32::MAX as usize {
114 bail!(
115 "Too many tagged fields to encode ({} fields)",
116 num_tagged_fields
117 );
118 }
119 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
120
121 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
122 }
123 Ok(total_size)
124 }
125}
126
127#[cfg(feature = "client")]
128impl Decodable for DeleteRecordsPartitionResult {
129 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
130 if version < 0 || version > 2 {
131 bail!("specified version not supported by this message type");
132 }
133 let partition_index = types::Int32.decode(buf)?;
134 let low_watermark = types::Int64.decode(buf)?;
135 let error_code = types::Int16.decode(buf)?;
136 let mut unknown_tagged_fields = BTreeMap::new();
137 if version >= 2 {
138 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
139 for _ in 0..num_tagged_fields {
140 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
141 let size: u32 = types::UnsignedVarInt.decode(buf)?;
142 let unknown_value = buf.try_get_bytes(size as usize)?;
143 unknown_tagged_fields.insert(tag as i32, unknown_value);
144 }
145 }
146 Ok(Self {
147 partition_index,
148 low_watermark,
149 error_code,
150 unknown_tagged_fields,
151 })
152 }
153}
154
155impl Default for DeleteRecordsPartitionResult {
156 fn default() -> Self {
157 Self {
158 partition_index: 0,
159 low_watermark: 0,
160 error_code: 0,
161 unknown_tagged_fields: BTreeMap::new(),
162 }
163 }
164}
165
166impl Message for DeleteRecordsPartitionResult {
167 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
168 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
169}
170
171#[non_exhaustive]
173#[derive(Debug, Clone, PartialEq)]
174pub struct DeleteRecordsResponse {
175 pub throttle_time_ms: i32,
179
180 pub topics: Vec<DeleteRecordsTopicResult>,
184
185 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
187}
188
189impl DeleteRecordsResponse {
190 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
196 self.throttle_time_ms = value;
197 self
198 }
199 pub fn with_topics(mut self, value: Vec<DeleteRecordsTopicResult>) -> Self {
205 self.topics = value;
206 self
207 }
208 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
210 self.unknown_tagged_fields = value;
211 self
212 }
213 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
215 self.unknown_tagged_fields.insert(key, value);
216 self
217 }
218}
219
220#[cfg(feature = "broker")]
221impl Encodable for DeleteRecordsResponse {
222 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
223 if version < 0 || version > 2 {
224 bail!("specified version not supported by this message type");
225 }
226 types::Int32.encode(buf, &self.throttle_time_ms)?;
227 if version >= 2 {
228 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
229 } else {
230 types::Array(types::Struct { version }).encode(buf, &self.topics)?;
231 }
232 if version >= 2 {
233 let num_tagged_fields = self.unknown_tagged_fields.len();
234 if num_tagged_fields > std::u32::MAX as usize {
235 bail!(
236 "Too many tagged fields to encode ({} fields)",
237 num_tagged_fields
238 );
239 }
240 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
241
242 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
243 }
244 Ok(())
245 }
246 fn compute_size(&self, version: i16) -> Result<usize> {
247 let mut total_size = 0;
248 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
249 if version >= 2 {
250 total_size +=
251 types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
252 } else {
253 total_size += types::Array(types::Struct { version }).compute_size(&self.topics)?;
254 }
255 if version >= 2 {
256 let num_tagged_fields = self.unknown_tagged_fields.len();
257 if num_tagged_fields > std::u32::MAX as usize {
258 bail!(
259 "Too many tagged fields to encode ({} fields)",
260 num_tagged_fields
261 );
262 }
263 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
264
265 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
266 }
267 Ok(total_size)
268 }
269}
270
271#[cfg(feature = "client")]
272impl Decodable for DeleteRecordsResponse {
273 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
274 if version < 0 || version > 2 {
275 bail!("specified version not supported by this message type");
276 }
277 let throttle_time_ms = types::Int32.decode(buf)?;
278 let topics = if version >= 2 {
279 types::CompactArray(types::Struct { version }).decode(buf)?
280 } else {
281 types::Array(types::Struct { version }).decode(buf)?
282 };
283 let mut unknown_tagged_fields = BTreeMap::new();
284 if version >= 2 {
285 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
286 for _ in 0..num_tagged_fields {
287 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
288 let size: u32 = types::UnsignedVarInt.decode(buf)?;
289 let unknown_value = buf.try_get_bytes(size as usize)?;
290 unknown_tagged_fields.insert(tag as i32, unknown_value);
291 }
292 }
293 Ok(Self {
294 throttle_time_ms,
295 topics,
296 unknown_tagged_fields,
297 })
298 }
299}
300
301impl Default for DeleteRecordsResponse {
302 fn default() -> Self {
303 Self {
304 throttle_time_ms: 0,
305 topics: Default::default(),
306 unknown_tagged_fields: BTreeMap::new(),
307 }
308 }
309}
310
311impl Message for DeleteRecordsResponse {
312 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
313 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
314}
315
316#[non_exhaustive]
318#[derive(Debug, Clone, PartialEq)]
319pub struct DeleteRecordsTopicResult {
320 pub name: super::TopicName,
324
325 pub partitions: Vec<DeleteRecordsPartitionResult>,
329
330 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
332}
333
334impl DeleteRecordsTopicResult {
335 pub fn with_name(mut self, value: super::TopicName) -> Self {
341 self.name = value;
342 self
343 }
344 pub fn with_partitions(mut self, value: Vec<DeleteRecordsPartitionResult>) -> Self {
350 self.partitions = value;
351 self
352 }
353 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
355 self.unknown_tagged_fields = value;
356 self
357 }
358 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
360 self.unknown_tagged_fields.insert(key, value);
361 self
362 }
363}
364
365#[cfg(feature = "broker")]
366impl Encodable for DeleteRecordsTopicResult {
367 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
368 if version < 0 || version > 2 {
369 bail!("specified version not supported by this message type");
370 }
371 if version >= 2 {
372 types::CompactString.encode(buf, &self.name)?;
373 } else {
374 types::String.encode(buf, &self.name)?;
375 }
376 if version >= 2 {
377 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
378 } else {
379 types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
380 }
381 if version >= 2 {
382 let num_tagged_fields = self.unknown_tagged_fields.len();
383 if num_tagged_fields > std::u32::MAX as usize {
384 bail!(
385 "Too many tagged fields to encode ({} fields)",
386 num_tagged_fields
387 );
388 }
389 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
390
391 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
392 }
393 Ok(())
394 }
395 fn compute_size(&self, version: i16) -> Result<usize> {
396 let mut total_size = 0;
397 if version >= 2 {
398 total_size += types::CompactString.compute_size(&self.name)?;
399 } else {
400 total_size += types::String.compute_size(&self.name)?;
401 }
402 if version >= 2 {
403 total_size +=
404 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
405 } else {
406 total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
407 }
408 if version >= 2 {
409 let num_tagged_fields = self.unknown_tagged_fields.len();
410 if num_tagged_fields > std::u32::MAX as usize {
411 bail!(
412 "Too many tagged fields to encode ({} fields)",
413 num_tagged_fields
414 );
415 }
416 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
417
418 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
419 }
420 Ok(total_size)
421 }
422}
423
424#[cfg(feature = "client")]
425impl Decodable for DeleteRecordsTopicResult {
426 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
427 if version < 0 || version > 2 {
428 bail!("specified version not supported by this message type");
429 }
430 let name = if version >= 2 {
431 types::CompactString.decode(buf)?
432 } else {
433 types::String.decode(buf)?
434 };
435 let partitions = if version >= 2 {
436 types::CompactArray(types::Struct { version }).decode(buf)?
437 } else {
438 types::Array(types::Struct { version }).decode(buf)?
439 };
440 let mut unknown_tagged_fields = BTreeMap::new();
441 if version >= 2 {
442 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
443 for _ in 0..num_tagged_fields {
444 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
445 let size: u32 = types::UnsignedVarInt.decode(buf)?;
446 let unknown_value = buf.try_get_bytes(size as usize)?;
447 unknown_tagged_fields.insert(tag as i32, unknown_value);
448 }
449 }
450 Ok(Self {
451 name,
452 partitions,
453 unknown_tagged_fields,
454 })
455 }
456}
457
458impl Default for DeleteRecordsTopicResult {
459 fn default() -> Self {
460 Self {
461 name: Default::default(),
462 partitions: Default::default(),
463 unknown_tagged_fields: BTreeMap::new(),
464 }
465 }
466}
467
468impl Message for DeleteRecordsTopicResult {
469 const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
470 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
471}
472
473impl HeaderVersion for DeleteRecordsResponse {
474 fn header_version(version: i16) -> i16 {
475 if version >= 2 {
476 1
477 } else {
478 0
479 }
480 }
481}