Skip to main content

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

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