Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteGroupsResponse.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_i16, get_i32, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 42;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 3;
23pub const FLEXIBLE_MIN: i16 = 2;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct DeleteGroupsResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub results: Vec<DeletableGroupResult<'a>>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl DeleteGroupsResponse<'_> {
36    /// # Panics
37    ///
38    /// Panics if a records field contains an invalid encoded record batch.
39    #[must_use]
40    pub fn to_owned(&self) -> crate::owned::delete_groups_response::DeleteGroupsResponse {
41        crate::owned::delete_groups_response::DeleteGroupsResponse {
42            throttle_time_ms: (self.throttle_time_ms),
43            results: (self.results)
44                .iter()
45                .map(DeletableGroupResult::to_owned)
46                .collect(),
47            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
48        }
49    }
50}
51impl Encode for DeleteGroupsResponse<'_> {
52    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
53        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54            return Err(ProtocolError::UnsupportedVersion {
55                api_key: API_KEY,
56                version,
57            });
58        }
59        let flex = is_flexible(version);
60        if version >= 0 {
61            put_i32(buf, self.throttle_time_ms);
62        }
63        if version >= 0 {
64            {
65                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
66                for it in &self.results {
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 += 4;
82        }
83        if version >= 0 {
84            n += {
85                let prefix =
86                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
87                let body: usize = (self.results)
88                    .iter()
89                    .map(|it| it.encoded_len(version))
90                    .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 DeleteGroupsResponse<'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.throttle_time_ms = get_i32(buf)?;
113        }
114        if version >= 0 {
115            out.results = {
116                let n = crate::primitives::array::get_array_len(buf, flex)?;
117                let mut v = Vec::with_capacity(n);
118                for _ in 0..n {
119                    v.push(DeletableGroupResult::decode_borrow(buf, version)?);
120                }
121                v
122            };
123        }
124        if flex {
125            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
126        }
127        Ok(out)
128    }
129}
130#[cfg(test)]
131impl DeleteGroupsResponse<'_> {
132    #[must_use]
133    pub fn populated(version: i16) -> Self {
134        let mut m = Self::default();
135        if version >= 0 {
136            m.throttle_time_ms = 1i32;
137        }
138        if version >= 0 {
139            m.results = vec![DeletableGroupResult::populated(version)];
140        }
141        m
142    }
143}
144#[derive(Debug, Clone, PartialEq, Eq, Default)]
145pub struct DeletableGroupResult<'a> {
146    pub group_id: &'a str,
147    pub error_code: i16,
148    pub error_message: Option<&'a str>,
149    pub unknown_tagged_fields: UnknownTaggedFields,
150}
151impl DeletableGroupResult<'_> {
152    /// # Panics
153    ///
154    /// Panics if a records field contains an invalid encoded record batch.
155    #[must_use]
156    pub fn to_owned(&self) -> crate::owned::delete_groups_response::DeletableGroupResult {
157        crate::owned::delete_groups_response::DeletableGroupResult {
158            group_id: (self.group_id).to_string(),
159            error_code: (self.error_code),
160            error_message: (self.error_message).map(std::string::ToString::to_string),
161            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
162        }
163    }
164}
165impl Encode for DeletableGroupResult<'_> {
166    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
167        let flex = version >= 2;
168        if version >= 0 {
169            if flex {
170                let () = put_compact_string(buf, self.group_id);
171            } else {
172                let () = put_string(buf, self.group_id);
173            }
174        }
175        if version >= 0 {
176            put_i16(buf, self.error_code);
177        }
178        if version >= 3 {
179            if flex {
180                let () = put_compact_nullable_string(buf, self.error_message);
181            } else {
182                let () = put_nullable_string(buf, self.error_message);
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 >= 2;
193        let mut n: usize = 0;
194        if version >= 0 {
195            n += if flex {
196                compact_string_len(self.group_id)
197            } else {
198                string_len(self.group_id)
199            };
200        }
201        if version >= 0 {
202            n += 2;
203        }
204        if version >= 3 {
205            n += if flex {
206                compact_nullable_string_len(self.error_message)
207            } else {
208                nullable_string_len(self.error_message)
209            };
210        }
211        if flex {
212            let known_pairs: Vec<(u32, usize)> = Vec::new();
213            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
214        }
215        n
216    }
217}
218impl<'de> DecodeBorrow<'de> for DeletableGroupResult<'de> {
219    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
220        let flex = version >= 2;
221        let mut out = Self::default();
222        if version >= 0 {
223            out.group_id = if flex {
224                get_compact_string_borrowed(buf)?
225            } else {
226                get_string_borrowed(buf)?
227            };
228        }
229        if version >= 0 {
230            out.error_code = get_i16(buf)?;
231        }
232        if version >= 3 {
233            out.error_message = if flex {
234                get_compact_nullable_string_borrowed(buf)?
235            } else {
236                get_nullable_string_borrowed(buf)?
237            };
238        }
239        if flex {
240            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
241        }
242        Ok(out)
243    }
244}
245#[cfg(test)]
246impl DeletableGroupResult<'_> {
247    #[must_use]
248    pub fn populated(version: i16) -> Self {
249        let mut m = Self::default();
250        if version >= 0 {
251            m.group_id = "x";
252        }
253        if version >= 0 {
254            m.error_code = 1i16;
255        }
256        if version >= 3 {
257            m.error_message = Some("x");
258        }
259        m
260    }
261}