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