#![allow(unused)]
use std::borrow::Borrow;
use std::collections::BTreeMap;
use anyhow::{bail, Result};
use bytes::Bytes;
use uuid::Uuid;
use crate::protocol::{
buf::{ByteBuf, ByteBufMut},
compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
};
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct DescribeConfigsResourceResult {
pub name: StrBytes,
pub value: Option<StrBytes>,
pub read_only: bool,
pub is_default: bool,
pub config_source: i8,
pub is_sensitive: bool,
pub synonyms: Vec<DescribeConfigsSynonym>,
pub config_type: i8,
pub documentation: Option<StrBytes>,
pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
}
impl DescribeConfigsResourceResult {
pub fn with_name(mut self, value: StrBytes) -> Self {
self.name = value;
self
}
pub fn with_value(mut self, value: Option<StrBytes>) -> Self {
self.value = value;
self
}
pub fn with_read_only(mut self, value: bool) -> Self {
self.read_only = value;
self
}
pub fn with_is_default(mut self, value: bool) -> Self {
self.is_default = value;
self
}
pub fn with_config_source(mut self, value: i8) -> Self {
self.config_source = value;
self
}
pub fn with_is_sensitive(mut self, value: bool) -> Self {
self.is_sensitive = value;
self
}
pub fn with_synonyms(mut self, value: Vec<DescribeConfigsSynonym>) -> Self {
self.synonyms = value;
self
}
pub fn with_config_type(mut self, value: i8) -> Self {
self.config_type = value;
self
}
pub fn with_documentation(mut self, value: Option<StrBytes>) -> Self {
self.documentation = value;
self
}
pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
self.unknown_tagged_fields = value;
self
}
pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
self.unknown_tagged_fields.insert(key, value);
self
}
}
#[cfg(feature = "broker")]
impl Encodable for DescribeConfigsResourceResult {
fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
if version >= 4 {
types::CompactString.encode(buf, &self.name)?;
} else {
types::String.encode(buf, &self.name)?;
}
if version >= 4 {
types::CompactString.encode(buf, &self.value)?;
} else {
types::String.encode(buf, &self.value)?;
}
types::Boolean.encode(buf, &self.read_only)?;
if version == 0 {
types::Boolean.encode(buf, &self.is_default)?;
} else {
if self.is_default {
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 1 {
types::Int8.encode(buf, &self.config_source)?;
}
types::Boolean.encode(buf, &self.is_sensitive)?;
if version >= 1 {
if version >= 4 {
types::CompactArray(types::Struct { version }).encode(buf, &self.synonyms)?;
} else {
types::Array(types::Struct { version }).encode(buf, &self.synonyms)?;
}
}
if version >= 3 {
types::Int8.encode(buf, &self.config_type)?;
}
if version >= 3 {
if version >= 4 {
types::CompactString.encode(buf, &self.documentation)?;
} else {
types::String.encode(buf, &self.documentation)?;
}
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
}
Ok(())
}
fn compute_size(&self, version: i16) -> Result<usize> {
let mut total_size = 0;
if version >= 4 {
total_size += types::CompactString.compute_size(&self.name)?;
} else {
total_size += types::String.compute_size(&self.name)?;
}
if version >= 4 {
total_size += types::CompactString.compute_size(&self.value)?;
} else {
total_size += types::String.compute_size(&self.value)?;
}
total_size += types::Boolean.compute_size(&self.read_only)?;
if version == 0 {
total_size += types::Boolean.compute_size(&self.is_default)?;
} else {
if self.is_default {
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 1 {
total_size += types::Int8.compute_size(&self.config_source)?;
}
total_size += types::Boolean.compute_size(&self.is_sensitive)?;
if version >= 1 {
if version >= 4 {
total_size +=
types::CompactArray(types::Struct { version }).compute_size(&self.synonyms)?;
} else {
total_size +=
types::Array(types::Struct { version }).compute_size(&self.synonyms)?;
}
}
if version >= 3 {
total_size += types::Int8.compute_size(&self.config_type)?;
}
if version >= 3 {
if version >= 4 {
total_size += types::CompactString.compute_size(&self.documentation)?;
} else {
total_size += types::String.compute_size(&self.documentation)?;
}
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
}
Ok(total_size)
}
}
#[cfg(feature = "client")]
impl Decodable for DescribeConfigsResourceResult {
fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
let name = if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
};
let value = if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
};
let read_only = types::Boolean.decode(buf)?;
let is_default = if version == 0 {
types::Boolean.decode(buf)?
} else {
false
};
let config_source = if version >= 1 {
types::Int8.decode(buf)?
} else {
-1
};
let is_sensitive = types::Boolean.decode(buf)?;
let synonyms = if version >= 1 {
if version >= 4 {
types::CompactArray(types::Struct { version }).decode(buf)?
} else {
types::Array(types::Struct { version }).decode(buf)?
}
} else {
Default::default()
};
let config_type = if version >= 3 {
types::Int8.decode(buf)?
} else {
0
};
let documentation = if version >= 3 {
if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
}
} else {
Some(Default::default())
};
let mut unknown_tagged_fields = BTreeMap::new();
if version >= 4 {
let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
for _ in 0..num_tagged_fields {
let tag: u32 = types::UnsignedVarInt.decode(buf)?;
let size: u32 = types::UnsignedVarInt.decode(buf)?;
let unknown_value = buf.try_get_bytes(size as usize)?;
unknown_tagged_fields.insert(tag as i32, unknown_value);
}
}
Ok(Self {
name,
value,
read_only,
is_default,
config_source,
is_sensitive,
synonyms,
config_type,
documentation,
unknown_tagged_fields,
})
}
}
impl Default for DescribeConfigsResourceResult {
fn default() -> Self {
Self {
name: Default::default(),
value: Some(Default::default()),
read_only: false,
is_default: false,
config_source: -1,
is_sensitive: false,
synonyms: Default::default(),
config_type: 0,
documentation: Some(Default::default()),
unknown_tagged_fields: BTreeMap::new(),
}
}
}
impl Message for DescribeConfigsResourceResult {
const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
const DEPRECATED_VERSIONS: Option<VersionRange> = None;
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct DescribeConfigsResponse {
pub throttle_time_ms: i32,
pub results: Vec<DescribeConfigsResult>,
pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
}
impl DescribeConfigsResponse {
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<DescribeConfigsResult>) -> Self {
self.results = value;
self
}
pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
self.unknown_tagged_fields = value;
self
}
pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
self.unknown_tagged_fields.insert(key, value);
self
}
}
#[cfg(feature = "broker")]
impl Encodable for DescribeConfigsResponse {
fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
types::Int32.encode(buf, &self.throttle_time_ms)?;
if version >= 4 {
types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
} else {
types::Array(types::Struct { version }).encode(buf, &self.results)?;
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
}
Ok(())
}
fn compute_size(&self, version: i16) -> Result<usize> {
let mut total_size = 0;
total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
if version >= 4 {
total_size +=
types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
} else {
total_size += types::Array(types::Struct { version }).compute_size(&self.results)?;
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
}
Ok(total_size)
}
}
#[cfg(feature = "client")]
impl Decodable for DescribeConfigsResponse {
fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
let throttle_time_ms = types::Int32.decode(buf)?;
let results = if version >= 4 {
types::CompactArray(types::Struct { version }).decode(buf)?
} else {
types::Array(types::Struct { version }).decode(buf)?
};
let mut unknown_tagged_fields = BTreeMap::new();
if version >= 4 {
let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
for _ in 0..num_tagged_fields {
let tag: u32 = types::UnsignedVarInt.decode(buf)?;
let size: u32 = types::UnsignedVarInt.decode(buf)?;
let unknown_value = buf.try_get_bytes(size as usize)?;
unknown_tagged_fields.insert(tag as i32, unknown_value);
}
}
Ok(Self {
throttle_time_ms,
results,
unknown_tagged_fields,
})
}
}
impl Default for DescribeConfigsResponse {
fn default() -> Self {
Self {
throttle_time_ms: 0,
results: Default::default(),
unknown_tagged_fields: BTreeMap::new(),
}
}
}
impl Message for DescribeConfigsResponse {
const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
const DEPRECATED_VERSIONS: Option<VersionRange> = None;
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct DescribeConfigsResult {
pub error_code: i16,
pub error_message: Option<StrBytes>,
pub resource_type: i8,
pub resource_name: StrBytes,
pub configs: Vec<DescribeConfigsResourceResult>,
pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
}
impl DescribeConfigsResult {
pub fn with_error_code(mut self, value: i16) -> Self {
self.error_code = value;
self
}
pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
self.error_message = value;
self
}
pub fn with_resource_type(mut self, value: i8) -> Self {
self.resource_type = value;
self
}
pub fn with_resource_name(mut self, value: StrBytes) -> Self {
self.resource_name = value;
self
}
pub fn with_configs(mut self, value: Vec<DescribeConfigsResourceResult>) -> Self {
self.configs = value;
self
}
pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
self.unknown_tagged_fields = value;
self
}
pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
self.unknown_tagged_fields.insert(key, value);
self
}
}
#[cfg(feature = "broker")]
impl Encodable for DescribeConfigsResult {
fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
types::Int16.encode(buf, &self.error_code)?;
if version >= 4 {
types::CompactString.encode(buf, &self.error_message)?;
} else {
types::String.encode(buf, &self.error_message)?;
}
types::Int8.encode(buf, &self.resource_type)?;
if version >= 4 {
types::CompactString.encode(buf, &self.resource_name)?;
} else {
types::String.encode(buf, &self.resource_name)?;
}
if version >= 4 {
types::CompactArray(types::Struct { version }).encode(buf, &self.configs)?;
} else {
types::Array(types::Struct { version }).encode(buf, &self.configs)?;
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
}
Ok(())
}
fn compute_size(&self, version: i16) -> Result<usize> {
let mut total_size = 0;
total_size += types::Int16.compute_size(&self.error_code)?;
if version >= 4 {
total_size += types::CompactString.compute_size(&self.error_message)?;
} else {
total_size += types::String.compute_size(&self.error_message)?;
}
total_size += types::Int8.compute_size(&self.resource_type)?;
if version >= 4 {
total_size += types::CompactString.compute_size(&self.resource_name)?;
} else {
total_size += types::String.compute_size(&self.resource_name)?;
}
if version >= 4 {
total_size +=
types::CompactArray(types::Struct { version }).compute_size(&self.configs)?;
} else {
total_size += types::Array(types::Struct { version }).compute_size(&self.configs)?;
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
}
Ok(total_size)
}
}
#[cfg(feature = "client")]
impl Decodable for DescribeConfigsResult {
fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
let error_code = types::Int16.decode(buf)?;
let error_message = if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
};
let resource_type = types::Int8.decode(buf)?;
let resource_name = if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
};
let configs = if version >= 4 {
types::CompactArray(types::Struct { version }).decode(buf)?
} else {
types::Array(types::Struct { version }).decode(buf)?
};
let mut unknown_tagged_fields = BTreeMap::new();
if version >= 4 {
let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
for _ in 0..num_tagged_fields {
let tag: u32 = types::UnsignedVarInt.decode(buf)?;
let size: u32 = types::UnsignedVarInt.decode(buf)?;
let unknown_value = buf.try_get_bytes(size as usize)?;
unknown_tagged_fields.insert(tag as i32, unknown_value);
}
}
Ok(Self {
error_code,
error_message,
resource_type,
resource_name,
configs,
unknown_tagged_fields,
})
}
}
impl Default for DescribeConfigsResult {
fn default() -> Self {
Self {
error_code: 0,
error_message: Some(Default::default()),
resource_type: 0,
resource_name: Default::default(),
configs: Default::default(),
unknown_tagged_fields: BTreeMap::new(),
}
}
}
impl Message for DescribeConfigsResult {
const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
const DEPRECATED_VERSIONS: Option<VersionRange> = None;
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct DescribeConfigsSynonym {
pub name: StrBytes,
pub value: Option<StrBytes>,
pub source: i8,
pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
}
impl DescribeConfigsSynonym {
pub fn with_name(mut self, value: StrBytes) -> Self {
self.name = value;
self
}
pub fn with_value(mut self, value: Option<StrBytes>) -> Self {
self.value = value;
self
}
pub fn with_source(mut self, value: i8) -> Self {
self.source = value;
self
}
pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
self.unknown_tagged_fields = value;
self
}
pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
self.unknown_tagged_fields.insert(key, value);
self
}
}
#[cfg(feature = "broker")]
impl Encodable for DescribeConfigsSynonym {
fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
if version >= 1 {
if version >= 4 {
types::CompactString.encode(buf, &self.name)?;
} else {
types::String.encode(buf, &self.name)?;
}
} else {
if !self.name.is_empty() {
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 1 {
if version >= 4 {
types::CompactString.encode(buf, &self.value)?;
} else {
types::String.encode(buf, &self.value)?;
}
} else {
if !self
.value
.as_ref()
.map(|x| x.is_empty())
.unwrap_or_default()
{
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 1 {
types::Int8.encode(buf, &self.source)?;
} else {
if self.source != 0 {
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
}
Ok(())
}
fn compute_size(&self, version: i16) -> Result<usize> {
let mut total_size = 0;
if version >= 1 {
if version >= 4 {
total_size += types::CompactString.compute_size(&self.name)?;
} else {
total_size += types::String.compute_size(&self.name)?;
}
} else {
if !self.name.is_empty() {
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 1 {
if version >= 4 {
total_size += types::CompactString.compute_size(&self.value)?;
} else {
total_size += types::String.compute_size(&self.value)?;
}
} else {
if !self
.value
.as_ref()
.map(|x| x.is_empty())
.unwrap_or_default()
{
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 1 {
total_size += types::Int8.compute_size(&self.source)?;
} else {
if self.source != 0 {
bail!("A field is set that is not available on the selected protocol version");
}
}
if version >= 4 {
let num_tagged_fields = self.unknown_tagged_fields.len();
if num_tagged_fields > std::u32::MAX as usize {
bail!(
"Too many tagged fields to encode ({} fields)",
num_tagged_fields
);
}
total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
}
Ok(total_size)
}
}
#[cfg(feature = "client")]
impl Decodable for DescribeConfigsSynonym {
fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
let name = if version >= 1 {
if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
}
} else {
Default::default()
};
let value = if version >= 1 {
if version >= 4 {
types::CompactString.decode(buf)?
} else {
types::String.decode(buf)?
}
} else {
Some(Default::default())
};
let source = if version >= 1 {
types::Int8.decode(buf)?
} else {
0
};
let mut unknown_tagged_fields = BTreeMap::new();
if version >= 4 {
let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
for _ in 0..num_tagged_fields {
let tag: u32 = types::UnsignedVarInt.decode(buf)?;
let size: u32 = types::UnsignedVarInt.decode(buf)?;
let unknown_value = buf.try_get_bytes(size as usize)?;
unknown_tagged_fields.insert(tag as i32, unknown_value);
}
}
Ok(Self {
name,
value,
source,
unknown_tagged_fields,
})
}
}
impl Default for DescribeConfigsSynonym {
fn default() -> Self {
Self {
name: Default::default(),
value: Some(Default::default()),
source: 0,
unknown_tagged_fields: BTreeMap::new(),
}
}
}
impl Message for DescribeConfigsSynonym {
const VERSIONS: VersionRange = VersionRange { min: 0, max: 4 };
const DEPRECATED_VERSIONS: Option<VersionRange> = None;
}
impl HeaderVersion for DescribeConfigsResponse {
fn header_version(version: i16) -> i16 {
if version >= 4 {
1
} else {
0
}
}
}