use fluvio_protocol::Encoder;
use fluvio_protocol::Decoder;
use fluvio_protocol::derive::FluvioDefault;
use fluvio_protocol::link::ErrorCode;
use fluvio_types::PartitionId;
#[derive(Encoder, Decoder, FluvioDefault, Debug)]
pub struct ProduceResponse {
pub responses: Vec<TopicProduceResponse>,
#[fluvio(min_version = 1, ignorable)]
pub throttle_time_ms: i32,
}
impl ProduceResponse {
pub fn find_partition_response(
&self,
topic: &str,
partition: u32,
) -> Option<&PartitionProduceResponse> {
if let Some(response) = self
.responses
.iter()
.find(|response| response.name == topic)
{
response
.partitions
.iter()
.find(|part_response| part_response.partition_index == partition)
} else {
None
}
}
}
#[derive(Encoder, Decoder, FluvioDefault, Debug)]
pub struct TopicProduceResponse {
pub name: String,
pub partitions: Vec<PartitionProduceResponse>,
}
#[derive(Encoder, Decoder, FluvioDefault, Debug)]
pub struct PartitionProduceResponse {
pub partition_index: PartitionId,
pub error_code: ErrorCode,
pub base_offset: i64,
#[fluvio(min_version = 2, ignorable)]
pub log_append_time_ms: i64,
#[fluvio(min_version = 5, ignorable)]
pub log_start_offset: i64,
}