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