crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryResponse.borrowed.rs1use bytes::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, nullable_string_len, put_compact_nullable_string,
8 put_nullable_string,
9};
10use crate::primitives::string_bytes_borrowed::{
11 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
12};
13use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
14use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
15
16pub const API_KEY: i16 = 87;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 1;
19pub const FLEXIBLE_MIN: i16 = 0;
20
21#[inline]
22fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct ReadShareGroupStateSummaryResponse<'a> {
28 pub results: Vec<ReadStateSummaryResult<'a>>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl ReadShareGroupStateSummaryResponse<'_> {
32 pub fn to_owned(
33 &self,
34 ) -> crate::owned::read_share_group_state_summary_response::ReadShareGroupStateSummaryResponse
35 {
36 crate::owned::read_share_group_state_summary_response::ReadShareGroupStateSummaryResponse {
37 results: (self.results)
38 .iter()
39 .map(ReadStateSummaryResult::to_owned)
40 .collect(),
41 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
42 }
43 }
44}
45impl Encode for ReadShareGroupStateSummaryResponse<'_> {
46 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
47 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48 return Err(ProtocolError::UnsupportedVersion {
49 api_key: API_KEY,
50 version,
51 });
52 }
53 let flex = is_flexible(version);
54 if version >= 0 {
55 {
56 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
57 for it in &self.results {
58 it.encode(buf, version)?;
59 }
60 }
61 }
62 if flex {
63 let tagged = WriteTaggedFields::new();
64 tagged.write(buf, &self.unknown_tagged_fields);
65 }
66 Ok(())
67 }
68 fn encoded_len(&self, version: i16) -> usize {
69 let flex = is_flexible(version);
70 let mut n: usize = 0;
71 if version >= 0 {
72 n += {
73 let prefix =
74 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
75 let body: usize = (self.results)
76 .iter()
77 .map(|it| it.encoded_len(version))
78 .sum();
79 prefix + body
80 };
81 }
82 if flex {
83 let known_pairs: Vec<(u32, usize)> = Vec::new();
84 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
85 }
86 n
87 }
88}
89impl<'de> DecodeBorrow<'de> for ReadShareGroupStateSummaryResponse<'de> {
90 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
91 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
92 return Err(ProtocolError::UnsupportedVersion {
93 api_key: API_KEY,
94 version,
95 });
96 }
97 let flex = is_flexible(version);
98 let mut out = Self::default();
99 if version >= 0 {
100 out.results = {
101 let n = crate::primitives::array::get_array_len(buf, flex)?;
102 let mut v = Vec::with_capacity(n);
103 for _ in 0..n {
104 v.push(ReadStateSummaryResult::decode_borrow(buf, version)?);
105 }
106 v
107 };
108 }
109 if flex {
110 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
111 }
112 Ok(out)
113 }
114}
115#[cfg(test)]
116impl ReadShareGroupStateSummaryResponse<'_> {
117 #[must_use]
118 pub fn populated(version: i16) -> Self {
119 let mut m = Self::default();
120 if version >= 0 {
121 m.results = vec![ReadStateSummaryResult::populated(version)];
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq, Default)]
127pub struct ReadStateSummaryResult<'a> {
128 pub topic_id: crate::primitives::uuid::Uuid,
129 pub partitions: Vec<PartitionResult<'a>>,
130 pub unknown_tagged_fields: UnknownTaggedFields,
131}
132impl ReadStateSummaryResult<'_> {
133 pub fn to_owned(
134 &self,
135 ) -> crate::owned::read_share_group_state_summary_response::ReadStateSummaryResult {
136 crate::owned::read_share_group_state_summary_response::ReadStateSummaryResult {
137 topic_id: (self.topic_id),
138 partitions: (self.partitions)
139 .iter()
140 .map(PartitionResult::to_owned)
141 .collect(),
142 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
143 }
144 }
145}
146impl Encode for ReadStateSummaryResult<'_> {
147 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
148 let flex = version >= 0;
149 if version >= 0 {
150 crate::primitives::uuid::put_uuid(buf, self.topic_id);
151 }
152 if version >= 0 {
153 {
154 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
155 for it in &self.partitions {
156 it.encode(buf, version)?;
157 }
158 }
159 }
160 if flex {
161 let tagged = WriteTaggedFields::new();
162 tagged.write(buf, &self.unknown_tagged_fields);
163 }
164 Ok(())
165 }
166 fn encoded_len(&self, version: i16) -> usize {
167 let flex = version >= 0;
168 let mut n: usize = 0;
169 if version >= 0 {
170 n += 16;
171 }
172 if version >= 0 {
173 n += {
174 let prefix =
175 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
176 let body: usize = (self.partitions)
177 .iter()
178 .map(|it| it.encoded_len(version))
179 .sum();
180 prefix + body
181 };
182 }
183 if flex {
184 let known_pairs: Vec<(u32, usize)> = Vec::new();
185 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
186 }
187 n
188 }
189}
190impl<'de> DecodeBorrow<'de> for ReadStateSummaryResult<'de> {
191 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
192 let flex = version >= 0;
193 let mut out = Self::default();
194 if version >= 0 {
195 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
196 }
197 if version >= 0 {
198 out.partitions = {
199 let n = crate::primitives::array::get_array_len(buf, flex)?;
200 let mut v = Vec::with_capacity(n);
201 for _ in 0..n {
202 v.push(PartitionResult::decode_borrow(buf, version)?);
203 }
204 v
205 };
206 }
207 if flex {
208 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
209 }
210 Ok(out)
211 }
212}
213#[cfg(test)]
214impl ReadStateSummaryResult<'_> {
215 #[must_use]
216 pub fn populated(version: i16) -> Self {
217 let mut m = Self::default();
218 if version >= 0 {
219 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
220 }
221 if version >= 0 {
222 m.partitions = vec![PartitionResult::populated(version)];
223 }
224 m
225 }
226}
227#[derive(Debug, Clone, PartialEq, Eq)]
228pub struct PartitionResult<'a> {
229 pub partition: i32,
230 pub error_code: i16,
231 pub error_message: Option<&'a str>,
232 pub state_epoch: i32,
233 pub leader_epoch: i32,
234 pub start_offset: i64,
235 pub delivery_complete_count: i32,
236 pub unknown_tagged_fields: UnknownTaggedFields,
237}
238impl Default for PartitionResult<'_> {
239 fn default() -> Self {
240 Self {
241 partition: 0i32,
242 error_code: 0i16,
243 error_message: None,
244 state_epoch: 0i32,
245 leader_epoch: 0i32,
246 start_offset: 0i64,
247 delivery_complete_count: -1i32,
248 unknown_tagged_fields: Default::default(),
249 }
250 }
251}
252impl PartitionResult<'_> {
253 pub fn to_owned(
254 &self,
255 ) -> crate::owned::read_share_group_state_summary_response::PartitionResult {
256 crate::owned::read_share_group_state_summary_response::PartitionResult {
257 partition: (self.partition),
258 error_code: (self.error_code),
259 error_message: (self.error_message).map(std::string::ToString::to_string),
260 state_epoch: (self.state_epoch),
261 leader_epoch: (self.leader_epoch),
262 start_offset: (self.start_offset),
263 delivery_complete_count: (self.delivery_complete_count),
264 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
265 }
266 }
267}
268impl Encode for PartitionResult<'_> {
269 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
270 let flex = version >= 0;
271 if version >= 0 {
272 put_i32(buf, self.partition);
273 }
274 if version >= 0 {
275 put_i16(buf, self.error_code);
276 }
277 if version >= 0 {
278 if flex {
279 put_compact_nullable_string(buf, self.error_message);
280 } else {
281 put_nullable_string(buf, self.error_message);
282 }
283 }
284 if version >= 0 {
285 put_i32(buf, self.state_epoch);
286 }
287 if version >= 0 {
288 put_i32(buf, self.leader_epoch);
289 }
290 if version >= 0 {
291 put_i64(buf, self.start_offset);
292 }
293 if version >= 1 {
294 put_i32(buf, self.delivery_complete_count);
295 }
296 if flex {
297 let tagged = WriteTaggedFields::new();
298 tagged.write(buf, &self.unknown_tagged_fields);
299 }
300 Ok(())
301 }
302 fn encoded_len(&self, version: i16) -> usize {
303 let flex = version >= 0;
304 let mut n: usize = 0;
305 if version >= 0 {
306 n += 4;
307 }
308 if version >= 0 {
309 n += 2;
310 }
311 if version >= 0 {
312 n += if flex {
313 compact_nullable_string_len(self.error_message)
314 } else {
315 nullable_string_len(self.error_message)
316 };
317 }
318 if version >= 0 {
319 n += 4;
320 }
321 if version >= 0 {
322 n += 4;
323 }
324 if version >= 0 {
325 n += 8;
326 }
327 if version >= 1 {
328 n += 4;
329 }
330 if flex {
331 let known_pairs: Vec<(u32, usize)> = Vec::new();
332 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
333 }
334 n
335 }
336}
337impl<'de> DecodeBorrow<'de> for PartitionResult<'de> {
338 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
339 let flex = version >= 0;
340 let mut out = Self::default();
341 if version >= 0 {
342 out.partition = get_i32(buf)?;
343 }
344 if version >= 0 {
345 out.error_code = get_i16(buf)?;
346 }
347 if version >= 0 {
348 out.error_message = if flex {
349 get_compact_nullable_string_borrowed(buf)?
350 } else {
351 get_nullable_string_borrowed(buf)?
352 };
353 }
354 if version >= 0 {
355 out.state_epoch = get_i32(buf)?;
356 }
357 if version >= 0 {
358 out.leader_epoch = get_i32(buf)?;
359 }
360 if version >= 0 {
361 out.start_offset = get_i64(buf)?;
362 }
363 if version >= 1 {
364 out.delivery_complete_count = get_i32(buf)?;
365 }
366 if flex {
367 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
368 }
369 Ok(out)
370 }
371}
372#[cfg(test)]
373impl PartitionResult<'_> {
374 #[must_use]
375 pub fn populated(version: i16) -> Self {
376 let mut m = Self::default();
377 if version >= 0 {
378 m.partition = 1i32;
379 }
380 if version >= 0 {
381 m.error_code = 1i16;
382 }
383 if version >= 0 {
384 m.error_message = Some("x");
385 }
386 if version >= 0 {
387 m.state_epoch = 1i32;
388 }
389 if version >= 0 {
390 m.leader_epoch = 1i32;
391 }
392 if version >= 0 {
393 m.start_offset = 1i64;
394 }
395 if version >= 1 {
396 m.delivery_complete_count = 1i32;
397 }
398 m
399 }
400}