krabka_protocol/opt/rustwide/workdir/generated/
DeleteRecordsResponse.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_i16, get_i32, get_i64, put_i16, 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 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 DeleteRecordsResponse {
28 pub throttle_time_ms: i32,
29 pub topics: Vec<DeleteRecordsTopicResult>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for DeleteRecordsResponse {
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 put_i32(buf, self.throttle_time_ms);
43 }
44 if version >= 0 {
45 {
46 put_array_len(buf, (self.topics).len(), flex)?;
47 for it in &self.topics {
48 it.encode(buf, version)?;
49 }
50 }
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 += 4;
63 }
64 if version >= 0 {
65 n += {
66 let prefix = array_len_prefix_len((self.topics).len(), flex);
67 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
68 prefix + body
69 };
70 }
71 if flex {
72 let known_pairs: Vec<(u32, usize)> = Vec::new();
73 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
74 }
75 n
76 }
77}
78impl Decode<'_> for DeleteRecordsResponse {
79 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
80 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
81 return Err(ProtocolError::UnsupportedVersion {
82 api_key: API_KEY,
83 version,
84 });
85 }
86 let flex = is_flexible(version);
87 let mut out = Self::default();
88 if version >= 0 {
89 out.throttle_time_ms = get_i32(buf)?;
90 }
91 if version >= 0 {
92 out.topics = {
93 let n = get_array_len(buf, flex)?;
94 let mut v = Vec::with_capacity(n);
95 for _ in 0..n {
96 v.push(DeleteRecordsTopicResult::decode(buf, version)?);
97 }
98 v
99 };
100 }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
103 }
104 Ok(out)
105 }
106}
107#[cfg(test)]
108impl DeleteRecordsResponse {
109 #[must_use]
110 pub fn populated(version: i16) -> Self {
111 let mut m = Self::default();
112 if version >= 0 {
113 m.throttle_time_ms = 1i32;
114 }
115 if version >= 0 {
116 m.topics = vec![DeleteRecordsTopicResult::populated(version)];
117 }
118 m
119 }
120}
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct DeleteRecordsTopicResult {
123 pub name: String,
124 pub partitions: Vec<DeleteRecordsPartitionResult>,
125 pub unknown_tagged_fields: UnknownTaggedFields,
126}
127impl Encode for DeleteRecordsTopicResult {
128 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
129 let flex = version >= 2;
130 if version >= 0 {
131 if flex {
132 put_compact_string(buf, &self.name)?;
133 } else {
134 put_string(buf, &self.name)?;
135 }
136 }
137 if version >= 0 {
138 {
139 put_array_len(buf, (self.partitions).len(), flex)?;
140 for it in &self.partitions {
141 it.encode(buf, version)?;
142 }
143 }
144 }
145 if flex {
146 let tagged = WriteTaggedFields::new();
147 tagged.write(buf, &self.unknown_tagged_fields)?;
148 }
149 Ok(())
150 }
151 fn encoded_len(&self, version: i16) -> usize {
152 let flex = version >= 2;
153 let mut n: usize = 0;
154 if version >= 0 {
155 n += if flex {
156 compact_string_len(&self.name)
157 } else {
158 string_len(&self.name)
159 };
160 }
161 if version >= 0 {
162 n += {
163 let prefix = array_len_prefix_len((self.partitions).len(), flex);
164 let body: usize = (self.partitions)
165 .iter()
166 .map(|it| it.encoded_len(version))
167 .sum();
168 prefix + body
169 };
170 }
171 if flex {
172 let known_pairs: Vec<(u32, usize)> = Vec::new();
173 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
174 }
175 n
176 }
177}
178impl Decode<'_> for DeleteRecordsTopicResult {
179 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
180 let flex = version >= 2;
181 let mut out = Self::default();
182 if version >= 0 {
183 out.name = if flex {
184 get_compact_string_owned(buf)?
185 } else {
186 get_string_owned(buf)?
187 };
188 }
189 if version >= 0 {
190 out.partitions = {
191 let n = get_array_len(buf, flex)?;
192 let mut v = Vec::with_capacity(n);
193 for _ in 0..n {
194 v.push(DeleteRecordsPartitionResult::decode(buf, version)?);
195 }
196 v
197 };
198 }
199 if flex {
200 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
201 }
202 Ok(out)
203 }
204}
205#[cfg(test)]
206impl DeleteRecordsTopicResult {
207 #[must_use]
208 pub fn populated(version: i16) -> Self {
209 let mut m = Self::default();
210 if version >= 0 {
211 m.name = "x".to_owned();
212 }
213 if version >= 0 {
214 m.partitions = vec![DeleteRecordsPartitionResult::populated(version)];
215 }
216 m
217 }
218}
219#[derive(Debug, Clone, PartialEq, Eq, Default)]
220pub struct DeleteRecordsPartitionResult {
221 pub partition_index: i32,
222 pub low_watermark: i64,
223 pub error_code: i16,
224 pub unknown_tagged_fields: UnknownTaggedFields,
225}
226impl Encode for DeleteRecordsPartitionResult {
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.low_watermark);
234 }
235 if version >= 0 {
236 put_i16(buf, self.error_code);
237 }
238 if flex {
239 let tagged = WriteTaggedFields::new();
240 tagged.write(buf, &self.unknown_tagged_fields)?;
241 }
242 Ok(())
243 }
244 fn encoded_len(&self, version: i16) -> usize {
245 let flex = version >= 2;
246 let mut n: usize = 0;
247 if version >= 0 {
248 n += 4;
249 }
250 if version >= 0 {
251 n += 8;
252 }
253 if version >= 0 {
254 n += 2;
255 }
256 if flex {
257 let known_pairs: Vec<(u32, usize)> = Vec::new();
258 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
259 }
260 n
261 }
262}
263impl Decode<'_> for DeleteRecordsPartitionResult {
264 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
265 let flex = version >= 2;
266 let mut out = Self::default();
267 if version >= 0 {
268 out.partition_index = get_i32(buf)?;
269 }
270 if version >= 0 {
271 out.low_watermark = get_i64(buf)?;
272 }
273 if version >= 0 {
274 out.error_code = get_i16(buf)?;
275 }
276 if flex {
277 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
278 }
279 Ok(out)
280 }
281}
282#[cfg(test)]
283impl DeleteRecordsPartitionResult {
284 #[must_use]
285 pub fn populated(version: i16) -> Self {
286 let mut m = Self::default();
287 if version >= 0 {
288 m.partition_index = 1i32;
289 }
290 if version >= 0 {
291 m.low_watermark = 1i64;
292 }
293 if version >= 0 {
294 m.error_code = 1i16;
295 }
296 m
297 }
298}
299#[must_use]
302#[allow(unused_comparisons)]
303pub fn default_json(_version: i16) -> ::serde_json::Value {
304 let mut obj = ::serde_json::Map::new();
305 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
306 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
307 ::serde_json::Value::Object(obj)
308}