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