Skip to main content

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