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