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