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