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