#![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 >= 3
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct AddPartitionsToTxnResponse {
pub throttle_time_ms: i32,
pub error_code: i16,
pub results_by_transaction: Vec<AddPartitionsToTxnResult>,
pub results_by_topic_v3_and_below: Vec<AddPartitionsToTxnTopicResult>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AddPartitionsToTxnResponse {
fn default() -> Self {
Self {
throttle_time_ms: 0,
error_code: 0,
results_by_transaction: Vec::new(),
results_by_topic_v3_and_below: Vec::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl AddPartitionsToTxnResponse {
pub const API_KEY: i16 = 24;
pub const MIN_VERSION: i16 = 0;
pub const MAX_VERSION: i16 = 5;
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
buf.put_i32(self.throttle_time_ms);
if version >= 4 {
buf.put_i16(self.error_code);
}
if version >= 4 {
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.results_by_transaction.len()));
} else {
wire::put_array_len(buf, Some(self.results_by_transaction.len()))?;
}
for item in &self.results_by_transaction {
item.encode(buf, version)?;
}
}
if version <= 3 {
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.results_by_topic_v3_and_below.len()));
} else {
wire::put_array_len(buf, Some(self.results_by_topic_v3_and_below.len()))?;
}
for item in &self.results_by_topic_v3_and_below {
item.encode(buf, version)?;
}
}
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();
this.throttle_time_ms = wire::get_i32(buf)?;
if version >= 4 {
this.error_code = wire::get_i16(buf)?;
}
if version >= 4 {
this.results_by_transaction = {
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 =
AddPartitionsToTxnResult::decode_with_budget(buf, version, budget)?;
budget.progress(mark, buf.remaining())?;
budget.push(&mut items, item)?;
}
items
}
}
};
}
if version <= 3 {
this.results_by_topic_v3_and_below = {
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 = AddPartitionsToTxnTopicResult::decode_with_budget(
buf, version, budget,
)?;
budget.progress(mark, buf.remaining())?;
budget.push(&mut items, item)?;
}
items
}
}
};
}
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}
impl crate::Message for AddPartitionsToTxnResponse {
const API_KEY: i16 = 24;
const MIN_VERSION: i16 = 0;
const MAX_VERSION: i16 = 5;
fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
AddPartitionsToTxnResponse::encode(self, buf, version)
}
fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
AddPartitionsToTxnResponse::decode(buf, version)
}
fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
AddPartitionsToTxnResponse::decode_with_limits(buf, version, limits)
}
fn throttle_time_ms(&self) -> Option<i32> {
Some(self.throttle_time_ms)
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct AddPartitionsToTxnResult {
pub transactional_id: String,
pub topic_results: Vec<AddPartitionsToTxnTopicResult>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AddPartitionsToTxnResult {
fn default() -> Self {
Self {
transactional_id: String::new(),
topic_results: Vec::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl AddPartitionsToTxnResult {
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
if version >= 4 {
if is_flexible(version) {
wire::put_compact_string(buf, &self.transactional_id);
} else {
wire::put_string(buf, &self.transactional_id)?;
}
}
if version >= 4 {
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.topic_results.len()));
} else {
wire::put_array_len(buf, Some(self.topic_results.len()))?;
}
for item in &self.topic_results {
item.encode(buf, version)?;
}
}
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 >= 4 {
this.transactional_id = if is_flexible(version) {
wire::get_compact_string(buf)?
} else {
wire::get_string(buf)?
};
}
if version >= 4 {
this.topic_results = {
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 = AddPartitionsToTxnTopicResult::decode_with_budget(
buf, version, budget,
)?;
budget.progress(mark, buf.remaining())?;
budget.push(&mut items, item)?;
}
items
}
}
};
}
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct AddPartitionsToTxnTopicResult {
pub name: String,
pub results_by_partition: Vec<AddPartitionsToTxnPartitionResult>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AddPartitionsToTxnTopicResult {
fn default() -> Self {
Self {
name: String::new(),
results_by_partition: Vec::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl AddPartitionsToTxnTopicResult {
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
if is_flexible(version) {
wire::put_compact_string(buf, &self.name);
} else {
wire::put_string(buf, &self.name)?;
}
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.results_by_partition.len()));
} else {
wire::put_array_len(buf, Some(self.results_by_partition.len()))?;
}
for item in &self.results_by_partition {
item.encode(buf, version)?;
}
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();
this.name = if is_flexible(version) {
wire::get_compact_string(buf)?
} else {
wire::get_string(buf)?
};
this.results_by_partition = {
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 = AddPartitionsToTxnPartitionResult::decode_with_budget(
buf, version, budget,
)?;
budget.progress(mark, buf.remaining())?;
budget.push(&mut items, item)?;
}
items
}
}
};
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct AddPartitionsToTxnPartitionResult {
pub partition_index: i32,
pub partition_error_code: i16,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for AddPartitionsToTxnPartitionResult {
fn default() -> Self {
Self {
partition_index: 0,
partition_error_code: 0,
unknown_tagged_fields: Vec::new(),
}
}
}
impl AddPartitionsToTxnPartitionResult {
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
buf.put_i32(self.partition_index);
buf.put_i16(self.partition_error_code);
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();
this.partition_index = wire::get_i32(buf)?;
this.partition_error_code = wire::get_i16(buf)?;
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}