#![allow(
clippy::field_reassign_with_default,
clippy::nonminimal_bool,
clippy::derivable_impls,
clippy::borrow_deref_ref,
clippy::double_parens,
unused_parens
)]
use bytes::{Buf, BufMut};
use crate::budget::{Budget, Limits};
#[allow(unused_imports)]
use crate::error::{DecodeError, EncodeError};
use crate::wire::{self, RawTaggedField};
pub fn is_flexible(version: i16) -> bool {
let _ = version;
version >= 4
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct SyncGroupResponse {
pub throttle_time_ms: i32,
pub error_code: i16,
pub protocol_type: Option<String>,
pub protocol_name: Option<String>,
pub assignment: bytes::Bytes,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for SyncGroupResponse {
fn default() -> Self {
Self {
throttle_time_ms: 0,
error_code: 0,
protocol_type: None,
protocol_name: None,
assignment: bytes::Bytes::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl SyncGroupResponse {
pub const API_KEY: i16 = 14;
pub const MIN_VERSION: i16 = 0;
pub const MAX_VERSION: i16 = 5;
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
if version >= 1 {
buf.put_i32(self.throttle_time_ms);
}
buf.put_i16(self.error_code);
if version >= 5 {
if is_flexible(version) {
wire::put_compact_nullable_string(buf, self.protocol_type.as_deref());
} else {
wire::put_nullable_string(buf, self.protocol_type.as_deref())?;
}
}
if version >= 5 {
if is_flexible(version) {
wire::put_compact_nullable_string(buf, self.protocol_name.as_deref());
} else {
wire::put_nullable_string(buf, self.protocol_name.as_deref())?;
}
}
if is_flexible(version) {
wire::put_compact_bytes(buf, &self.assignment);
} else {
wire::put_bytes(buf, &self.assignment)?;
}
if is_flexible(version) {
wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
}
Ok(())
}
pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
Self::decode_with_limits(buf, version, Limits::default())
}
pub fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
let mut budget = limits.budget(buf.remaining());
Self::decode_with_budget(buf, version, &mut budget)
}
pub fn decode_with_budget(
buf: &mut impl Buf,
version: i16,
budget: &mut Budget,
) -> Result<Self, DecodeError> {
let mut this = Self::default();
if version >= 1 {
this.throttle_time_ms = wire::get_i32(buf)?;
}
this.error_code = wire::get_i16(buf)?;
if version >= 5 {
this.protocol_type = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
}
if version >= 5 {
this.protocol_name = if is_flexible(version) {
wire::get_compact_nullable_string(buf)?
} else {
wire::get_nullable_string(buf)?
};
}
this.assignment = {
let raw = if is_flexible(version) {
wire::get_compact_nullable_bytes(buf)?
} else {
wire::get_nullable_bytes(buf)?
};
match raw {
Some(v) => v,
None => return Err(DecodeError::InvalidLength(-1)),
}
};
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}
impl crate::Message for SyncGroupResponse {
const API_KEY: i16 = 14;
const MIN_VERSION: i16 = 0;
const MAX_VERSION: i16 = 5;
fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
SyncGroupResponse::encode(self, buf, version)
}
fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
SyncGroupResponse::decode(buf, version)
}
fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
SyncGroupResponse::decode_with_limits(buf, version, limits)
}
fn throttle_time_ms(&self) -> Option<i32> {
Some(self.throttle_time_ms)
}
}