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