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