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