use byteorder::ReadBytesExt;
use crate::codec::*;
use crate::IoResult;
#[derive(Debug, Default, Clone)]
pub struct OffsetFetchRequest {
pub group_id: String,
pub topics: Vec<OffsetFetchRequestTopic>,
pub groups: Vec<OffsetFetchRequestGroup>,
pub require_stable: bool,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for OffsetFetchRequest {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
let mut this = OffsetFetchRequest::default();
if version <= 7 {
this.group_id = NullableString(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("groups"))?;
this.topics = NullableArray(Struct(version), version >= 6)
.decode(buf)?
.or_else(|| if version >= 2 { Some(vec![]) } else { None })
.ok_or_else(|| err_decode_message_null("topics"))?;
}
if version >= 8 {
this.groups = NullableArray(Struct(version), true)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("groups"))?;
}
if version >= 7 {
this.require_stable = Bool.decode(buf)?;
}
if version >= 6 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}
#[derive(Debug, Default, Clone)]
pub struct OffsetFetchRequestTopic {
pub name: String,
pub partition_indexes: Vec<i32>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for OffsetFetchRequestTopic {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
let mut this = OffsetFetchRequestTopic {
name: NullableString(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("name"))?,
partition_indexes: NullableArray(Int32, version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("partition_indexes"))?,
..Default::default()
};
if version >= 6 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}
#[derive(Debug, Default, Clone)]
pub struct OffsetFetchRequestGroup {
pub group_id: String,
pub topics: Vec<OffsetFetchRequestTopic>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for OffsetFetchRequestGroup {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
if version > 8 {
Err(err_decode_message_unsupported(
version,
"OffsetFetchRequestGroup",
))?
}
let mut this = OffsetFetchRequestGroup {
group_id: NullableString(true)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("group_id"))?,
topics: NullableArray(Struct(version), true)
.decode(buf)?
.unwrap_or_default(),
..Default::default()
};
if version >= 6 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}