kafka_api/schemata/
api_versions_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// Versions 0 through 2 of ApiVersionsRequest are the same.
21//
22// Version 3 is the first flexible version and adds ClientSoftwareName and ClientSoftwareVersion.
23
24#[derive(Debug, Default, Clone)]
25pub struct ApiVersionsRequest {
26    /// The name of the client.
27    pub client_software_name: String,
28    /// The version of the client.
29    pub client_software_version: String,
30    /// Unknown tagged fields.
31    pub unknown_tagged_fields: Vec<RawTaggedField>,
32}
33
34impl Decodable for ApiVersionsRequest {
35    fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
36        let mut this = ApiVersionsRequest::default();
37        if version >= 3 {
38            this.client_software_name = NullableString(true)
39                .decode(buf)?
40                .ok_or_else(|| err_decode_message_null("client_software_name"))?;
41        }
42        if version >= 3 {
43            this.client_software_version = NullableString(true)
44                .decode(buf)?
45                .ok_or_else(|| err_decode_message_null("client_software_version"))?;
46        }
47        if version >= 3 {
48            this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
49        }
50        Ok(this)
51    }
52}