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