#![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 AlterPartitionResponseData {
pub throttle_time_ms: i32,
pub error_code: i16,
pub topics: Vec<TopicData>,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AlterPartitionResponseData {
fn default() -> Self {
Self {
throttle_time_ms: 0_i32,
error_code: 0_i16,
topics: Vec::new(),
_unknown_tagged_fields: Vec::new(),
}
}
}
impl AlterPartitionResponseData {
pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
self.throttle_time_ms = value;
self
}
pub fn with_error_code(mut self, value: i16) -> Self {
self.error_code = value;
self
}
pub fn with_topics(mut self, value: Vec<TopicData>) -> Self {
self.topics = value;
self
}
pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
if version < 2 || version > 3 {
return Err(UnsupportedVersion::new(56, version).into());
}
let throttle_time_ms;
let error_code;
let topics;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
throttle_time_ms = read_i32(buf)?;
error_code = read_i16(buf)?;
topics = {
let len = read_compact_array_length(buf)?;
let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
for _ in 0..len {
arr.push(TopicData::read(buf, version)?);
}
arr
};
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,
error_code,
topics,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
if version < 2 || version > 3 {
return Err(UnsupportedVersion::new(56, version).into());
}
write_i32(buf, self.throttle_time_ms);
write_i16(buf, self.error_code);
write_compact_array_length(buf, self.topics.len() as i32);
for el in &self.topics {
el.write(buf, version)?;
}
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 < 2 || version > 3 {
return Err(UnsupportedVersion::new(56, version).into());
}
let mut len: usize = 0;
len += 4;
len += 2;
len += compact_array_length_len(self.topics.len() as i32);
for el in &self.topics {
len += el.encoded_len(version)?;
}
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 TopicData {
pub topic_id: KafkaUuid,
pub partitions: Vec<PartitionData>,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for TopicData {
fn default() -> Self {
Self {
topic_id: KafkaUuid::ZERO,
partitions: Vec::new(),
_unknown_tagged_fields: Vec::new(),
}
}
}
impl TopicData {
pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
self.topic_id = value;
self
}
pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
self.partitions = value;
self
}
pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
let topic_id;
let partitions;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
topic_id = read_uuid(buf)?;
partitions = {
let len = read_compact_array_length(buf)?;
let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
for _ in 0..len {
arr.push(PartitionData::read(buf, version)?);
}
arr
};
let tagged_fields = read_tagged_fields(buf)?;
for field in &tagged_fields {
match field.tag {
_ => {
_unknown_tagged_fields.push(field.clone());
},
}
}
Ok(Self {
topic_id,
partitions,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
write_uuid(buf, &self.topic_id);
write_compact_array_length(buf, self.partitions.len() as i32);
for el in &self.partitions {
el.write(buf, version)?;
}
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 += 16;
len += compact_array_length_len(self.partitions.len() as i32);
for el in &self.partitions {
len += el.encoded_len(version)?;
}
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 PartitionData {
pub partition_index: i32,
pub error_code: i16,
pub leader_id: i32,
pub leader_epoch: i32,
pub isr: Vec<i32>,
pub leader_recovery_state: i8,
pub partition_epoch: i32,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for PartitionData {
fn default() -> Self {
Self {
partition_index: 0_i32,
error_code: 0_i16,
leader_id: 0_i32,
leader_epoch: 0_i32,
isr: Vec::new(),
leader_recovery_state: 0i8,
partition_epoch: 0_i32,
_unknown_tagged_fields: Vec::new(),
}
}
}
impl PartitionData {
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 with_leader_id(mut self, value: i32) -> Self {
self.leader_id = value;
self
}
pub fn with_leader_epoch(mut self, value: i32) -> Self {
self.leader_epoch = value;
self
}
pub fn with_isr(mut self, value: Vec<i32>) -> Self {
self.isr = value;
self
}
pub fn with_leader_recovery_state(mut self, value: i8) -> Self {
self.leader_recovery_state = value;
self
}
pub fn with_partition_epoch(mut self, value: i32) -> Self {
self.partition_epoch = value;
self
}
pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
let partition_index;
let error_code;
let leader_id;
let leader_epoch;
let isr;
let leader_recovery_state;
let partition_epoch;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
partition_index = read_i32(buf)?;
error_code = read_i16(buf)?;
leader_id = read_i32(buf)?;
leader_epoch = read_i32(buf)?;
isr = {
let len = read_compact_array_length(buf)?;
let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
for _ in 0..len {
arr.push(read_i32(buf)?);
}
arr
};
leader_recovery_state = read_i8(buf)?;
partition_epoch = read_i32(buf)?;
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,
leader_id,
leader_epoch,
isr,
leader_recovery_state,
partition_epoch,
_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);
write_i32(buf, self.leader_id);
write_i32(buf, self.leader_epoch);
write_compact_array_length(buf, self.isr.len() as i32);
for el in &self.isr {
write_i32(buf, *el);
}
write_i8(buf, self.leader_recovery_state);
write_i32(buf, self.partition_epoch);
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;
len += 4;
len += 4;
len += compact_array_length_len(self.isr.len() as i32);
len += self.isr.len() * 4usize;
len += 1;
len += 4;
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)
}
}