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