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