Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryResponse.borrowed.rs

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