kafka_api/schemata/find_coordinator_request.rs
1// Copyright 2024 tison <wander4096@gmail.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use byteorder::ReadBytesExt;
16
17use crate::codec::*;
18use crate::IoResult;
19
20// Version 1 adds KeyType.
21//
22// Version 2 is the same as version 1.
23//
24// Version 3 is the first flexible version.
25//
26// Version 4 adds support for batching via CoordinatorKeys (KIP-699)
27
28#[derive(Debug, Default, Clone)]
29pub struct FindCoordinatorRequest {
30 /// The coordinator key.
31 pub key: String,
32 /// The coordinator key type. (Group, transaction, etc.)
33 pub key_type: i8,
34 /// The coordinator keys.
35 pub coordinator_keys: Vec<String>,
36 /// Unknown tagged fields.
37 pub unknown_tagged_fields: Vec<RawTaggedField>,
38}
39
40impl Decodable for FindCoordinatorRequest {
41 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
42 let mut this = FindCoordinatorRequest::default();
43 if version <= 3 {
44 this.key = NullableString(version >= 3)
45 .decode(buf)?
46 .unwrap_or_default();
47 }
48 if version >= 1 {
49 this.key_type = Int8.decode(buf)?;
50 }
51 if version >= 4 {
52 this.coordinator_keys = NullableArray(NullableString(true), true)
53 .decode(buf)?
54 .unwrap_or_default()
55 .into_iter()
56 .map(|key| key.ok_or_else(|| err_decode_message_null("coordinatorKeys element")))
57 .collect::<std::io::Result<Vec<String>>>()?;
58 }
59 if version >= 3 {
60 this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
61 }
62 Ok(this)
63 }
64}