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