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