#![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 DescribeConfigsResponse {
pub throttle_time_ms: i32,
pub results: Vec<DescribeConfigsResult>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for DescribeConfigsResponse {
fn default() -> Self {
Self {
throttle_time_ms: 0,
results: Vec::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl DescribeConfigsResponse {
pub const API_KEY: i16 = 32;
pub const MIN_VERSION: i16 = 1;
pub const MAX_VERSION: i16 = 4;
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
buf.put_i32(self.throttle_time_ms);
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.results.len()));
} else {
wire::put_array_len(buf, Some(self.results.len()))?;
}
for item in &self.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();
this.throttle_time_ms = wire::get_i32(buf)?;
this.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 = DescribeConfigsResult::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 DescribeConfigsResponse {
const API_KEY: i16 = 32;
const MIN_VERSION: i16 = 1;
const MAX_VERSION: i16 = 4;
fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
DescribeConfigsResponse::encode(self, buf, version)
}
fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
DescribeConfigsResponse::decode(buf, version)
}
fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
DescribeConfigsResponse::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 DescribeConfigsResult {
pub error_code: i16,
pub error_message: Option<String>,
pub resource_type: i8,
pub resource_name: String,
pub configs: Vec<DescribeConfigsResourceResult>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for DescribeConfigsResult {
fn default() -> Self {
Self {
error_code: 0,
error_message: Some(String::new()),
resource_type: 0,
resource_name: String::new(),
configs: Vec::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl DescribeConfigsResult {
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
buf.put_i16(self.error_code);
if is_flexible(version) {
wire::put_compact_nullable_string(buf, self.error_message.as_deref());
} else {
wire::put_nullable_string(buf, self.error_message.as_deref())?;
}
buf.put_i8(self.resource_type);
if is_flexible(version) {
wire::put_compact_string(buf, &self.resource_name);
} else {
wire::put_string(buf, &self.resource_name)?;
}
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.configs.len()));
} else {
wire::put_array_len(buf, Some(self.configs.len()))?;
}
for item in &self.configs {
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.error_code = wire::get_i16(buf)?;
this.error_message = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
this.resource_type = wire::get_i8(buf)?;
this.resource_name = if is_flexible(version) {
wire::get_compact_string(buf)?
} else {
wire::get_string(buf)?
};
this.configs = {
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 = DescribeConfigsResourceResult::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 DescribeConfigsResourceResult {
pub name: String,
pub value: Option<String>,
pub read_only: bool,
pub config_source: i8,
pub is_sensitive: bool,
pub synonyms: Vec<DescribeConfigsSynonym>,
pub config_type: i8,
pub documentation: Option<String>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for DescribeConfigsResourceResult {
fn default() -> Self {
Self {
name: String::new(),
value: Some(String::new()),
read_only: false,
config_source: -1,
is_sensitive: false,
synonyms: Vec::new(),
config_type: 0,
documentation: Some(String::new()),
unknown_tagged_fields: Vec::new(),
}
}
}
impl DescribeConfigsResourceResult {
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_nullable_string(buf, self.value.as_deref());
} else {
wire::put_nullable_string(buf, self.value.as_deref())?;
}
buf.put_u8(u8::from(self.read_only));
buf.put_i8(self.config_source);
buf.put_u8(u8::from(self.is_sensitive));
if is_flexible(version) {
wire::put_compact_array_len(buf, Some(self.synonyms.len()));
} else {
wire::put_array_len(buf, Some(self.synonyms.len()))?;
}
for item in &self.synonyms {
item.encode(buf, version)?;
}
if version >= 3 {
buf.put_i8(self.config_type);
}
if version >= 3 {
if is_flexible(version) {
wire::put_compact_nullable_string(buf, self.documentation.as_deref());
} else {
wire::put_nullable_string(buf, self.documentation.as_deref())?;
}
}
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.value = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
this.read_only = wire::get_bool(buf)?;
this.config_source = wire::get_i8(buf)?;
this.is_sensitive = wire::get_bool(buf)?;
this.synonyms = {
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 =
DescribeConfigsSynonym::decode_with_budget(buf, version, budget)?;
budget.progress(mark, buf.remaining())?;
budget.push(&mut items, item)?;
}
items
}
}
};
if version >= 3 {
this.config_type = wire::get_i8(buf)?;
}
if version >= 3 {
this.documentation = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
}
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 DescribeConfigsSynonym {
pub name: String,
pub value: Option<String>,
pub source: i8,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for DescribeConfigsSynonym {
fn default() -> Self {
Self {
name: String::new(),
value: Some(String::new()),
source: 0,
unknown_tagged_fields: Vec::new(),
}
}
}
impl DescribeConfigsSynonym {
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_nullable_string(buf, self.value.as_deref());
} else {
wire::put_nullable_string(buf, self.value.as_deref())?;
}
buf.put_i8(self.source);
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.value = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
this.source = wire::get_i8(buf)?;
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}