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