crabka_protocol/opt/rustwide/workdir/generated/
DeleteRecordsResponse.owned.rs1use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, 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 DeleteRecordsResponse {
21 pub throttle_time_ms: i32,
22 pub topics: Vec<DeleteRecordsTopicResult>,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for DeleteRecordsResponse {
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 put_i32(buf, self.throttle_time_ms);
36 }
37 if version >= 0 {
38 {
39 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
40 for it in &self.topics {
41 it.encode(buf, version)?;
42 }
43 }
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 += 4;
56 }
57 if version >= 0 {
58 n += {
59 let prefix =
60 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
61 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
62 prefix + body
63 };
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 DeleteRecordsResponse {
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.throttle_time_ms = get_i32(buf)?;
84 }
85 if version >= 0 {
86 out.topics = {
87 let n = crate::primitives::array::get_array_len(buf, flex)?;
88 let mut v = Vec::with_capacity(n);
89 for _ in 0..n {
90 v.push(DeleteRecordsTopicResult::decode(buf, version)?);
91 }
92 v
93 };
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 DeleteRecordsResponse {
103 #[must_use]
104 pub fn populated(version: i16) -> Self {
105 let mut m = Self::default();
106 if version >= 0 {
107 m.throttle_time_ms = 1i32;
108 }
109 if version >= 0 {
110 m.topics = vec![DeleteRecordsTopicResult::populated(version)];
111 }
112 m
113 }
114}
115#[derive(Debug, Clone, PartialEq, Eq, Default)]
116pub struct DeleteRecordsTopicResult {
117 pub name: String,
118 pub partitions: Vec<DeleteRecordsPartitionResult>,
119 pub unknown_tagged_fields: UnknownTaggedFields,
120}
121impl Encode for DeleteRecordsTopicResult {
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 DeleteRecordsTopicResult {
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(DeleteRecordsPartitionResult::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 DeleteRecordsTopicResult {
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![DeleteRecordsPartitionResult::populated(version)];
210 }
211 m
212 }
213}
214#[derive(Debug, Clone, PartialEq, Eq, Default)]
215pub struct DeleteRecordsPartitionResult {
216 pub partition_index: i32,
217 pub low_watermark: i64,
218 pub error_code: i16,
219 pub unknown_tagged_fields: UnknownTaggedFields,
220}
221impl Encode for DeleteRecordsPartitionResult {
222 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
223 let flex = version >= 2;
224 if version >= 0 {
225 put_i32(buf, self.partition_index);
226 }
227 if version >= 0 {
228 put_i64(buf, self.low_watermark);
229 }
230 if version >= 0 {
231 put_i16(buf, self.error_code);
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 version >= 0 {
249 n += 2;
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 DeleteRecordsPartitionResult {
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.low_watermark = get_i64(buf)?;
267 }
268 if version >= 0 {
269 out.error_code = get_i16(buf)?;
270 }
271 if flex {
272 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
273 }
274 Ok(out)
275 }
276}
277#[cfg(test)]
278impl DeleteRecordsPartitionResult {
279 #[must_use]
280 pub fn populated(version: i16) -> Self {
281 let mut m = Self::default();
282 if version >= 0 {
283 m.partition_index = 1i32;
284 }
285 if version >= 0 {
286 m.low_watermark = 1i64;
287 }
288 if version >= 0 {
289 m.error_code = 1i16;
290 }
291 m
292 }
293}
294#[must_use]
297#[allow(unused_comparisons)]
298pub fn default_json(version: i16) -> ::serde_json::Value {
299 let mut obj = ::serde_json::Map::new();
300 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
301 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
302 ::serde_json::Value::Object(obj)
303}