Skip to main content

kacrab_protocol/generated/
find_coordinator_request.rs

1//! Generated from FindCoordinatorRequest.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 FindCoordinatorRequestData {
17    /// The coordinator key.
18    pub key: KafkaString,
19    /// The coordinator key type. (group, transaction, share).
20    pub key_type: i8,
21    /// The coordinator keys.
22    pub coordinator_keys: Vec<KafkaString>,
23    pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for FindCoordinatorRequestData {
26    fn default() -> Self {
27        Self {
28            key: KafkaString::default(),
29            key_type: 0i8,
30            coordinator_keys: Vec::new(),
31            _unknown_tagged_fields: Vec::new(),
32        }
33    }
34}
35impl FindCoordinatorRequestData {
36    pub fn with_key(mut self, value: KafkaString) -> Self {
37        self.key = value;
38        self
39    }
40    pub fn with_key_type(mut self, value: i8) -> Self {
41        self.key_type = value;
42        self
43    }
44    pub fn with_coordinator_keys(mut self, value: Vec<KafkaString>) -> Self {
45        self.coordinator_keys = value;
46        self
47    }
48    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49        if version < 0 || version > 6 {
50            return Err(UnsupportedVersion::new(10, version).into());
51        }
52        let mut key = KafkaString::default();
53        let mut key_type = 0i8;
54        let mut coordinator_keys = Vec::new();
55        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56        if version <= 3 {
57            if version >= 3 {
58                key = read_compact_string(buf)?;
59            } else {
60                key = read_string(buf)?;
61            }
62        }
63        if version >= 1 {
64            key_type = read_i8(buf)?;
65        }
66        if version >= 4 {
67            coordinator_keys = {
68                let len = read_compact_array_length(buf)?;
69                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
70                for _ in 0..len {
71                    arr.push(read_compact_string(buf)?);
72                }
73                arr
74            };
75        }
76        if version >= 3 {
77            let tagged_fields = read_tagged_fields(buf)?;
78            for field in &tagged_fields {
79                match field.tag {
80                    _ => {
81                        _unknown_tagged_fields.push(field.clone());
82                    },
83                }
84            }
85        }
86        Ok(Self {
87            key,
88            key_type,
89            coordinator_keys,
90            _unknown_tagged_fields,
91        })
92    }
93    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
94        if version < 0 || version > 6 {
95            return Err(UnsupportedVersion::new(10, version).into());
96        }
97        if version <= 3 {
98            if version >= 3 {
99                write_compact_string(buf, &self.key)?;
100            } else {
101                write_string(buf, &self.key)?;
102            }
103        } else if self.key != KafkaString::default() {
104            return Err(UnsupportedFieldVersion::new(10, "key", version).into());
105        }
106        if version >= 1 {
107            write_i8(buf, self.key_type);
108        } else if self.key_type != 0i8 {
109            return Err(UnsupportedFieldVersion::new(10, "key_type", version).into());
110        }
111        if version >= 4 {
112            write_compact_array_length(buf, self.coordinator_keys.len() as i32);
113            for el in &self.coordinator_keys {
114                write_compact_string(buf, el)?;
115            }
116        } else if self.coordinator_keys != Vec::new() {
117            return Err(UnsupportedFieldVersion::new(10, "coordinator_keys", version).into());
118        }
119        if version >= 3 {
120            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
121            all_tags.sort_by_key(|f| f.tag);
122            write_tagged_fields(buf, &all_tags)?;
123        }
124        Ok(())
125    }
126    pub fn encoded_len(&self, version: i16) -> Result<usize> {
127        if version < 0 || version > 6 {
128            return Err(UnsupportedVersion::new(10, version).into());
129        }
130        let mut len: usize = 0;
131        if version <= 3 {
132            if version >= 3 {
133                len += compact_string_len(&self.key)?;
134            } else {
135                len += string_len(&self.key)?;
136            }
137        } else if self.key != KafkaString::default() {
138            return Err(UnsupportedFieldVersion::new(10, "key", version).into());
139        }
140        if version >= 1 {
141            len += 1;
142        } else if self.key_type != 0i8 {
143            return Err(UnsupportedFieldVersion::new(10, "key_type", version).into());
144        }
145        if version >= 4 {
146            len += compact_array_length_len(self.coordinator_keys.len() as i32);
147            for el in &self.coordinator_keys {
148                len += compact_string_len(el)?;
149            }
150        } else if self.coordinator_keys != Vec::new() {
151            return Err(UnsupportedFieldVersion::new(10, "coordinator_keys", version).into());
152        }
153        if version >= 3 {
154            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
155            all_tags.sort_by_key(|f| f.tag);
156            len += tagged_fields_len(&all_tags)?;
157        }
158        Ok(len)
159    }
160}