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::api_version::ApiVersion;
20use crate::rpc::frame::{ReadError, WriteError};
21use bytes::{Buf, BufMut};
22
23mod authenticate;
24mod create_database;
25mod create_partition;
26mod create_table;
27mod database_exists;
28mod drop_database;
29mod drop_partition;
30mod drop_table;
31mod fetch;
32mod get_database_info;
33mod get_latest_lake_snapshot;
34mod get_security_token;
35mod get_table;
36mod header;
37mod init_writer;
38mod list_databases;
39mod list_offsets;
40mod list_partition_infos;
41mod list_tables;
42mod lookup;
43mod produce_log;
44mod put_kv;
45mod table_exists;
46mod update_metadata;
47
48pub use crate::rpc::RpcError;
49pub use authenticate::*;
50pub use create_database::*;
51pub use create_partition::*;
52pub use create_table::*;
53pub use database_exists::*;
54pub use drop_database::*;
55pub use drop_partition::*;
56pub use drop_table::*;
57pub use fetch::*;
58pub use get_database_info::*;
59pub use get_latest_lake_snapshot::*;
60pub use get_security_token::*;
61pub use get_table::*;
62pub use header::*;
63pub use init_writer::*;
64pub use list_databases::*;
65pub use list_offsets::*;
66pub use list_partition_infos::*;
67pub use list_tables::*;
68pub use lookup::*;
69pub use produce_log::*;
70pub use put_kv::*;
71pub use table_exists::*;
72pub use update_metadata::*;
73
74pub trait RequestBody {
75    type ResponseBody;
76
77    const API_KEY: ApiKey;
78
79    const REQUEST_VERSION: ApiVersion;
80}
81
82impl<T: RequestBody> RequestBody for &T {
83    type ResponseBody = T::ResponseBody;
84
85    const API_KEY: ApiKey = T::API_KEY;
86
87    const REQUEST_VERSION: ApiVersion = T::REQUEST_VERSION;
88}
89
90pub trait WriteVersionedType<W>: Sized
91where
92    W: BufMut,
93{
94    fn write_versioned(&self, writer: &mut W, version: ApiVersion) -> Result<(), WriteError>;
95}
96
97pub trait ReadVersionedType<R>: Sized
98where
99    R: Buf,
100{
101    fn read_versioned(reader: &mut R, version: ApiVersion) -> Result<Self, ReadError>;
102}
103
104#[macro_export]
105macro_rules! impl_write_version_type {
106    ($type:ty) => {
107        impl<W> WriteVersionedType<W> for $type
108        where
109            W: BufMut,
110        {
111            fn write_versioned(
112                &self,
113                writer: &mut W,
114                _version: ApiVersion,
115            ) -> Result<(), WriteError> {
116                Ok(self.inner_request.encode(writer).unwrap())
117            }
118        }
119    };
120}
121
122#[macro_export]
123macro_rules! impl_read_version_type {
124    ($type:ty) => {
125        impl<R> ReadVersionedType<R> for $type
126        where
127            R: Buf,
128        {
129            fn read_versioned(reader: &mut R, _version: ApiVersion) -> Result<Self, ReadError> {
130                Ok(<$type>::decode(reader).unwrap())
131            }
132        }
133    };
134}