use byteorder::WriteBytesExt;
use crate::codec::*;
use crate::IoResult;
#[derive(Debug, Default, Clone)]
pub struct SyncGroupResponse {
pub throttle_time_ms: i32,
pub error_code: i16,
pub protocol_type: Option<String>,
pub protocol_name: Option<String>,
pub assignment: Vec<u8>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Encodable for SyncGroupResponse {
fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
if version >= 1 {
Int32.encode(buf, self.throttle_time_ms)?;
}
Int16.encode(buf, self.error_code)?;
if version >= 5 {
NullableString(true).encode(buf, self.protocol_type.as_deref())?;
NullableString(true).encode(buf, self.protocol_name.as_deref())?;
}
NullableBytes(version >= 4).encode(buf, &self.assignment)?;
if version >= 4 {
RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
}
Ok(())
}
fn calculate_size(&self, version: i16) -> usize {
let mut res = 0;
if version >= 1 {
res += Int32::SIZE; }
res += Int16::SIZE; if version >= 5 {
res += NullableString(true).calculate_size(self.protocol_type.as_deref());
res += NullableString(true).calculate_size(self.protocol_name.as_deref());
}
res += NullableBytes(version >= 4).calculate_size(&self.assignment);
if version >= 4 {
res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
}
res
}
}