Skip to main content

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