// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
use bytes::BufMut;
use crate::primitives::fixed::{get_bool, get_i32, put_bool, put_i32};
use crate::primitives::string_bytes::{
compact_nullable_string_len, compact_string_len, nullable_string_len,
put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
string_len,
};
use crate::primitives::string_bytes_borrowed::{
get_compact_nullable_string_borrowed, get_compact_string_borrowed,
get_nullable_string_borrowed, get_string_borrowed,
};
use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
pub const API_KEY: i16 = 9;
pub const MIN_VERSION: i16 = 1;
pub const MAX_VERSION: i16 = 10;
pub const FLEXIBLE_MIN: i16 = 6;
#[inline]
fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OffsetFetchRequest<'a> {
pub group_id: &'a str,
pub topics: Option<Vec<OffsetFetchRequestTopic<'a>>>,
pub groups: Vec<OffsetFetchRequestGroup<'a>>,
pub require_stable: bool,
pub unknown_tagged_fields: UnknownTaggedFields,
}
impl<'a> Default for OffsetFetchRequest<'a> {
fn default() -> Self {
Self {
group_id: "",
topics: None,
groups: Vec::new(),
require_stable: false,
unknown_tagged_fields: Default::default(),
}
}
}
impl<'a> OffsetFetchRequest<'a> {
pub fn to_owned(&self) -> crate::owned::offset_fetch_request::OffsetFetchRequest {
crate::owned::offset_fetch_request::OffsetFetchRequest {
group_id: (self.group_id).to_string(),
topics: (self.topics).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
groups: (self.groups).iter().map(|it| it.to_owned()).collect(),
require_stable: (self.require_stable),
unknown_tagged_fields: self.unknown_tagged_fields.clone(),
}
}
}
impl<'a> Encode for OffsetFetchRequest<'a> {
fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
}
let flex = is_flexible(version);
if version >= 0 && version <= 7 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
if version >= 0 && version <= 7 { if version >= 2 { { let len = (self.topics).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topics { for it in v { it.encode(buf, version)?; } } } } else { { let v = (self.topics).as_ref().map(Vec::as_slice).unwrap_or(&[]); crate::primitives::array::put_array_len(buf, v.len(), flex); for it in v { it.encode(buf, version)?; } } } }
if version >= 8 { { crate::primitives::array::put_array_len(buf, (self.groups).len(), flex); for it in &self.groups { it.encode(buf, version)?; } } }
if version >= 7 { put_bool(buf, self.require_stable) }
if flex {
let tagged = WriteTaggedFields::new();
tagged.write(buf, &self.unknown_tagged_fields);
}
Ok(())
}
fn encoded_len(&self, version: i16) -> usize {
let flex = is_flexible(version);
let mut n: usize = 0;
if version >= 0 && version <= 7 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
if version >= 0 && version <= 7 { n += if version >= 2 { { let opt: Option<&Vec<_>> = (self.topics).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body } } else { { let v = (self.topics).as_ref().map(Vec::as_slice).unwrap_or(&[]); let prefix = crate::primitives::array::array_len_prefix_len(v.len(), flex); let body: usize = v.iter().map(|it| it.encoded_len(version)).sum(); prefix + body } }; }
if version >= 8 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.groups).len(), flex); let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
if version >= 7 { n += 1; }
if flex {
let known_pairs: Vec<(u32, usize)> = Vec::new();
n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
}
n
}
}
impl<'de> DecodeBorrow<'de> for OffsetFetchRequest<'de> {
fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
}
let flex = is_flexible(version);
let mut out = Self::default();
if version >= 0 && version <= 7 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
if version >= 0 && version <= 7 { out.topics = if version >= 2 { { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(OffsetFetchRequestTopic::decode_borrow(buf, version)?); } Some(v) } } } } else { Some({ let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(OffsetFetchRequestTopic::decode_borrow(buf, version)?); } v }) }; }
if version >= 8 { out.groups = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(OffsetFetchRequestGroup::decode_borrow(buf, version)?); } v }; }
if version >= 7 { out.require_stable = get_bool(buf)?; }
if flex {
out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
Ok(false)
})?;
}
Ok(out)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OffsetFetchRequestTopic<'a> {
pub name: &'a str,
pub partition_indexes: Vec<i32>,
pub unknown_tagged_fields: UnknownTaggedFields,
}
impl<'a> Default for OffsetFetchRequestTopic<'a> {
fn default() -> Self {
Self {
name: "",
partition_indexes: Vec::new(),
unknown_tagged_fields: Default::default(),
}
}
}
impl<'a> OffsetFetchRequestTopic<'a> {
pub fn to_owned(&self) -> crate::owned::offset_fetch_request::OffsetFetchRequestTopic {
crate::owned::offset_fetch_request::OffsetFetchRequestTopic {
name: (self.name).to_string(),
partition_indexes: (self.partition_indexes).clone(),
unknown_tagged_fields: self.unknown_tagged_fields.clone(),
}
}
}
impl<'a> Encode for OffsetFetchRequestTopic<'a> {
fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
let flex = version >= 6;
if version >= 0 && version <= 7 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
if version >= 0 && version <= 7 { { crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex); for it in &self.partition_indexes { put_i32(buf, *it); } } }
if flex {
let tagged = WriteTaggedFields::new();
tagged.write(buf, &self.unknown_tagged_fields);
}
Ok(())
}
fn encoded_len(&self, version: i16) -> usize {
let flex = version >= 6;
let mut n: usize = 0;
if version >= 0 && version <= 7 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
if version >= 0 && version <= 7 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_indexes).len(), flex); let body: usize = (self.partition_indexes).iter().map(|_| 4).sum(); prefix + body }; }
if flex {
let known_pairs: Vec<(u32, usize)> = Vec::new();
n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
}
n
}
}
impl<'de> DecodeBorrow<'de> for OffsetFetchRequestTopic<'de> {
fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
let flex = version >= 6;
let mut out = Self::default();
if version >= 0 && version <= 7 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
if version >= 0 && version <= 7 { out.partition_indexes = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
if flex {
out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
Ok(false)
})?;
}
Ok(out)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OffsetFetchRequestGroup<'a> {
pub group_id: &'a str,
pub member_id: Option<&'a str>,
pub member_epoch: i32,
pub topics: Option<Vec<OffsetFetchRequestTopics<'a>>>,
pub unknown_tagged_fields: UnknownTaggedFields,
}
impl<'a> Default for OffsetFetchRequestGroup<'a> {
fn default() -> Self {
Self {
group_id: "",
member_id: None,
member_epoch: -1i32,
topics: None,
unknown_tagged_fields: Default::default(),
}
}
}
impl<'a> OffsetFetchRequestGroup<'a> {
pub fn to_owned(&self) -> crate::owned::offset_fetch_request::OffsetFetchRequestGroup {
crate::owned::offset_fetch_request::OffsetFetchRequestGroup {
group_id: (self.group_id).to_string(),
member_id: (self.member_id).map(|s| s.to_string()),
member_epoch: (self.member_epoch),
topics: (self.topics).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
unknown_tagged_fields: self.unknown_tagged_fields.clone(),
}
}
}
impl<'a> Encode for OffsetFetchRequestGroup<'a> {
fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
let flex = version >= 6;
if version >= 8 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
if version >= 9 { if flex { put_compact_nullable_string(buf, self.member_id) } else { put_nullable_string(buf, self.member_id) } }
if version >= 9 { put_i32(buf, self.member_epoch) }
if version >= 8 { { let len = (self.topics).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topics { for it in v { it.encode(buf, version)?; } } } }
if flex {
let tagged = WriteTaggedFields::new();
tagged.write(buf, &self.unknown_tagged_fields);
}
Ok(())
}
fn encoded_len(&self, version: i16) -> usize {
let flex = version >= 6;
let mut n: usize = 0;
if version >= 8 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
if version >= 9 { n += if flex { compact_nullable_string_len(self.member_id) } else { nullable_string_len(self.member_id) }; }
if version >= 9 { n += 4; }
if version >= 8 { n += { let opt: Option<&Vec<_>> = (self.topics).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
if flex {
let known_pairs: Vec<(u32, usize)> = Vec::new();
n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
}
n
}
}
impl<'de> DecodeBorrow<'de> for OffsetFetchRequestGroup<'de> {
fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
let flex = version >= 6;
let mut out = Self::default();
if version >= 8 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
if version >= 9 { out.member_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
if version >= 9 { out.member_epoch = get_i32(buf)?; }
if version >= 8 { out.topics = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(OffsetFetchRequestTopics::decode_borrow(buf, version)?); } Some(v) } } }; }
if flex {
out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
Ok(false)
})?;
}
Ok(out)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OffsetFetchRequestTopics<'a> {
pub name: &'a str,
pub topic_id: crate::primitives::uuid::Uuid,
pub partition_indexes: Vec<i32>,
pub unknown_tagged_fields: UnknownTaggedFields,
}
impl<'a> Default for OffsetFetchRequestTopics<'a> {
fn default() -> Self {
Self {
name: "",
topic_id: Default::default(),
partition_indexes: Vec::new(),
unknown_tagged_fields: Default::default(),
}
}
}
impl<'a> OffsetFetchRequestTopics<'a> {
pub fn to_owned(&self) -> crate::owned::offset_fetch_request::OffsetFetchRequestTopics {
crate::owned::offset_fetch_request::OffsetFetchRequestTopics {
name: (self.name).to_string(),
topic_id: (self.topic_id),
partition_indexes: (self.partition_indexes).clone(),
unknown_tagged_fields: self.unknown_tagged_fields.clone(),
}
}
}
impl<'a> Encode for OffsetFetchRequestTopics<'a> {
fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
let flex = version >= 6;
if version >= 8 && version <= 9 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
if version >= 10 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
if version >= 8 { { crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex); for it in &self.partition_indexes { put_i32(buf, *it); } } }
if flex {
let tagged = WriteTaggedFields::new();
tagged.write(buf, &self.unknown_tagged_fields);
}
Ok(())
}
fn encoded_len(&self, version: i16) -> usize {
let flex = version >= 6;
let mut n: usize = 0;
if version >= 8 && version <= 9 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
if version >= 10 { n += 16; }
if version >= 8 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_indexes).len(), flex); let body: usize = (self.partition_indexes).iter().map(|_| 4).sum(); prefix + body }; }
if flex {
let known_pairs: Vec<(u32, usize)> = Vec::new();
n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
}
n
}
}
impl<'de> DecodeBorrow<'de> for OffsetFetchRequestTopics<'de> {
fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
let flex = version >= 6;
let mut out = Self::default();
if version >= 8 && version <= 9 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
if version >= 10 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
if version >= 8 { out.partition_indexes = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
if flex {
out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
Ok(false)
})?;
}
Ok(out)
}
}