krabka_protocol/opt/rustwide/workdir/generated/
DescribeQuorumRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i32, put_i32},
8 string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9 string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10 },
11 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 55;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 2;
16pub const LATEST_STABLE_VERSION: i16 = 2;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeQuorumRequest<'a> {
25 pub topics: Vec<TopicData<'a>>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl DescribeQuorumRequest<'_> {
29 #[must_use]
33 pub fn to_owned(&self) -> crate::owned::describe_quorum_request::DescribeQuorumRequest {
34 crate::owned::describe_quorum_request::DescribeQuorumRequest {
35 topics: (self.topics).iter().map(TopicData::to_owned).collect(),
36 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37 }
38 }
39}
40impl Encode for DescribeQuorumRequest<'_> {
41 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::UnsupportedVersion {
44 api_key: API_KEY,
45 version,
46 });
47 }
48 let flex = is_flexible(version);
49 if version >= 0 {
50 {
51 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
52 for it in &self.topics {
53 it.encode(buf, version)?;
54 }
55 };
56 }
57 if flex {
58 let tagged = WriteTaggedFields::new();
59 tagged.write(buf, &self.unknown_tagged_fields);
60 }
61 Ok(())
62 }
63 fn encoded_len(&self, version: i16) -> usize {
64 let flex = is_flexible(version);
65 let mut n: usize = 0;
66 if version >= 0 {
67 n += {
68 let prefix =
69 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
70 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
71 prefix + body
72 };
73 }
74 if flex {
75 let known_pairs: Vec<(u32, usize)> = Vec::new();
76 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77 }
78 n
79 }
80}
81impl<'de> DecodeBorrow<'de> for DescribeQuorumRequest<'de> {
82 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
83 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84 return Err(ProtocolError::UnsupportedVersion {
85 api_key: API_KEY,
86 version,
87 });
88 }
89 let flex = is_flexible(version);
90 let mut out = Self::default();
91 if version >= 0 {
92 out.topics = {
93 let n = crate::primitives::array::get_array_len(buf, flex)?;
94 let mut v = Vec::with_capacity(n);
95 for _ in 0..n {
96 v.push(TopicData::decode_borrow(buf, version)?);
97 }
98 v
99 };
100 }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
103 }
104 Ok(out)
105 }
106}
107#[cfg(test)]
108impl DescribeQuorumRequest<'_> {
109 #[must_use]
110 pub fn populated(version: i16) -> Self {
111 let mut m = Self::default();
112 if version >= 0 {
113 m.topics = vec![TopicData::populated(version)];
114 }
115 m
116 }
117}
118#[derive(Debug, Clone, PartialEq, Eq, Default)]
119pub struct TopicData<'a> {
120 pub topic_name: &'a str,
121 pub partitions: Vec<PartitionData>,
122 pub unknown_tagged_fields: UnknownTaggedFields,
123}
124impl TopicData<'_> {
125 #[must_use]
129 pub fn to_owned(&self) -> crate::owned::describe_quorum_request::TopicData {
130 crate::owned::describe_quorum_request::TopicData {
131 topic_name: (self.topic_name).to_string(),
132 partitions: (self.partitions)
133 .iter()
134 .map(PartitionData::to_owned)
135 .collect(),
136 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
137 }
138 }
139}
140impl Encode for TopicData<'_> {
141 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142 let flex = version >= 0;
143 if version >= 0 {
144 if flex {
145 let () = put_compact_string(buf, self.topic_name);
146 } else {
147 let () = put_string(buf, self.topic_name);
148 }
149 }
150 if version >= 0 {
151 {
152 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
153 for it in &self.partitions {
154 it.encode(buf, version)?;
155 }
156 };
157 }
158 if flex {
159 let tagged = WriteTaggedFields::new();
160 tagged.write(buf, &self.unknown_tagged_fields);
161 }
162 Ok(())
163 }
164 fn encoded_len(&self, version: i16) -> usize {
165 let flex = version >= 0;
166 let mut n: usize = 0;
167 if version >= 0 {
168 n += if flex {
169 compact_string_len(self.topic_name)
170 } else {
171 string_len(self.topic_name)
172 };
173 }
174 if version >= 0 {
175 n += {
176 let prefix =
177 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
178 let body: usize = (self.partitions)
179 .iter()
180 .map(|it| it.encoded_len(version))
181 .sum();
182 prefix + body
183 };
184 }
185 if flex {
186 let known_pairs: Vec<(u32, usize)> = Vec::new();
187 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
188 }
189 n
190 }
191}
192impl<'de> DecodeBorrow<'de> for TopicData<'de> {
193 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
194 let flex = version >= 0;
195 let mut out = Self::default();
196 if version >= 0 {
197 out.topic_name = if flex {
198 get_compact_string_borrowed(buf)?
199 } else {
200 get_string_borrowed(buf)?
201 };
202 }
203 if version >= 0 {
204 out.partitions = {
205 let n = crate::primitives::array::get_array_len(buf, flex)?;
206 let mut v = Vec::with_capacity(n);
207 for _ in 0..n {
208 v.push(PartitionData::decode_borrow(buf, version)?);
209 }
210 v
211 };
212 }
213 if flex {
214 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
215 }
216 Ok(out)
217 }
218}
219#[cfg(test)]
220impl TopicData<'_> {
221 #[must_use]
222 pub fn populated(version: i16) -> Self {
223 let mut m = Self::default();
224 if version >= 0 {
225 m.topic_name = "x";
226 }
227 if version >= 0 {
228 m.partitions = vec![PartitionData::populated(version)];
229 }
230 m
231 }
232}
233#[derive(Debug, Clone, PartialEq, Eq, Default)]
234pub struct PartitionData {
235 pub partition_index: i32,
236 pub unknown_tagged_fields: UnknownTaggedFields,
237}
238impl PartitionData {
239 #[must_use]
243 pub fn to_owned(&self) -> crate::owned::describe_quorum_request::PartitionData {
244 crate::owned::describe_quorum_request::PartitionData {
245 partition_index: (self.partition_index),
246 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
247 }
248 }
249}
250impl Encode for PartitionData {
251 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
252 let flex = version >= 0;
253 if version >= 0 {
254 put_i32(buf, self.partition_index);
255 }
256 if flex {
257 let tagged = WriteTaggedFields::new();
258 tagged.write(buf, &self.unknown_tagged_fields);
259 }
260 Ok(())
261 }
262 fn encoded_len(&self, version: i16) -> usize {
263 let flex = version >= 0;
264 let mut n: usize = 0;
265 if version >= 0 {
266 n += 4;
267 }
268 if flex {
269 let known_pairs: Vec<(u32, usize)> = Vec::new();
270 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
271 }
272 n
273 }
274}
275impl<'de> DecodeBorrow<'de> for PartitionData {
276 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
277 let flex = version >= 0;
278 let mut out = Self::default();
279 if version >= 0 {
280 out.partition_index = get_i32(buf)?;
281 }
282 if flex {
283 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
284 }
285 Ok(out)
286 }
287}
288#[cfg(test)]
289impl PartitionData {
290 #[must_use]
291 pub fn populated(version: i16) -> Self {
292 let mut m = Self::default();
293 if version >= 0 {
294 m.partition_index = 1i32;
295 }
296 m
297 }
298}