Skip to main content

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