use byteorder::ReadBytesExt;
use crate::codec::*;
use crate::IoResult;
#[derive(Debug, Default, Clone)]
pub struct MetadataRequest {
pub topics: Option<Vec<MetadataRequestTopic>>,
pub allow_auto_topic_creation: bool,
pub include_cluster_authorized_operations: bool,
pub include_topic_authorized_operations: bool,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for MetadataRequest {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
let mut this = MetadataRequest::default();
if version >= 1 {
this.topics = NullableArray(Struct(version), version >= 9).decode(buf)?;
} else {
let topics = NullableArray(Struct(version), version >= 9)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("topics"))?;
this.topics = if topics.is_empty() {
None
} else {
Some(topics)
};
}
if version >= 4 {
this.allow_auto_topic_creation = Bool.decode(buf)?;
} else {
this.allow_auto_topic_creation = true;
};
if (8..=10).contains(&version) {
this.include_cluster_authorized_operations = Bool.decode(buf)?;
}
if version >= 9 {
this.include_topic_authorized_operations = Bool.decode(buf)?;
}
if version >= 9 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}
#[derive(Debug, Default, Clone)]
pub struct MetadataRequestTopic {
pub topic_id: uuid::Uuid,
pub name: Option<String>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for MetadataRequestTopic {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
if version > 12 {
Err(err_decode_message_unsupported(
version,
"MetadataRequestTopic",
))?
}
let mut this = MetadataRequestTopic::default();
if version >= 10 {
this.topic_id = Uuid.decode(buf)?;
}
this.name = if version >= 10 {
NullableString(true).decode(buf)?
} else {
Some(
NullableString(version >= 9)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("name"))?,
)
};
if version >= 9 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}