Skip to main content

fluss/rpc/message/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::rpc::api_key::ApiKey;
19use crate::rpc::frame::{ReadError, WriteError};
20use bytes::{Buf, BufMut};
21
22mod acquire_kv_snapshot_lease;
23mod add_server_tag;
24mod alter_cluster_configs;
25mod alter_database;
26mod alter_table;
27mod api_versions;
28mod authenticate;
29mod cancel_rebalance;
30mod create_acls;
31mod create_database;
32mod create_partition;
33mod create_table;
34mod database_exists;
35mod delete_producer_offsets;
36mod describe_cluster_configs;
37mod drop_acls;
38mod drop_database;
39mod drop_kv_snapshot_lease;
40mod drop_partition;
41mod drop_table;
42mod fetch;
43mod get_cluster_health;
44mod get_database_info;
45mod get_kv_snapshot_metadata;
46mod get_lake_snapshot;
47mod get_latest_kv_snapshots;
48mod get_latest_lake_snapshot;
49mod get_producer_offsets;
50mod get_security_token;
51mod get_table;
52mod get_table_schema;
53mod get_table_stats;
54mod header;
55mod init_writer;
56mod limit_scan;
57mod list_acls;
58mod list_database_summaries;
59mod list_databases;
60mod list_kv_snapshots;
61mod list_offsets;
62mod list_partition_infos;
63mod list_rebalance_progress;
64mod list_remote_log_manifests;
65mod list_tables;
66mod lookup;
67mod prefix_lookup;
68mod produce_log;
69mod put_kv;
70mod rebalance;
71mod register_producer_offsets;
72mod release_kv_snapshot_lease;
73mod remove_server_tag;
74mod scan_kv;
75mod table_exists;
76mod update_metadata;
77
78pub use crate::rpc::RpcError;
79pub use acquire_kv_snapshot_lease::*;
80pub use add_server_tag::*;
81pub use alter_cluster_configs::*;
82pub use alter_database::*;
83pub use alter_table::*;
84pub use api_versions::*;
85pub use authenticate::*;
86pub use cancel_rebalance::*;
87pub use create_acls::*;
88pub use create_database::*;
89pub use create_partition::*;
90pub use create_table::*;
91pub use database_exists::*;
92pub use delete_producer_offsets::*;
93pub use describe_cluster_configs::*;
94pub use drop_acls::*;
95pub use drop_database::*;
96pub use drop_kv_snapshot_lease::*;
97pub use drop_partition::*;
98pub use drop_table::*;
99pub use fetch::*;
100pub use get_cluster_health::*;
101pub use get_database_info::*;
102pub use get_kv_snapshot_metadata::*;
103pub use get_lake_snapshot::*;
104pub use get_latest_kv_snapshots::*;
105pub use get_latest_lake_snapshot::*;
106pub use get_producer_offsets::*;
107pub use get_security_token::*;
108pub use get_table::*;
109pub use get_table_schema::*;
110pub use get_table_stats::*;
111pub use header::*;
112pub use init_writer::*;
113pub use limit_scan::*;
114pub use list_acls::*;
115pub use list_database_summaries::*;
116pub use list_databases::*;
117pub use list_kv_snapshots::*;
118pub use list_offsets::*;
119pub use list_partition_infos::*;
120pub use list_rebalance_progress::*;
121pub use list_remote_log_manifests::*;
122pub use list_tables::*;
123pub use lookup::*;
124pub use prefix_lookup::*;
125pub use produce_log::*;
126pub use put_kv::*;
127pub use rebalance::*;
128pub use register_producer_offsets::*;
129pub use release_kv_snapshot_lease::*;
130pub use remove_server_tag::*;
131pub use scan_kv::*;
132pub use table_exists::*;
133pub use update_metadata::*;
134
135pub trait RequestBody {
136    type ResponseBody;
137
138    const API_KEY: ApiKey;
139}
140
141impl<T: RequestBody> RequestBody for &T {
142    type ResponseBody = T::ResponseBody;
143
144    const API_KEY: ApiKey = T::API_KEY;
145}
146
147pub trait WriteType<W>: Sized
148where
149    W: BufMut,
150{
151    fn write(&self, writer: &mut W) -> Result<(), WriteError>;
152}
153
154pub trait ReadType<R>: Sized
155where
156    R: Buf,
157{
158    fn read(reader: &mut R) -> Result<Self, ReadError>;
159}
160
161#[macro_export]
162macro_rules! impl_write_type {
163    ($type:ty) => {
164        impl<W> WriteType<W> for $type
165        where
166            W: BufMut,
167        {
168            fn write(&self, writer: &mut W) -> Result<(), WriteError> {
169                Ok(self.inner_request.encode(writer).unwrap())
170            }
171        }
172    };
173}
174
175#[macro_export]
176macro_rules! impl_read_type {
177    ($type:ty) => {
178        impl<R> ReadType<R> for $type
179        where
180            R: Buf,
181        {
182            fn read(reader: &mut R) -> Result<Self, ReadError> {
183                Ok(<$type>::decode(reader).unwrap())
184            }
185        }
186    };
187}