krabka_protocol/opt/rustwide/workdir/generated/
DeleteRecordsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i32, get_i64, put_i32, put_i64},
10 string_bytes::{
11 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
12 put_string, string_len,
13 },
14 },
15 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 21;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 2;
20pub const LATEST_STABLE_VERSION: i16 = 2;
21pub const FLEXIBLE_MIN: i16 = 2;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct DeleteRecordsRequest {
29 pub topics: Vec<DeleteRecordsTopic>,
30 pub timeout_ms: i32,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for DeleteRecordsRequest {
34 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36 return Err(ProtocolError::UnsupportedVersion {
37 api_key: API_KEY,
38 version,
39 });
40 }
41 let flex = is_flexible(version);
42 if version >= 0 {
43 {
44 put_array_len(buf, (self.topics).len(), flex)?;
45 for it in &self.topics {
46 it.encode(buf, version)?;
47 }
48 }
49 }
50 if version >= 0 {
51 put_i32(buf, self.timeout_ms);
52 }
53 if flex {
54 let tagged = WriteTaggedFields::new();
55 tagged.write(buf, &self.unknown_tagged_fields)?;
56 }
57 Ok(())
58 }
59 fn encoded_len(&self, version: i16) -> usize {
60 let flex = is_flexible(version);
61 let mut n: usize = 0;
62 if version >= 0 {
63 n += {
64 let prefix = 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 = 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 put_compact_string(buf, &self.name)?;
134 } else {
135 put_string(buf, &self.name)?;
136 }
137 }
138 if version >= 0 {
139 {
140 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 = array_len_prefix_len((self.partitions).len(), flex);
165 let body: usize = (self.partitions)
166 .iter()
167 .map(|it| it.encoded_len(version))
168 .sum();
169 prefix + body
170 };
171 }
172 if flex {
173 let known_pairs: Vec<(u32, usize)> = Vec::new();
174 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
175 }
176 n
177 }
178}
179impl Decode<'_> for DeleteRecordsTopic {
180 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181 let flex = version >= 2;
182 let mut out = Self::default();
183 if version >= 0 {
184 out.name = if flex {
185 get_compact_string_owned(buf)?
186 } else {
187 get_string_owned(buf)?
188 };
189 }
190 if version >= 0 {
191 out.partitions = {
192 let n = get_array_len(buf, flex)?;
193 let mut v = Vec::with_capacity(n);
194 for _ in 0..n {
195 v.push(DeleteRecordsPartition::decode(buf, version)?);
196 }
197 v
198 };
199 }
200 if flex {
201 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
202 }
203 Ok(out)
204 }
205}
206#[cfg(test)]
207impl DeleteRecordsTopic {
208 #[must_use]
209 pub fn populated(version: i16) -> Self {
210 let mut m = Self::default();
211 if version >= 0 {
212 m.name = "x".to_owned();
213 }
214 if version >= 0 {
215 m.partitions = vec![DeleteRecordsPartition::populated(version)];
216 }
217 m
218 }
219}
220#[derive(Debug, Clone, PartialEq, Eq, Default)]
221pub struct DeleteRecordsPartition {
222 pub partition_index: i32,
223 pub offset: i64,
224 pub unknown_tagged_fields: UnknownTaggedFields,
225}
226impl Encode for DeleteRecordsPartition {
227 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
228 let flex = version >= 2;
229 if version >= 0 {
230 put_i32(buf, self.partition_index);
231 }
232 if version >= 0 {
233 put_i64(buf, self.offset);
234 }
235 if flex {
236 let tagged = WriteTaggedFields::new();
237 tagged.write(buf, &self.unknown_tagged_fields)?;
238 }
239 Ok(())
240 }
241 fn encoded_len(&self, version: i16) -> usize {
242 let flex = version >= 2;
243 let mut n: usize = 0;
244 if version >= 0 {
245 n += 4;
246 }
247 if version >= 0 {
248 n += 8;
249 }
250 if flex {
251 let known_pairs: Vec<(u32, usize)> = Vec::new();
252 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
253 }
254 n
255 }
256}
257impl Decode<'_> for DeleteRecordsPartition {
258 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
259 let flex = version >= 2;
260 let mut out = Self::default();
261 if version >= 0 {
262 out.partition_index = get_i32(buf)?;
263 }
264 if version >= 0 {
265 out.offset = get_i64(buf)?;
266 }
267 if flex {
268 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
269 }
270 Ok(out)
271 }
272}
273#[cfg(test)]
274impl DeleteRecordsPartition {
275 #[must_use]
276 pub fn populated(version: i16) -> Self {
277 let mut m = Self::default();
278 if version >= 0 {
279 m.partition_index = 1i32;
280 }
281 if version >= 0 {
282 m.offset = 1i64;
283 }
284 m
285 }
286}
287#[must_use]
290#[allow(unused_comparisons)]
291pub fn default_json(_version: i16) -> ::serde_json::Value {
292 let mut obj = ::serde_json::Map::new();
293 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
294 obj.insert("timeoutMs".to_owned(), ::serde_json::json!(0));
295 ::serde_json::Value::Object(obj)
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 LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
302 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
303 type Response = super::delete_records_response::DeleteRecordsResponse;
304}