fluvio_dataplane_protocol/produce/
response.rs

1use crate::core::Encoder;
2use crate::core::Decoder;
3use crate::derive::FluvioDefault;
4
5use crate::ErrorCode;
6
7#[derive(Encoder, Decoder, FluvioDefault, Debug)]
8pub struct ProduceResponse {
9    /// Each produce response
10    pub responses: Vec<TopicProduceResponse>,
11
12    /// The duration in milliseconds for which the request was throttled due to a quota violation,
13    /// or zero if the request did not violate any quota.
14    #[fluvio(min_version = 1, ignorable)]
15    pub throttle_time_ms: i32,
16}
17
18impl ProduceResponse {
19    /// Find partition in Response
20    pub fn find_partition_response(
21        &self,
22        topic: &str,
23        partition: i32,
24    ) -> Option<&PartitionProduceResponse> {
25        if let Some(response) = self
26            .responses
27            .iter()
28            .find(|response| response.name == topic)
29        {
30            response
31                .partitions
32                .iter()
33                .find(|part_response| part_response.partition_index == partition)
34        } else {
35            None
36        }
37    }
38}
39
40#[derive(Encoder, Decoder, FluvioDefault, Debug)]
41pub struct TopicProduceResponse {
42    /// The topic name
43    pub name: String,
44
45    /// Each partition that we produced to within the topic.
46    pub partitions: Vec<PartitionProduceResponse>,
47}
48
49#[derive(Encoder, Decoder, FluvioDefault, Debug)]
50pub struct PartitionProduceResponse {
51    /// The partition index.
52    pub partition_index: i32,
53
54    /// The error code, or 0 if there was no error.
55    pub error_code: ErrorCode,
56
57    /// The base offset.
58    pub base_offset: i64,
59
60    /// The timestamp returned by broker after appending the messages. If CreateTime is used for the
61    /// topic, the timestamp will be -1.  If LogAppendTime is used for the topic, the timestamp will
62    /// be the broker local time when the messages are appended.
63    #[fluvio(min_version = 2, ignorable)]
64    pub log_append_time_ms: i64,
65
66    /// The log start offset.
67    #[fluvio(min_version = 5, ignorable)]
68    pub log_start_offset: i64,
69}