kf_protocol_message/kf_code_gen/
produce.rs

1/// WARNING: CODE GENERATED FILE
2/// * This file is generated by kfspec2code.
3/// * Any changes applied to this file will be lost when a new spec is generated.
4use std::fmt::Debug;
5use std::marker::PhantomData;
6
7use kf_protocol::Decoder;
8use kf_protocol::Encoder;
9
10use serde::{Deserialize, Serialize};
11
12use kf_protocol_api::ErrorCode;
13use kf_protocol_api::Request;
14
15use kf_protocol_derive::Decode;
16use kf_protocol_derive::Encode;
17use kf_protocol_derive::KfDefault;
18
19// -----------------------------------
20// KfProduceRequest<R>
21// -----------------------------------
22
23#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
24pub struct KfProduceRequest<R>
25where
26    R: Encoder + Decoder + Default + Debug,
27{
28    /// The transactional ID, or null if the producer is not transactional.
29    #[fluvio_kf(min_version = 3)]
30    pub transactional_id: Option<String>,
31
32    /// The number of acknowledgments the producer requires the leader to have received before
33    /// considering a request complete. Allowed values: 0 for no acknowledgments, 1 for only the
34    /// leader and -1 for the full ISR.
35    pub acks: i16,
36
37    /// The timeout to await a response in miliseconds.
38    pub timeout_ms: i32,
39
40    /// Each topic to produce to.
41    pub topics: Vec<TopicProduceData<R>>,
42    pub data: PhantomData<R>,
43}
44
45#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
46pub struct TopicProduceData<R>
47where
48    R: Encoder + Decoder + Default + Debug,
49{
50    /// The topic name.
51    pub name: String,
52
53    /// Each partition to produce to.
54    pub partitions: Vec<PartitionProduceData<R>>,
55    pub data: PhantomData<R>,
56}
57
58#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
59pub struct PartitionProduceData<R>
60where
61    R: Encoder + Decoder + Default + Debug,
62{
63    /// The partition index.
64    pub partition_index: i32,
65
66    /// The record data to be produced.
67    pub records: R,
68}
69
70// -----------------------------------
71// KfProduceResponse
72// -----------------------------------
73
74#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
75pub struct KfProduceResponse {
76    /// Each produce response
77    pub responses: Vec<TopicProduceResponse>,
78
79    /// The duration in milliseconds for which the request was throttled due to a quota violation,
80    /// or zero if the request did not violate any quota.
81    #[fluvio_kf(min_version = 1, ignorable)]
82    pub throttle_time_ms: i32,
83}
84
85#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
86pub struct TopicProduceResponse {
87    /// The topic name
88    pub name: String,
89
90    /// Each partition that we produced to within the topic.
91    pub partitions: Vec<PartitionProduceResponse>,
92}
93
94#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
95pub struct PartitionProduceResponse {
96    /// The partition index.
97    pub partition_index: i32,
98
99    /// The error code, or 0 if there was no error.
100    pub error_code: ErrorCode,
101
102    /// The base offset.
103    pub base_offset: i64,
104
105    /// The timestamp returned by broker after appending the messages. If CreateTime is used for the
106    /// topic, the timestamp will be -1.  If LogAppendTime is used for the topic, the timestamp will
107    /// be the broker local time when the messages are appended.
108    #[fluvio_kf(min_version = 2, ignorable)]
109    pub log_append_time_ms: i64,
110
111    /// The log start offset.
112    #[fluvio_kf(min_version = 5, ignorable)]
113    pub log_start_offset: i64,
114}
115
116// -----------------------------------
117// Implementation - KfProduceRequest<R>
118// -----------------------------------
119
120impl<R> Request for KfProduceRequest<R>
121where
122    R: Debug + Decoder + Encoder,
123{
124    const API_KEY: u16 = 0;
125
126    const MIN_API_VERSION: i16 = 0;
127    const MAX_API_VERSION: i16 = 7;
128    const DEFAULT_API_VERSION: i16 = 7;
129
130    type Response = KfProduceResponse;
131
132}