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