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