Skip to main content

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