Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteResponse.borrowed.rs

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