use byteorder::ReadBytesExt;
use crate::codec::*;
use crate::IoResult;
#[derive(Debug, Default, Clone)]
pub struct JoinGroupRequest {
pub group_id: String,
pub session_timeout_ms: i32,
pub rebalance_timeout_ms: i32,
pub member_id: String,
pub group_instance_id: Option<String>,
pub protocol_type: String,
pub protocols: Vec<JoinGroupRequestProtocol>,
pub reason: Option<String>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for JoinGroupRequest {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
let mut this = JoinGroupRequest {
group_id: NullableString(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("group_id"))?,
session_timeout_ms: Int32.decode(buf)?,
..Default::default()
};
this.rebalance_timeout_ms = if version >= 1 { Int32.decode(buf)? } else { -1 };
this.member_id = NullableString(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("member_id"))?;
if version >= 5 {
this.group_instance_id = NullableString(version >= 6).decode(buf)?;
}
this.protocol_type = NullableString(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("protocol_type"))?;
this.protocols = NullableArray(Struct(version), version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("protocols"))?;
if version >= 8 {
this.reason = NullableString(true).decode(buf)?;
}
if version >= 6 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}
#[derive(Debug, Default, Clone)]
pub struct JoinGroupRequestProtocol {
pub name: String,
pub metadata: Vec<u8>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for JoinGroupRequestProtocol {
fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
if version > 9 {
Err(err_decode_message_unsupported(
version,
"JoinGroupRequestProtocol",
))?
}
let mut this = JoinGroupRequestProtocol {
name: NullableString(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("name"))?,
metadata: NullableBytes(version >= 6)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("metadata"))?,
..Default::default()
};
if version >= 6 {
this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(this)
}
}