#![allow(
clippy::field_reassign_with_default,
clippy::nonminimal_bool,
clippy::derivable_impls,
clippy::borrow_deref_ref,
clippy::double_parens,
unused_parens
)]
use bytes::{Buf, BufMut};
use crate::budget::{Budget, Limits};
#[allow(unused_imports)]
use crate::error::{DecodeError, EncodeError};
use crate::wire::{self, RawTaggedField};
pub fn is_flexible(version: i16) -> bool {
let _ = version;
version >= 4
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct DeleteTopicsRequest {
pub topics: Vec<DeleteTopicState>,
pub topic_names: Vec<String>,
pub timeout_ms: i32,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for DeleteTopicsRequest {
fn default() -> Self {
Self {
topics: Vec::new(),
topic_names: Vec::new(),
timeout_ms: 0,
unknown_tagged_fields: Vec::new(),
}
}
}
impl DeleteTopicsRequest {
pub const API_KEY: i16 = 20;
pub const MIN_VERSION: i16 = 1;
pub const MAX_VERSION: i16 = 6;
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
if version >= 6 {
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.topics.len()));
} else {
wire::put_array_len(buf, Some(self.topics.len()))?;
}
for item in &self.topics {
item.encode(buf, version)?;
}
}
if version <= 5 {
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.topic_names.len()));
} else {
wire::put_array_len(buf, Some(self.topic_names.len()))?;
}
for item in &self.topic_names {
if is_flexible(version) {
wire::put_compact_string(buf, item);
} else {
wire::put_string(buf, item)?;
}
}
}
buf.put_i32(self.timeout_ms);
if is_flexible(version) {
wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
}
Ok(())
}
pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
Self::decode_with_limits(buf, version, Limits::default())
}
pub fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
let mut budget = limits.budget(buf.remaining());
Self::decode_with_budget(buf, version, &mut budget)
}
pub fn decode_with_budget(
buf: &mut impl Buf,
version: i16,
budget: &mut Budget,
) -> Result<Self, DecodeError> {
let mut this = Self::default();
if version >= 6 {
this.topics = {
let len = if is_flexible(version) {
wire::get_compact_array_len(buf)?
} else {
wire::get_array_len(buf)?
};
match len {
None => return Err(DecodeError::InvalidLength(-1)),
Some(n) => {
let mut items = Vec::new();
for _ in 0..n {
let mark = buf.remaining();
let item = DeleteTopicState::decode_with_budget(buf, version, budget)?;
budget.progress(mark, buf.remaining())?;
budget.push(&mut items, item)?;
}
items
}
}
};
}
if version <= 5 {
this.topic_names = {
let len = if is_flexible(version) {
wire::get_compact_array_len(buf)?
} else {
wire::get_array_len(buf)?
};
match len {
None => return Err(DecodeError::InvalidLength(-1)),
Some(n) => {
let mut items = Vec::new();
for _ in 0..n {
budget.push(
&mut items,
if is_flexible(version) {
wire::get_compact_string(buf)?
} else {
wire::get_string(buf)?
},
)?;
}
items
}
}
};
}
this.timeout_ms = wire::get_i32(buf)?;
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}
impl crate::Message for DeleteTopicsRequest {
const API_KEY: i16 = 20;
const MIN_VERSION: i16 = 1;
const MAX_VERSION: i16 = 6;
fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
DeleteTopicsRequest::encode(self, buf, version)
}
fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
DeleteTopicsRequest::decode(buf, version)
}
fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
DeleteTopicsRequest::decode_with_limits(buf, version, limits)
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct DeleteTopicState {
pub name: Option<String>,
pub topic_id: [u8; 16],
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for DeleteTopicState {
fn default() -> Self {
Self {
name: None,
topic_id: [0u8; 16],
unknown_tagged_fields: Vec::new(),
}
}
}
impl DeleteTopicState {
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
if version >= 6 {
if is_flexible(version) {
wire::put_compact_nullable_string(buf, self.name.as_deref());
} else {
wire::put_nullable_string(buf, self.name.as_deref())?;
}
}
if version >= 6 {
wire::put_uuid(buf, self.topic_id);
}
if is_flexible(version) {
wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
}
Ok(())
}
pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
Self::decode_with_limits(buf, version, Limits::default())
}
pub fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
let mut budget = limits.budget(buf.remaining());
Self::decode_with_budget(buf, version, &mut budget)
}
pub fn decode_with_budget(
buf: &mut impl Buf,
version: i16,
budget: &mut Budget,
) -> Result<Self, DecodeError> {
let mut this = Self::default();
if version >= 6 {
this.name = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
}
if version >= 6 {
this.topic_id = wire::get_uuid(buf)?;
}
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}