Skip to main content

kacrab_protocol/generated/
api_versions_request.rs

1//! Generated from ApiVersionsRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct ApiVersionsRequestData {
17    /// The name of the client.
18    pub client_software_name: KafkaString,
19    /// The version of the client.
20    pub client_software_version: KafkaString,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for ApiVersionsRequestData {
24    fn default() -> Self {
25        Self {
26            client_software_name: KafkaString::default(),
27            client_software_version: KafkaString::default(),
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl ApiVersionsRequestData {
33    pub fn with_client_software_name(mut self, value: KafkaString) -> Self {
34        self.client_software_name = value;
35        self
36    }
37    pub fn with_client_software_version(mut self, value: KafkaString) -> Self {
38        self.client_software_version = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42        if version < 0 || version > 4 {
43            return Err(UnsupportedVersion::new(18, version).into());
44        }
45        let mut client_software_name = KafkaString::default();
46        let mut client_software_version = KafkaString::default();
47        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
48        if version >= 3 {
49            client_software_name = read_compact_string(buf)?;
50        }
51        if version >= 3 {
52            client_software_version = read_compact_string(buf)?;
53        }
54        if version >= 3 {
55            let tagged_fields = read_tagged_fields(buf)?;
56            for field in &tagged_fields {
57                match field.tag {
58                    _ => {
59                        _unknown_tagged_fields.push(field.clone());
60                    },
61                }
62            }
63        }
64        Ok(Self {
65            client_software_name,
66            client_software_version,
67            _unknown_tagged_fields,
68        })
69    }
70    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
71        if version < 0 || version > 4 {
72            return Err(UnsupportedVersion::new(18, version).into());
73        }
74        if version >= 3 {
75            write_compact_string(buf, &self.client_software_name)?;
76        } else if self.client_software_name != KafkaString::default() {
77            return Err(UnsupportedFieldVersion::new(18, "client_software_name", version).into());
78        }
79        if version >= 3 {
80            write_compact_string(buf, &self.client_software_version)?;
81        } else if self.client_software_version != KafkaString::default() {
82            return Err(
83                UnsupportedFieldVersion::new(18, "client_software_version", version).into(),
84            );
85        }
86        if version >= 3 {
87            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
88            all_tags.sort_by_key(|f| f.tag);
89            write_tagged_fields(buf, &all_tags)?;
90        }
91        Ok(())
92    }
93    pub fn encoded_len(&self, version: i16) -> Result<usize> {
94        if version < 0 || version > 4 {
95            return Err(UnsupportedVersion::new(18, version).into());
96        }
97        let mut len: usize = 0;
98        if version >= 3 {
99            len += compact_string_len(&self.client_software_name)?;
100        } else if self.client_software_name != KafkaString::default() {
101            return Err(UnsupportedFieldVersion::new(18, "client_software_name", version).into());
102        }
103        if version >= 3 {
104            len += compact_string_len(&self.client_software_version)?;
105        } else if self.client_software_version != KafkaString::default() {
106            return Err(
107                UnsupportedFieldVersion::new(18, "client_software_version", version).into(),
108            );
109        }
110        if version >= 3 {
111            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
112            all_tags.sort_by_key(|f| f.tag);
113            len += tagged_fields_len(&all_tags)?;
114        }
115        Ok(len)
116    }
117}