Skip to main content

fluss/rpc/message/
lookup.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::proto::LookupResponse;
19use crate::rpc::frame::ReadError;
20
21use crate::rpc::api_key::ApiKey;
22use crate::rpc::api_version::ApiVersion;
23use crate::rpc::frame::WriteError;
24use crate::rpc::message::{ReadVersionedType, RequestBody, WriteVersionedType};
25use crate::{impl_read_version_type, impl_write_version_type, proto};
26use prost::Message;
27
28use bytes::{Buf, BufMut};
29
30pub struct LookupRequest {
31    pub inner_request: proto::LookupRequest,
32}
33
34impl LookupRequest {
35    pub fn new(
36        table_id: i64,
37        partition_id: Option<i64>,
38        bucket_id: i32,
39        keys: Vec<Vec<u8>>,
40    ) -> Self {
41        let bucket_req = proto::PbLookupReqForBucket {
42            partition_id,
43            bucket_id,
44            key: keys,
45        };
46
47        let request = proto::LookupRequest {
48            table_id,
49            buckets_req: vec![bucket_req],
50        };
51
52        Self {
53            inner_request: request,
54        }
55    }
56}
57
58impl RequestBody for LookupRequest {
59    type ResponseBody = LookupResponse;
60
61    const API_KEY: ApiKey = ApiKey::Lookup;
62
63    const REQUEST_VERSION: ApiVersion = ApiVersion(0);
64}
65
66impl_write_version_type!(LookupRequest);
67impl_read_version_type!(LookupResponse);