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