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