crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryResponse.owned.rs1use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
4use crate::primitives::string_bytes::{
5 compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
6 nullable_string_len, put_compact_nullable_string, put_nullable_string,
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 = 87;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 1;
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 ReadShareGroupStateSummaryResponse {
21 pub results: Vec<ReadStateSummaryResult>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for ReadShareGroupStateSummaryResponse {
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.results).len(), flex);
36 for it in &self.results {
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.results).len(), flex);
54 let body: usize = (self.results)
55 .iter()
56 .map(|it| it.encoded_len(version))
57 .sum();
58 prefix + body
59 };
60 }
61 if flex {
62 let known_pairs: Vec<(u32, usize)> = Vec::new();
63 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64 }
65 n
66 }
67}
68impl Decode<'_> for ReadShareGroupStateSummaryResponse {
69 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
70 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71 return Err(ProtocolError::UnsupportedVersion {
72 api_key: API_KEY,
73 version,
74 });
75 }
76 let flex = is_flexible(version);
77 let mut out = Self::default();
78 if version >= 0 {
79 out.results = {
80 let n = crate::primitives::array::get_array_len(buf, flex)?;
81 let mut v = Vec::with_capacity(n);
82 for _ in 0..n {
83 v.push(ReadStateSummaryResult::decode(buf, version)?);
84 }
85 v
86 };
87 }
88 if flex {
89 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
90 }
91 Ok(out)
92 }
93}
94#[cfg(test)]
95impl ReadShareGroupStateSummaryResponse {
96 #[must_use]
97 pub fn populated(version: i16) -> Self {
98 let mut m = Self::default();
99 if version >= 0 {
100 m.results = vec![ReadStateSummaryResult::populated(version)];
101 }
102 m
103 }
104}
105#[derive(Debug, Clone, PartialEq, Eq, Default)]
106pub struct ReadStateSummaryResult {
107 pub topic_id: crate::primitives::uuid::Uuid,
108 pub partitions: Vec<PartitionResult>,
109 pub unknown_tagged_fields: UnknownTaggedFields,
110}
111impl Encode for ReadStateSummaryResult {
112 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
113 let flex = version >= 0;
114 if version >= 0 {
115 crate::primitives::uuid::put_uuid(buf, self.topic_id);
116 }
117 if version >= 0 {
118 {
119 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
120 for it in &self.partitions {
121 it.encode(buf, version)?;
122 }
123 }
124 }
125 if flex {
126 let tagged = WriteTaggedFields::new();
127 tagged.write(buf, &self.unknown_tagged_fields);
128 }
129 Ok(())
130 }
131 fn encoded_len(&self, version: i16) -> usize {
132 let flex = version >= 0;
133 let mut n: usize = 0;
134 if version >= 0 {
135 n += 16;
136 }
137 if version >= 0 {
138 n += {
139 let prefix =
140 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
141 let body: usize = (self.partitions)
142 .iter()
143 .map(|it| it.encoded_len(version))
144 .sum();
145 prefix + body
146 };
147 }
148 if flex {
149 let known_pairs: Vec<(u32, usize)> = Vec::new();
150 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
151 }
152 n
153 }
154}
155impl Decode<'_> for ReadStateSummaryResult {
156 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
157 let flex = version >= 0;
158 let mut out = Self::default();
159 if version >= 0 {
160 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
161 }
162 if version >= 0 {
163 out.partitions = {
164 let n = crate::primitives::array::get_array_len(buf, flex)?;
165 let mut v = Vec::with_capacity(n);
166 for _ in 0..n {
167 v.push(PartitionResult::decode(buf, version)?);
168 }
169 v
170 };
171 }
172 if flex {
173 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
174 }
175 Ok(out)
176 }
177}
178#[cfg(test)]
179impl ReadStateSummaryResult {
180 #[must_use]
181 pub fn populated(version: i16) -> Self {
182 let mut m = Self::default();
183 if version >= 0 {
184 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
185 }
186 if version >= 0 {
187 m.partitions = vec![PartitionResult::populated(version)];
188 }
189 m
190 }
191}
192#[derive(Debug, Clone, PartialEq, Eq)]
193pub struct PartitionResult {
194 pub partition: i32,
195 pub error_code: i16,
196 pub error_message: Option<String>,
197 pub state_epoch: i32,
198 pub leader_epoch: i32,
199 pub start_offset: i64,
200 pub delivery_complete_count: i32,
201 pub unknown_tagged_fields: UnknownTaggedFields,
202}
203impl Default for PartitionResult {
204 fn default() -> Self {
205 Self {
206 partition: 0i32,
207 error_code: 0i16,
208 error_message: None,
209 state_epoch: 0i32,
210 leader_epoch: 0i32,
211 start_offset: 0i64,
212 delivery_complete_count: -1i32,
213 unknown_tagged_fields: Default::default(),
214 }
215 }
216}
217impl Encode for PartitionResult {
218 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
219 let flex = version >= 0;
220 if version >= 0 {
221 put_i32(buf, self.partition);
222 }
223 if version >= 0 {
224 put_i16(buf, self.error_code);
225 }
226 if version >= 0 {
227 if flex {
228 put_compact_nullable_string(buf, self.error_message.as_deref());
229 } else {
230 put_nullable_string(buf, self.error_message.as_deref());
231 }
232 }
233 if version >= 0 {
234 put_i32(buf, self.state_epoch);
235 }
236 if version >= 0 {
237 put_i32(buf, self.leader_epoch);
238 }
239 if version >= 0 {
240 put_i64(buf, self.start_offset);
241 }
242 if version >= 1 {
243 put_i32(buf, self.delivery_complete_count);
244 }
245 if flex {
246 let tagged = WriteTaggedFields::new();
247 tagged.write(buf, &self.unknown_tagged_fields);
248 }
249 Ok(())
250 }
251 fn encoded_len(&self, version: i16) -> usize {
252 let flex = version >= 0;
253 let mut n: usize = 0;
254 if version >= 0 {
255 n += 4;
256 }
257 if version >= 0 {
258 n += 2;
259 }
260 if version >= 0 {
261 n += if flex {
262 compact_nullable_string_len(self.error_message.as_deref())
263 } else {
264 nullable_string_len(self.error_message.as_deref())
265 };
266 }
267 if version >= 0 {
268 n += 4;
269 }
270 if version >= 0 {
271 n += 4;
272 }
273 if version >= 0 {
274 n += 8;
275 }
276 if version >= 1 {
277 n += 4;
278 }
279 if flex {
280 let known_pairs: Vec<(u32, usize)> = Vec::new();
281 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
282 }
283 n
284 }
285}
286impl Decode<'_> for PartitionResult {
287 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
288 let flex = version >= 0;
289 let mut out = Self::default();
290 if version >= 0 {
291 out.partition = get_i32(buf)?;
292 }
293 if version >= 0 {
294 out.error_code = get_i16(buf)?;
295 }
296 if version >= 0 {
297 out.error_message = if flex {
298 get_compact_nullable_string_owned(buf)?
299 } else {
300 get_nullable_string_owned(buf)?
301 };
302 }
303 if version >= 0 {
304 out.state_epoch = get_i32(buf)?;
305 }
306 if version >= 0 {
307 out.leader_epoch = get_i32(buf)?;
308 }
309 if version >= 0 {
310 out.start_offset = get_i64(buf)?;
311 }
312 if version >= 1 {
313 out.delivery_complete_count = get_i32(buf)?;
314 }
315 if flex {
316 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
317 }
318 Ok(out)
319 }
320}
321#[cfg(test)]
322impl PartitionResult {
323 #[must_use]
324 pub fn populated(version: i16) -> Self {
325 let mut m = Self::default();
326 if version >= 0 {
327 m.partition = 1i32;
328 }
329 if version >= 0 {
330 m.error_code = 1i16;
331 }
332 if version >= 0 {
333 m.error_message = Some("x".to_string());
334 }
335 if version >= 0 {
336 m.state_epoch = 1i32;
337 }
338 if version >= 0 {
339 m.leader_epoch = 1i32;
340 }
341 if version >= 0 {
342 m.start_offset = 1i64;
343 }
344 if version >= 1 {
345 m.delivery_complete_count = 1i32;
346 }
347 m
348 }
349}
350#[must_use]
353#[allow(unused_comparisons)]
354pub fn default_json(version: i16) -> ::serde_json::Value {
355 let mut obj = ::serde_json::Map::new();
356 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
357 ::serde_json::Value::Object(obj)
358}