use std::fmt::Debug;
use std::marker::PhantomData;
use crate::Isolation;
use crate::api::Request;
use crate::core::Decoder;
use crate::core::Encoder;
use crate::derive::Decode;
use crate::derive::Encode;
use crate::derive::FluvioDefault;
use crate::record::RecordSet;
use super::FetchResponse;
pub type DefaultFetchRequest = FetchRequest<RecordSet>;
#[derive(Encode, Decode, FluvioDefault, Debug)]
pub struct FetchRequest<R>
where
R: Encoder + Decoder + Default + Debug,
{
pub max_wait: i32,
pub min_bytes: i32,
#[fluvio(min_version = 3, ignorable)]
pub max_bytes: i32,
#[fluvio(min_version = 4)]
pub isolation_level: Isolation,
pub topics: Vec<FetchableTopic>,
#[fluvio(min_version = 7)]
pub forgotten: Vec<ForgottenTopic>,
pub data: PhantomData<R>,
}
impl<R> Request for FetchRequest<R>
where
R: Debug + Decoder + Encoder,
{
const API_KEY: u16 = 1;
const MIN_API_VERSION: i16 = 0;
const MAX_API_VERSION: i16 = 10;
const DEFAULT_API_VERSION: i16 = 10;
type Response = FetchResponse<R>;
}
#[derive(Encode, Decode, FluvioDefault, Debug)]
pub struct FetchableTopic {
pub name: String,
pub fetch_partitions: Vec<FetchPartition>,
}
#[derive(Encode, Decode, FluvioDefault, Debug)]
pub struct ForgottenTopic {
#[fluvio(min_version = 7)]
pub name: String,
#[fluvio(min_version = 7)]
pub forgotten_partition_indexes: Vec<i32>,
}
#[derive(Encode, Decode, FluvioDefault, Debug)]
pub struct FetchPartition {
pub partition_index: i32,
#[fluvio(min_version = 9, ignorable)]
pub current_leader_epoch: i32,
pub fetch_offset: i64,
#[fluvio(min_version = 5)]
pub log_start_offset: i64,
pub max_bytes: i32,
}
#[cfg(feature = "file")]
pub use file::*;
#[cfg(feature = "file")]
mod file {
use super::*;
use crate::record::FileRecordSet;
pub type FileFetchRequest = FetchRequest<FileRecordSet>;
}