#![allow(
missing_docs,
clippy::all,
clippy::pedantic,
clippy::nursery,
clippy::arithmetic_side_effects,
reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
hand-written lint style for reproducible wire-code output."
)]
use bytes::{Bytes, BytesMut};
use crate::*;
#[derive(Debug, Clone, PartialEq)]
pub struct AlterReplicaLogDirsResponseData {
pub throttle_time_ms: i32,
pub results: Vec<AlterReplicaLogDirTopicResult>,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AlterReplicaLogDirsResponseData {
fn default() -> Self {
Self {
throttle_time_ms: 0_i32,
results: Vec::new(),
_unknown_tagged_fields: Vec::new(),
}
}
}
impl AlterReplicaLogDirsResponseData {
pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
self.throttle_time_ms = value;
self
}
pub fn with_results(mut self, value: Vec<AlterReplicaLogDirTopicResult>) -> Self {
self.results = value;
self
}
pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
if version < 1 || version > 2 {
return Err(UnsupportedVersion::new(34, version).into());
}
let throttle_time_ms;
let results;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
throttle_time_ms = read_i32(buf)?;
if version >= 2 {
results = {
let len = read_compact_array_length(buf)?;
let mut arr = Vec::with_capacity(len.max(0) as usize);
for _ in 0..len {
arr.push(AlterReplicaLogDirTopicResult::read(buf, version)?);
}
arr
};
} else {
results = {
let len = read_array_length(buf)?;
let mut arr = Vec::with_capacity(len.max(0) as usize);
for _ in 0..len {
arr.push(AlterReplicaLogDirTopicResult::read(buf, version)?);
}
arr
};
}
if version >= 2 {
let tagged_fields = read_tagged_fields(buf)?;
for field in &tagged_fields {
match field.tag {
_ => {
_unknown_tagged_fields.push(field.clone());
},
}
}
}
Ok(Self {
throttle_time_ms,
results,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
if version < 1 || version > 2 {
return Err(UnsupportedVersion::new(34, version).into());
}
write_i32(buf, self.throttle_time_ms);
if version >= 2 {
write_compact_array_length(buf, self.results.len() as i32);
for el in &self.results {
el.write(buf, version)?;
}
} else {
write_array_length(buf, self.results.len() as i32);
for el in &self.results {
el.write(buf, version)?;
}
}
if version >= 2 {
let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
all_tags.sort_by_key(|f| f.tag);
write_tagged_fields(buf, &all_tags)?;
}
Ok(())
}
pub fn encoded_len(&self, version: i16) -> Result<usize> {
if version < 1 || version > 2 {
return Err(UnsupportedVersion::new(34, version).into());
}
let mut len: usize = 0;
len += 4;
if version >= 2 {
len += compact_array_length_len(self.results.len() as i32);
for el in &self.results {
len += el.encoded_len(version)?;
}
} else {
len += array_length_len();
for el in &self.results {
len += el.encoded_len(version)?;
}
}
if version >= 2 {
let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
all_tags.sort_by_key(|f| f.tag);
len += tagged_fields_len(&all_tags)?;
}
Ok(len)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct AlterReplicaLogDirTopicResult {
pub topic_name: KafkaString,
pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AlterReplicaLogDirTopicResult {
fn default() -> Self {
Self {
topic_name: KafkaString::default(),
partitions: Vec::new(),
_unknown_tagged_fields: Vec::new(),
}
}
}
impl AlterReplicaLogDirTopicResult {
pub fn with_topic_name(mut self, value: KafkaString) -> Self {
self.topic_name = value;
self
}
pub fn with_partitions(mut self, value: Vec<AlterReplicaLogDirPartitionResult>) -> Self {
self.partitions = value;
self
}
pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
let topic_name;
let partitions;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
if version >= 2 {
topic_name = read_compact_string(buf)?;
} else {
topic_name = read_string(buf)?;
}
if version >= 2 {
partitions = {
let len = read_compact_array_length(buf)?;
let mut arr = Vec::with_capacity(len.max(0) as usize);
for _ in 0..len {
arr.push(AlterReplicaLogDirPartitionResult::read(buf, version)?);
}
arr
};
} else {
partitions = {
let len = read_array_length(buf)?;
let mut arr = Vec::with_capacity(len.max(0) as usize);
for _ in 0..len {
arr.push(AlterReplicaLogDirPartitionResult::read(buf, version)?);
}
arr
};
}
if version >= 2 {
let tagged_fields = read_tagged_fields(buf)?;
for field in &tagged_fields {
match field.tag {
_ => {
_unknown_tagged_fields.push(field.clone());
},
}
}
}
Ok(Self {
topic_name,
partitions,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
if version >= 2 {
write_compact_string(buf, &self.topic_name)?;
} else {
write_string(buf, &self.topic_name)?;
}
if version >= 2 {
write_compact_array_length(buf, self.partitions.len() as i32);
for el in &self.partitions {
el.write(buf, version)?;
}
} else {
write_array_length(buf, self.partitions.len() as i32);
for el in &self.partitions {
el.write(buf, version)?;
}
}
if version >= 2 {
let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
all_tags.sort_by_key(|f| f.tag);
write_tagged_fields(buf, &all_tags)?;
}
Ok(())
}
pub fn encoded_len(&self, version: i16) -> Result<usize> {
let mut len: usize = 0;
if version >= 2 {
len += compact_string_len(&self.topic_name)?;
} else {
len += string_len(&self.topic_name)?;
}
if version >= 2 {
len += compact_array_length_len(self.partitions.len() as i32);
for el in &self.partitions {
len += el.encoded_len(version)?;
}
} else {
len += array_length_len();
for el in &self.partitions {
len += el.encoded_len(version)?;
}
}
if version >= 2 {
let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
all_tags.sort_by_key(|f| f.tag);
len += tagged_fields_len(&all_tags)?;
}
Ok(len)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct AlterReplicaLogDirPartitionResult {
pub partition_index: i32,
pub error_code: i16,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AlterReplicaLogDirPartitionResult {
fn default() -> Self {
Self {
partition_index: 0_i32,
error_code: 0_i16,
_unknown_tagged_fields: Vec::new(),
}
}
}
impl AlterReplicaLogDirPartitionResult {
pub fn with_partition_index(mut self, value: i32) -> Self {
self.partition_index = value;
self
}
pub fn with_error_code(mut self, value: i16) -> Self {
self.error_code = value;
self
}
pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
let partition_index;
let error_code;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
partition_index = read_i32(buf)?;
error_code = read_i16(buf)?;
if version >= 2 {
let tagged_fields = read_tagged_fields(buf)?;
for field in &tagged_fields {
match field.tag {
_ => {
_unknown_tagged_fields.push(field.clone());
},
}
}
}
Ok(Self {
partition_index,
error_code,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
write_i32(buf, self.partition_index);
write_i16(buf, self.error_code);
if version >= 2 {
let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
all_tags.sort_by_key(|f| f.tag);
write_tagged_fields(buf, &all_tags)?;
}
Ok(())
}
pub fn encoded_len(&self, version: i16) -> Result<usize> {
let mut len: usize = 0;
len += 4;
len += 2;
if version >= 2 {
let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
all_tags.sort_by_key(|f| f.tag);
len += tagged_fields_len(&all_tags)?;
}
Ok(len)
}
}