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