kf_protocol_message/kf_code_gen/
metadata.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 serde::{Deserialize, Serialize};
5
6use kf_protocol_api::ErrorCode;
7use kf_protocol_api::Request;
8
9use kf_protocol_derive::Decode;
10use kf_protocol_derive::Encode;
11use kf_protocol_derive::KfDefault;
12use flv_util::socket_helpers::ServerAddress;
13// -----------------------------------
14// KfMetadataRequest
15// -----------------------------------
16
17#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
18pub struct KfMetadataRequest {
19    /// The topics to fetch metadata for.
20    pub topics: Option<Vec<MetadataRequestTopic>>,
21
22    /// If this is true, the broker may auto-create topics that we requested which do not already
23    /// exist, if it is configured to do so.
24    #[fluvio_kf(min_version = 4)]
25    pub allow_auto_topic_creation: bool,
26}
27
28#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
29pub struct MetadataRequestTopic {
30    /// The topic name.
31    pub name: String,
32}
33
34// -----------------------------------
35// KfMetadataResponse
36// -----------------------------------
37
38#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
39pub struct KfMetadataResponse {
40    /// The duration in milliseconds for which the request was throttled due to a quota violation,
41    /// or zero if the request did not violate any quota.
42    #[fluvio_kf(min_version = 3)]
43    pub throttle_time_ms: i32,
44
45    /// Each broker in the response.
46    pub brokers: Vec<MetadataResponseBroker>,
47
48    /// The cluster ID that responding broker belongs to.
49    #[fluvio_kf(min_version = 2, ignorable)]
50    pub cluster_id: Option<String>,
51
52    /// The ID of the controller broker.
53    #[fluvio_kf(min_version = 1, ignorable)]
54    pub controller_id: i32,
55
56    /// Each topic in the response.
57    pub topics: Vec<MetadataResponseTopic>,
58}
59
60#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
61pub struct MetadataResponseBroker {
62    /// The broker ID.
63    pub node_id: i32,
64
65    /// The broker hostname.
66    pub host: String,
67
68    /// The broker port.
69    pub port: i32,
70
71    /// The rack of the broker, or null if it has not been assigned to a rack.
72    #[fluvio_kf(min_version = 1, ignorable)]
73    pub rack: Option<String>,
74}
75
76impl MetadataResponseBroker {
77    pub fn into(&self) -> ServerAddress {
78        ServerAddress::new(self.host.clone(),self.port as u16)
79    }
80}
81
82#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
83pub struct MetadataResponseTopic {
84    /// The topic error, or 0 if there was no error.
85    pub error_code: ErrorCode,
86
87    /// The topic name.
88    pub name: String,
89
90    /// True if the topic is internal.
91    #[fluvio_kf(min_version = 1, ignorable)]
92    pub is_internal: bool,
93
94    /// Each partition in the topic.
95    pub partitions: Vec<MetadataResponsePartition>,
96}
97
98#[derive(Encode, Decode, Serialize, Deserialize, KfDefault, Debug)]
99pub struct MetadataResponsePartition {
100    /// The partition error, or 0 if there was no error.
101    pub error_code: ErrorCode,
102
103    /// The partition index.
104    pub partition_index: i32,
105
106    /// The ID of the leader broker.
107    pub leader_id: i32,
108
109    /// The leader epoch of this partition.
110    #[fluvio_kf(min_version = 7, ignorable)]
111    pub leader_epoch: i32,
112
113    /// The set of all nodes that host this partition.
114    pub replica_nodes: Vec<i32>,
115
116    /// The set of nodes that are in sync with the leader for this partition.
117    pub isr_nodes: Vec<i32>,
118
119    /// The set of offline replicas of this partition.
120    #[fluvio_kf(min_version = 5, ignorable)]
121    pub offline_replicas: Vec<i32>,
122}
123
124// -----------------------------------
125// Implementation - KfMetadataRequest
126// -----------------------------------
127
128impl Request for KfMetadataRequest {
129    const API_KEY: u16 = 3;
130
131    const MIN_API_VERSION: i16 = 0;
132    const MAX_API_VERSION: i16 = 7;
133    const DEFAULT_API_VERSION: i16 = 7;
134
135    type Response = KfMetadataResponse;
136}