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