krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 owned::read_share_group_state_summary_response,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
10 string_bytes::{
11 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
12 put_nullable_string,
13 },
14 string_bytes_borrowed::{
15 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
16 },
17 uuid::{Uuid, get_uuid, put_uuid},
18 },
19 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
20};
21pub const API_KEY: i16 = 87;
22pub const MIN_VERSION: i16 = 0;
23pub const MAX_VERSION: i16 = 1;
24pub const FLEXIBLE_MIN: i16 = 0;
25#[inline]
26#[must_use]
27pub fn is_flexible(version: i16) -> bool {
28 version >= FLEXIBLE_MIN
29}
30#[derive(Debug, Clone, PartialEq, Eq, Default)]
31pub struct ReadShareGroupStateSummaryResponse<'a> {
32 pub results: Vec<ReadStateSummaryResult<'a>>,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl ReadShareGroupStateSummaryResponse<'_> {
36 #[must_use]
37 pub fn to_owned(
38 &self,
39 ) -> read_share_group_state_summary_response::ReadShareGroupStateSummaryResponse {
40 read_share_group_state_summary_response::ReadShareGroupStateSummaryResponse {
41 results: (self.results)
42 .iter()
43 .map(ReadStateSummaryResult::to_owned)
44 .collect(),
45 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46 }
47 }
48}
49impl Encode for ReadShareGroupStateSummaryResponse<'_> {
50 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
51 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52 return Err(ProtocolError::UnsupportedVersion {
53 api_key: API_KEY,
54 version,
55 });
56 }
57 let flex = is_flexible(version);
58 if version >= 0 {
59 {
60 put_array_len(buf, (self.results).len(), flex)?;
61 for it in &self.results {
62 it.encode(buf, version)?;
63 }
64 }
65 }
66 if flex {
67 let tagged = WriteTaggedFields::new();
68 tagged.write(buf, &self.unknown_tagged_fields)?;
69 }
70 Ok(())
71 }
72 fn encoded_len(&self, version: i16) -> usize {
73 let flex = is_flexible(version);
74 let mut n: usize = 0;
75 if version >= 0 {
76 n += {
77 let prefix = array_len_prefix_len((self.results).len(), flex);
78 let body: usize = (self.results)
79 .iter()
80 .map(|it| it.encoded_len(version))
81 .sum();
82 prefix + body
83 };
84 }
85 if flex {
86 let known_pairs: Vec<(u32, usize)> = Vec::new();
87 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
88 }
89 n
90 }
91}
92impl<'de> DecodeBorrow<'de> for ReadShareGroupStateSummaryResponse<'de> {
93 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
94 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95 return Err(ProtocolError::UnsupportedVersion {
96 api_key: API_KEY,
97 version,
98 });
99 }
100 let flex = is_flexible(version);
101 let mut out = Self::default();
102 if version >= 0 {
103 out.results = {
104 let n = get_array_len(buf, flex)?;
105 let mut v = Vec::with_capacity(n);
106 for _ in 0..n {
107 v.push(ReadStateSummaryResult::decode_borrow(buf, version)?);
108 }
109 v
110 };
111 }
112 if flex {
113 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
114 }
115 Ok(out)
116 }
117}
118#[cfg(test)]
119impl ReadShareGroupStateSummaryResponse<'_> {
120 #[must_use]
121 pub fn populated(version: i16) -> Self {
122 let mut m = Self::default();
123 if version >= 0 {
124 m.results = vec![ReadStateSummaryResult::populated(version)];
125 }
126 m
127 }
128}
129#[derive(Debug, Clone, PartialEq, Eq, Default)]
130pub struct ReadStateSummaryResult<'a> {
131 pub topic_id: Uuid,
132 pub partitions: Vec<PartitionResult<'a>>,
133 pub unknown_tagged_fields: UnknownTaggedFields,
134}
135impl ReadStateSummaryResult<'_> {
136 #[must_use]
137 pub fn to_owned(&self) -> read_share_group_state_summary_response::ReadStateSummaryResult {
138 read_share_group_state_summary_response::ReadStateSummaryResult {
139 topic_id: (self.topic_id),
140 partitions: (self.partitions)
141 .iter()
142 .map(PartitionResult::to_owned)
143 .collect(),
144 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
145 }
146 }
147}
148impl Encode for ReadStateSummaryResult<'_> {
149 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
150 let flex = version >= 0;
151 if version >= 0 {
152 put_uuid(buf, self.topic_id);
153 }
154 if version >= 0 {
155 {
156 put_array_len(buf, (self.partitions).len(), flex)?;
157 for it in &self.partitions {
158 it.encode(buf, version)?;
159 }
160 }
161 }
162 if flex {
163 let tagged = WriteTaggedFields::new();
164 tagged.write(buf, &self.unknown_tagged_fields)?;
165 }
166 Ok(())
167 }
168 fn encoded_len(&self, version: i16) -> usize {
169 let flex = version >= 0;
170 let mut n: usize = 0;
171 if version >= 0 {
172 n += 16;
173 }
174 if version >= 0 {
175 n += {
176 let prefix = array_len_prefix_len((self.partitions).len(), flex);
177 let body: usize = (self.partitions)
178 .iter()
179 .map(|it| it.encoded_len(version))
180 .sum();
181 prefix + body
182 };
183 }
184 if flex {
185 let known_pairs: Vec<(u32, usize)> = Vec::new();
186 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
187 }
188 n
189 }
190}
191impl<'de> DecodeBorrow<'de> for ReadStateSummaryResult<'de> {
192 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
193 let flex = version >= 0;
194 let mut out = Self::default();
195 if version >= 0 {
196 out.topic_id = get_uuid(buf)?;
197 }
198 if version >= 0 {
199 out.partitions = {
200 let n = get_array_len(buf, flex)?;
201 let mut v = Vec::with_capacity(n);
202 for _ in 0..n {
203 v.push(PartitionResult::decode_borrow(buf, version)?);
204 }
205 v
206 };
207 }
208 if flex {
209 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
210 }
211 Ok(out)
212 }
213}
214#[cfg(test)]
215impl ReadStateSummaryResult<'_> {
216 #[must_use]
217 pub fn populated(version: i16) -> Self {
218 let mut m = Self::default();
219 if version >= 0 {
220 m.topic_id = Uuid([1u8; 16]);
221 }
222 if version >= 0 {
223 m.partitions = vec![PartitionResult::populated(version)];
224 }
225 m
226 }
227}
228#[derive(Debug, Clone, PartialEq, Eq)]
229pub struct PartitionResult<'a> {
230 pub partition: i32,
231 pub error_code: i16,
232 pub error_message: Option<&'a str>,
233 pub state_epoch: i32,
234 pub leader_epoch: i32,
235 pub start_offset: i64,
236 pub delivery_complete_count: i32,
237 pub unknown_tagged_fields: UnknownTaggedFields,
238}
239impl Default for PartitionResult<'_> {
240 fn default() -> Self {
241 Self {
242 partition: 0i32,
243 error_code: 0i16,
244 error_message: None,
245 state_epoch: 0i32,
246 leader_epoch: 0i32,
247 start_offset: 0i64,
248 delivery_complete_count: -1i32,
249 unknown_tagged_fields: UnknownTaggedFields::default(),
250 }
251 }
252}
253impl PartitionResult<'_> {
254 #[must_use]
255 pub fn to_owned(&self) -> read_share_group_state_summary_response::PartitionResult {
256 read_share_group_state_summary_response::PartitionResult {
257 partition: (self.partition),
258 error_code: (self.error_code),
259 error_message: (self.error_message).map(str::to_owned),
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}