#![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 VoteResponseData {
pub error_code: i16,
pub topics: Vec<TopicData>,
pub node_endpoints: Vec<NodeEndpoint>,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for VoteResponseData {
fn default() -> Self {
Self {
error_code: 0_i16,
topics: Vec::new(),
node_endpoints: Vec::new(),
_unknown_tagged_fields: Vec::new(),
}
}
}
impl VoteResponseData {
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 with_node_endpoints(mut self, value: Vec<NodeEndpoint>) -> Self {
self.node_endpoints = value;
self
}
pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
if version < 0 || version > 2 {
return Err(UnsupportedVersion::new(52, version).into());
}
let error_code;
let topics;
let mut node_endpoints = Vec::new();
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
error_code = read_i16(buf)?;
topics = {
let len = read_compact_array_length(buf)?;
let mut arr = Vec::with_capacity(len.max(0) as usize);
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 {
0 => {
if version >= 1 {
let mut tag_buf = field.data.clone();
node_endpoints = {
let len = read_compact_array_length(&mut tag_buf)?;
let mut arr = Vec::with_capacity(len.max(0) as usize);
for _ in 0..len {
arr.push(NodeEndpoint::read(&mut tag_buf, version)?);
}
arr
};
}
},
_ => {
_unknown_tagged_fields.push(field.clone());
},
}
}
Ok(Self {
error_code,
topics,
node_endpoints,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
if version < 0 || version > 2 {
return Err(UnsupportedVersion::new(52, version).into());
}
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 known_tagged_fields: Vec<RawTaggedField> = Vec::new();
if version >= 1 && !self.node_endpoints.is_empty() {
let mut tag_buf = BytesMut::new();
write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
for el in &self.node_endpoints {
el.write(&mut tag_buf, version)?;
}
known_tagged_fields.push(RawTaggedField {
tag: 0,
data: tag_buf.freeze(),
});
}
let mut all_tags = known_tagged_fields;
all_tags.extend(self._unknown_tagged_fields.iter().cloned());
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 < 0 || version > 2 {
return Err(UnsupportedVersion::new(52, version).into());
}
let mut len: usize = 0;
len += 2;
len += compact_array_length_len(self.topics.len() as i32);
for el in &self.topics {
len += el.encoded_len(version)?;
}
let mut known_tagged_fields: Vec<RawTaggedField> = Vec::new();
if version >= 1 && !self.node_endpoints.is_empty() {
let mut tag_buf = BytesMut::new();
write_compact_array_length(&mut tag_buf, self.node_endpoints.len() as i32);
for el in &self.node_endpoints {
el.write(&mut tag_buf, version)?;
}
known_tagged_fields.push(RawTaggedField {
tag: 0,
data: tag_buf.freeze(),
});
}
let mut all_tags = known_tagged_fields;
all_tags.extend(self._unknown_tagged_fields.iter().cloned());
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_name: KafkaString,
pub partitions: Vec<PartitionData>,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for TopicData {
fn default() -> Self {
Self {
topic_name: KafkaString::default(),
partitions: Vec::new(),
_unknown_tagged_fields: Vec::new(),
}
}
}
impl TopicData {
pub fn with_topic_name(mut self, value: KafkaString) -> Self {
self.topic_name = 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_name;
let partitions;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
topic_name = read_compact_string(buf)?;
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(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_name,
partitions,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
write_compact_string(buf, &self.topic_name)?;
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 += compact_string_len(&self.topic_name)?;
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 vote_granted: bool,
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,
vote_granted: false,
_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_vote_granted(mut self, value: bool) -> Self {
self.vote_granted = 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 vote_granted;
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)?;
vote_granted = read_bool(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,
vote_granted,
_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_bool(buf, self.vote_granted);
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 += 1;
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 NodeEndpoint {
pub node_id: i32,
pub host: KafkaString,
pub port: u16,
pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for NodeEndpoint {
fn default() -> Self {
Self {
node_id: 0_i32,
host: KafkaString::default(),
port: 0_u16,
_unknown_tagged_fields: Vec::new(),
}
}
}
impl NodeEndpoint {
pub fn with_node_id(mut self, value: i32) -> Self {
self.node_id = value;
self
}
pub fn with_host(mut self, value: KafkaString) -> Self {
self.host = value;
self
}
pub fn with_port(mut self, value: u16) -> Self {
self.port = value;
self
}
pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
let node_id;
let host;
let port;
let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
node_id = read_i32(buf)?;
host = read_compact_string(buf)?;
port = read_u16(buf)?;
let tagged_fields = read_tagged_fields(buf)?;
for field in &tagged_fields {
match field.tag {
_ => {
_unknown_tagged_fields.push(field.clone());
},
}
}
Ok(Self {
node_id,
host,
port,
_unknown_tagged_fields,
})
}
pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
write_i32(buf, self.node_id);
write_compact_string(buf, &self.host)?;
write_u16(buf, self.port);
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 += compact_string_len(&self.host)?;
len += 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)
}
}