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