Skip to main content

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

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