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