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