krabka_protocol/opt/rustwide/workdir/generated/
DeleteTopicsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i32, 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 LATEST_STABLE_VERSION: i16 = 6;
22pub const FLEXIBLE_MIN: i16 = 4;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct DeleteTopicsRequest {
30 pub topics: Vec<DeleteTopicState>,
31 pub topic_names: Vec<String>,
32 pub timeout_ms: i32,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for DeleteTopicsRequest {
36 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38 return Err(ProtocolError::UnsupportedVersion {
39 api_key: API_KEY,
40 version,
41 });
42 }
43 let flex = is_flexible(version);
44 if version >= 6 {
45 {
46 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
47 for it in &self.topics {
48 it.encode(buf, version)?;
49 }
50 };
51 }
52 if (0..=5).contains(&version) {
53 {
54 crate::primitives::array::put_array_len(buf, (self.topic_names).len(), flex);
55 for it in &self.topic_names {
56 if flex {
57 let () = put_compact_string(buf, it);
58 } else {
59 let () = put_string(buf, it);
60 }
61 }
62 };
63 }
64 if version >= 0 {
65 put_i32(buf, self.timeout_ms);
66 }
67 if flex {
68 let tagged = WriteTaggedFields::new();
69 tagged.write(buf, &self.unknown_tagged_fields);
70 }
71 Ok(())
72 }
73 fn encoded_len(&self, version: i16) -> usize {
74 let flex = is_flexible(version);
75 let mut n: usize = 0;
76 if version >= 6 {
77 n += {
78 let prefix =
79 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
80 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
81 prefix + body
82 };
83 }
84 if (0..=5).contains(&version) {
85 n += {
86 let prefix =
87 crate::primitives::array::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 = crate::primitives::array::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 = crate::primitives::array::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_string()];
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: crate::primitives::uuid::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 let () = put_compact_nullable_string(buf, self.name.as_deref());
183 } else {
184 let () = put_nullable_string(buf, self.name.as_deref());
185 }
186 }
187 if version >= 6 {
188 crate::primitives::uuid::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 = crate::primitives::uuid::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_string());
243 }
244 if version >= 6 {
245 m.topic_id = crate::primitives::uuid::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_string(), ::serde_json::Value::Array(vec![]));
258 }
259 if version <= 5 {
260 obj.insert("topicNames".to_string(), ::serde_json::Value::Array(vec![]));
261 }
262 obj.insert("timeoutMs".to_string(), ::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}