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