Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryRequest.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_i32, put_i32},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 87;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
16pub const LATEST_STABLE_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ReadShareGroupStateSummaryRequest<'a> {
25    pub group_id: &'a str,
26    pub topics: Vec<ReadStateSummaryData>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl ReadShareGroupStateSummaryRequest<'_> {
30    /// # Panics
31    ///
32    /// Panics if a records field contains an invalid encoded record batch.
33    #[must_use]
34    pub fn to_owned(
35        &self,
36    ) -> crate::owned::read_share_group_state_summary_request::ReadShareGroupStateSummaryRequest
37    {
38        crate::owned::read_share_group_state_summary_request::ReadShareGroupStateSummaryRequest {
39            group_id: (self.group_id).to_string(),
40            topics: (self.topics)
41                .iter()
42                .map(ReadStateSummaryData::to_owned)
43                .collect(),
44            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
45        }
46    }
47}
48impl Encode for ReadShareGroupStateSummaryRequest<'_> {
49    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
50        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51            return Err(ProtocolError::UnsupportedVersion {
52                api_key: API_KEY,
53                version,
54            });
55        }
56        let flex = is_flexible(version);
57        if version >= 0 {
58            if flex {
59                let () = put_compact_string(buf, self.group_id);
60            } else {
61                let () = put_string(buf, self.group_id);
62            }
63        }
64        if version >= 0 {
65            {
66                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
67                for it in &self.topics {
68                    it.encode(buf, version)?;
69                }
70            };
71        }
72        if flex {
73            let tagged = WriteTaggedFields::new();
74            tagged.write(buf, &self.unknown_tagged_fields);
75        }
76        Ok(())
77    }
78    fn encoded_len(&self, version: i16) -> usize {
79        let flex = is_flexible(version);
80        let mut n: usize = 0;
81        if version >= 0 {
82            n += if flex {
83                compact_string_len(self.group_id)
84            } else {
85                string_len(self.group_id)
86            };
87        }
88        if version >= 0 {
89            n += {
90                let prefix =
91                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
92                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
93                prefix + body
94            };
95        }
96        if flex {
97            let known_pairs: Vec<(u32, usize)> = Vec::new();
98            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
99        }
100        n
101    }
102}
103impl<'de> DecodeBorrow<'de> for ReadShareGroupStateSummaryRequest<'de> {
104    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
105        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
106            return Err(ProtocolError::UnsupportedVersion {
107                api_key: API_KEY,
108                version,
109            });
110        }
111        let flex = is_flexible(version);
112        let mut out = Self::default();
113        if version >= 0 {
114            out.group_id = if flex {
115                get_compact_string_borrowed(buf)?
116            } else {
117                get_string_borrowed(buf)?
118            };
119        }
120        if version >= 0 {
121            out.topics = {
122                let n = crate::primitives::array::get_array_len(buf, flex)?;
123                let mut v = Vec::with_capacity(n);
124                for _ in 0..n {
125                    v.push(ReadStateSummaryData::decode_borrow(buf, version)?);
126                }
127                v
128            };
129        }
130        if flex {
131            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
132        }
133        Ok(out)
134    }
135}
136#[cfg(test)]
137impl ReadShareGroupStateSummaryRequest<'_> {
138    #[must_use]
139    pub fn populated(version: i16) -> Self {
140        let mut m = Self::default();
141        if version >= 0 {
142            m.group_id = "x";
143        }
144        if version >= 0 {
145            m.topics = vec![ReadStateSummaryData::populated(version)];
146        }
147        m
148    }
149}
150#[derive(Debug, Clone, PartialEq, Eq, Default)]
151pub struct ReadStateSummaryData {
152    pub topic_id: crate::primitives::uuid::Uuid,
153    pub partitions: Vec<PartitionData>,
154    pub unknown_tagged_fields: UnknownTaggedFields,
155}
156impl ReadStateSummaryData {
157    /// # Panics
158    ///
159    /// Panics if a records field contains an invalid encoded record batch.
160    #[must_use]
161    pub fn to_owned(
162        &self,
163    ) -> crate::owned::read_share_group_state_summary_request::ReadStateSummaryData {
164        crate::owned::read_share_group_state_summary_request::ReadStateSummaryData {
165            topic_id: (self.topic_id),
166            partitions: (self.partitions)
167                .iter()
168                .map(PartitionData::to_owned)
169                .collect(),
170            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
171        }
172    }
173}
174impl Encode for ReadStateSummaryData {
175    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
176        let flex = version >= 0;
177        if version >= 0 {
178            crate::primitives::uuid::put_uuid(buf, self.topic_id);
179        }
180        if version >= 0 {
181            {
182                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
183                for it in &self.partitions {
184                    it.encode(buf, version)?;
185                }
186            };
187        }
188        if flex {
189            let tagged = WriteTaggedFields::new();
190            tagged.write(buf, &self.unknown_tagged_fields);
191        }
192        Ok(())
193    }
194    fn encoded_len(&self, version: i16) -> usize {
195        let flex = version >= 0;
196        let mut n: usize = 0;
197        if version >= 0 {
198            n += 16;
199        }
200        if version >= 0 {
201            n += {
202                let prefix =
203                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
204                let body: usize = (self.partitions)
205                    .iter()
206                    .map(|it| it.encoded_len(version))
207                    .sum();
208                prefix + body
209            };
210        }
211        if flex {
212            let known_pairs: Vec<(u32, usize)> = Vec::new();
213            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
214        }
215        n
216    }
217}
218impl<'de> DecodeBorrow<'de> for ReadStateSummaryData {
219    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
220        let flex = version >= 0;
221        let mut out = Self::default();
222        if version >= 0 {
223            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
224        }
225        if version >= 0 {
226            out.partitions = {
227                let n = crate::primitives::array::get_array_len(buf, flex)?;
228                let mut v = Vec::with_capacity(n);
229                for _ in 0..n {
230                    v.push(PartitionData::decode_borrow(buf, version)?);
231                }
232                v
233            };
234        }
235        if flex {
236            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
237        }
238        Ok(out)
239    }
240}
241#[cfg(test)]
242impl ReadStateSummaryData {
243    #[must_use]
244    pub fn populated(version: i16) -> Self {
245        let mut m = Self::default();
246        if version >= 0 {
247            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
248        }
249        if version >= 0 {
250            m.partitions = vec![PartitionData::populated(version)];
251        }
252        m
253    }
254}
255#[derive(Debug, Clone, PartialEq, Eq, Default)]
256pub struct PartitionData {
257    pub partition: i32,
258    pub leader_epoch: i32,
259    pub unknown_tagged_fields: UnknownTaggedFields,
260}
261impl PartitionData {
262    /// # Panics
263    ///
264    /// Panics if a records field contains an invalid encoded record batch.
265    #[must_use]
266    pub fn to_owned(&self) -> crate::owned::read_share_group_state_summary_request::PartitionData {
267        crate::owned::read_share_group_state_summary_request::PartitionData {
268            partition: (self.partition),
269            leader_epoch: (self.leader_epoch),
270            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
271        }
272    }
273}
274impl Encode for PartitionData {
275    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
276        let flex = version >= 0;
277        if version >= 0 {
278            put_i32(buf, self.partition);
279        }
280        if version >= 0 {
281            put_i32(buf, self.leader_epoch);
282        }
283        if flex {
284            let tagged = WriteTaggedFields::new();
285            tagged.write(buf, &self.unknown_tagged_fields);
286        }
287        Ok(())
288    }
289    fn encoded_len(&self, version: i16) -> usize {
290        let flex = version >= 0;
291        let mut n: usize = 0;
292        if version >= 0 {
293            n += 4;
294        }
295        if version >= 0 {
296            n += 4;
297        }
298        if flex {
299            let known_pairs: Vec<(u32, usize)> = Vec::new();
300            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
301        }
302        n
303    }
304}
305impl<'de> DecodeBorrow<'de> for PartitionData {
306    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
307        let flex = version >= 0;
308        let mut out = Self::default();
309        if version >= 0 {
310            out.partition = get_i32(buf)?;
311        }
312        if version >= 0 {
313            out.leader_epoch = get_i32(buf)?;
314        }
315        if flex {
316            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
317        }
318        Ok(out)
319    }
320}
321#[cfg(test)]
322impl PartitionData {
323    #[must_use]
324    pub fn populated(version: i16) -> Self {
325        let mut m = Self::default();
326        if version >= 0 {
327            m.partition = 1i32;
328        }
329        if version >= 0 {
330            m.leader_epoch = 1i32;
331        }
332        m
333    }
334}