Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteShareGroupStateRequest.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 = 86;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const LATEST_STABLE_VERSION: i16 = 0;
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 DeleteShareGroupStateRequest<'a> {
25    pub group_id: &'a str,
26    pub topics: Vec<DeleteStateData>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl DeleteShareGroupStateRequest<'_> {
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::delete_share_group_state_request::DeleteShareGroupStateRequest {
37        crate::owned::delete_share_group_state_request::DeleteShareGroupStateRequest {
38            group_id: (self.group_id).to_string(),
39            topics: (self.topics)
40                .iter()
41                .map(DeleteStateData::to_owned)
42                .collect(),
43            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
44        }
45    }
46}
47impl Encode for DeleteShareGroupStateRequest<'_> {
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                let () = put_compact_string(buf, self.group_id);
59            } else {
60                let () = put_string(buf, self.group_id);
61            }
62        }
63        if version >= 0 {
64            {
65                crate::primitives::array::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 =
90                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
91                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
92                prefix + body
93            };
94        }
95        if flex {
96            let known_pairs: Vec<(u32, usize)> = Vec::new();
97            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
98        }
99        n
100    }
101}
102impl<'de> DecodeBorrow<'de> for DeleteShareGroupStateRequest<'de> {
103    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
104        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
105            return Err(ProtocolError::UnsupportedVersion {
106                api_key: API_KEY,
107                version,
108            });
109        }
110        let flex = is_flexible(version);
111        let mut out = Self::default();
112        if version >= 0 {
113            out.group_id = if flex {
114                get_compact_string_borrowed(buf)?
115            } else {
116                get_string_borrowed(buf)?
117            };
118        }
119        if version >= 0 {
120            out.topics = {
121                let n = crate::primitives::array::get_array_len(buf, flex)?;
122                let mut v = Vec::with_capacity(n);
123                for _ in 0..n {
124                    v.push(DeleteStateData::decode_borrow(buf, version)?);
125                }
126                v
127            };
128        }
129        if flex {
130            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
131        }
132        Ok(out)
133    }
134}
135#[cfg(test)]
136impl DeleteShareGroupStateRequest<'_> {
137    #[must_use]
138    pub fn populated(version: i16) -> Self {
139        let mut m = Self::default();
140        if version >= 0 {
141            m.group_id = "x";
142        }
143        if version >= 0 {
144            m.topics = vec![DeleteStateData::populated(version)];
145        }
146        m
147    }
148}
149#[derive(Debug, Clone, PartialEq, Eq, Default)]
150pub struct DeleteStateData {
151    pub topic_id: crate::primitives::uuid::Uuid,
152    pub partitions: Vec<PartitionData>,
153    pub unknown_tagged_fields: UnknownTaggedFields,
154}
155impl DeleteStateData {
156    /// # Panics
157    ///
158    /// Panics if a records field contains an invalid encoded record batch.
159    #[must_use]
160    pub fn to_owned(&self) -> crate::owned::delete_share_group_state_request::DeleteStateData {
161        crate::owned::delete_share_group_state_request::DeleteStateData {
162            topic_id: (self.topic_id),
163            partitions: (self.partitions)
164                .iter()
165                .map(PartitionData::to_owned)
166                .collect(),
167            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
168        }
169    }
170}
171impl Encode for DeleteStateData {
172    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
173        let flex = version >= 0;
174        if version >= 0 {
175            crate::primitives::uuid::put_uuid(buf, self.topic_id);
176        }
177        if version >= 0 {
178            {
179                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
180                for it in &self.partitions {
181                    it.encode(buf, version)?;
182                }
183            };
184        }
185        if flex {
186            let tagged = WriteTaggedFields::new();
187            tagged.write(buf, &self.unknown_tagged_fields);
188        }
189        Ok(())
190    }
191    fn encoded_len(&self, version: i16) -> usize {
192        let flex = version >= 0;
193        let mut n: usize = 0;
194        if version >= 0 {
195            n += 16;
196        }
197        if version >= 0 {
198            n += {
199                let prefix =
200                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
201                let body: usize = (self.partitions)
202                    .iter()
203                    .map(|it| it.encoded_len(version))
204                    .sum();
205                prefix + body
206            };
207        }
208        if flex {
209            let known_pairs: Vec<(u32, usize)> = Vec::new();
210            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
211        }
212        n
213    }
214}
215impl<'de> DecodeBorrow<'de> for DeleteStateData {
216    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
217        let flex = version >= 0;
218        let mut out = Self::default();
219        if version >= 0 {
220            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
221        }
222        if version >= 0 {
223            out.partitions = {
224                let n = crate::primitives::array::get_array_len(buf, flex)?;
225                let mut v = Vec::with_capacity(n);
226                for _ in 0..n {
227                    v.push(PartitionData::decode_borrow(buf, version)?);
228                }
229                v
230            };
231        }
232        if flex {
233            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
234        }
235        Ok(out)
236    }
237}
238#[cfg(test)]
239impl DeleteStateData {
240    #[must_use]
241    pub fn populated(version: i16) -> Self {
242        let mut m = Self::default();
243        if version >= 0 {
244            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
245        }
246        if version >= 0 {
247            m.partitions = vec![PartitionData::populated(version)];
248        }
249        m
250    }
251}
252#[derive(Debug, Clone, PartialEq, Eq, Default)]
253pub struct PartitionData {
254    pub partition: i32,
255    pub unknown_tagged_fields: UnknownTaggedFields,
256}
257impl PartitionData {
258    /// # Panics
259    ///
260    /// Panics if a records field contains an invalid encoded record batch.
261    #[must_use]
262    pub fn to_owned(&self) -> crate::owned::delete_share_group_state_request::PartitionData {
263        crate::owned::delete_share_group_state_request::PartitionData {
264            partition: (self.partition),
265            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
266        }
267    }
268}
269impl Encode for PartitionData {
270    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
271        let flex = version >= 0;
272        if version >= 0 {
273            put_i32(buf, self.partition);
274        }
275        if flex {
276            let tagged = WriteTaggedFields::new();
277            tagged.write(buf, &self.unknown_tagged_fields);
278        }
279        Ok(())
280    }
281    fn encoded_len(&self, version: i16) -> usize {
282        let flex = version >= 0;
283        let mut n: usize = 0;
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 flex {
302            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
303        }
304        Ok(out)
305    }
306}
307#[cfg(test)]
308impl PartitionData {
309    #[must_use]
310    pub fn populated(version: i16) -> Self {
311        let mut m = Self::default();
312        if version >= 0 {
313            m.partition = 1i32;
314        }
315        m
316    }
317}