#![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 >= 3
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct ApiVersionsRequest {
pub client_software_name: String,
pub client_software_version: String,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for ApiVersionsRequest {
fn default() -> Self {
Self {
client_software_name: String::new(),
client_software_version: String::new(),
unknown_tagged_fields: Vec::new(),
}
}
}
impl ApiVersionsRequest {
pub const API_KEY: i16 = 18;
pub const MIN_VERSION: i16 = 0;
pub const MAX_VERSION: i16 = 4;
pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
if version >= 3 {
if is_flexible(version) {
wire::put_compact_string(buf, &self.client_software_name);
} else {
wire::put_string(buf, &self.client_software_name)?;
}
}
if version >= 3 {
if is_flexible(version) {
wire::put_compact_string(buf, &self.client_software_version);
} else {
wire::put_string(buf, &self.client_software_version)?;
}
}
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 >= 3 {
this.client_software_name = if is_flexible(version) {
wire::get_compact_string(buf)?
} else {
wire::get_string(buf)?
};
}
if version >= 3 {
this.client_software_version = if is_flexible(version) {
wire::get_compact_string(buf)?
} else {
wire::get_string(buf)?
};
}
if is_flexible(version) {
this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
}
Ok(this)
}
}
impl crate::Message for ApiVersionsRequest {
const API_KEY: i16 = 18;
const MIN_VERSION: i16 = 0;
const MAX_VERSION: i16 = 4;
fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
ApiVersionsRequest::encode(self, buf, version)
}
fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
ApiVersionsRequest::decode(buf, version)
}
fn decode_with_limits(
buf: &mut impl Buf,
version: i16,
limits: Limits,
) -> Result<Self, DecodeError> {
ApiVersionsRequest::decode_with_limits(buf, version, limits)
}
}