krabka_protocol/opt/rustwide/workdir/generated/
DescribeProducersResponse.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_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13 nullable_string_len, put_compact_nullable_string, put_compact_string,
14 put_nullable_string, put_string, string_len,
15 },
16 },
17 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 61;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 0;
22pub const FLEXIBLE_MIN: i16 = 0;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct DescribeProducersResponse {
30 pub throttle_time_ms: i32,
31 pub topics: Vec<TopicResponse>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for DescribeProducersResponse {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 put_i32(buf, self.throttle_time_ms);
45 }
46 if version >= 0 {
47 {
48 put_array_len(buf, (self.topics).len(), flex)?;
49 for it in &self.topics {
50 it.encode(buf, version)?;
51 }
52 }
53 }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields)?;
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 if version >= 0 {
64 n += 4;
65 }
66 if version >= 0 {
67 n += {
68 let prefix = array_len_prefix_len((self.topics).len(), flex);
69 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
70 prefix + body
71 };
72 }
73 if flex {
74 let known_pairs: Vec<(u32, usize)> = Vec::new();
75 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76 }
77 n
78 }
79}
80impl Decode<'_> for DescribeProducersResponse {
81 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83 return Err(ProtocolError::UnsupportedVersion {
84 api_key: API_KEY,
85 version,
86 });
87 }
88 let flex = is_flexible(version);
89 let mut out = Self::default();
90 if version >= 0 {
91 out.throttle_time_ms = get_i32(buf)?;
92 }
93 if version >= 0 {
94 out.topics = {
95 let n = get_array_len(buf, flex)?;
96 let mut v = Vec::with_capacity(n);
97 for _ in 0..n {
98 v.push(TopicResponse::decode(buf, version)?);
99 }
100 v
101 };
102 }
103 if flex {
104 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
105 }
106 Ok(out)
107 }
108}
109#[cfg(test)]
110impl DescribeProducersResponse {
111 #[must_use]
112 pub fn populated(version: i16) -> Self {
113 let mut m = Self::default();
114 if version >= 0 {
115 m.throttle_time_ms = 1i32;
116 }
117 if version >= 0 {
118 m.topics = vec![TopicResponse::populated(version)];
119 }
120 m
121 }
122}
123#[derive(Debug, Clone, PartialEq, Eq, Default)]
124pub struct TopicResponse {
125 pub name: String,
126 pub partitions: Vec<PartitionResponse>,
127 pub unknown_tagged_fields: UnknownTaggedFields,
128}
129impl Encode for TopicResponse {
130 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
131 let flex = version >= 0;
132 if version >= 0 {
133 if flex {
134 put_compact_string(buf, &self.name)?;
135 } else {
136 put_string(buf, &self.name)?;
137 }
138 }
139 if version >= 0 {
140 {
141 put_array_len(buf, (self.partitions).len(), flex)?;
142 for it in &self.partitions {
143 it.encode(buf, version)?;
144 }
145 }
146 }
147 if flex {
148 let tagged = WriteTaggedFields::new();
149 tagged.write(buf, &self.unknown_tagged_fields)?;
150 }
151 Ok(())
152 }
153 fn encoded_len(&self, version: i16) -> usize {
154 let flex = version >= 0;
155 let mut n: usize = 0;
156 if version >= 0 {
157 n += if flex {
158 compact_string_len(&self.name)
159 } else {
160 string_len(&self.name)
161 };
162 }
163 if version >= 0 {
164 n += {
165 let prefix = array_len_prefix_len((self.partitions).len(), flex);
166 let body: usize = (self.partitions)
167 .iter()
168 .map(|it| it.encoded_len(version))
169 .sum();
170 prefix + body
171 };
172 }
173 if flex {
174 let known_pairs: Vec<(u32, usize)> = Vec::new();
175 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
176 }
177 n
178 }
179}
180impl Decode<'_> for TopicResponse {
181 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
182 let flex = version >= 0;
183 let mut out = Self::default();
184 if version >= 0 {
185 out.name = if flex {
186 get_compact_string_owned(buf)?
187 } else {
188 get_string_owned(buf)?
189 };
190 }
191 if version >= 0 {
192 out.partitions = {
193 let n = get_array_len(buf, flex)?;
194 let mut v = Vec::with_capacity(n);
195 for _ in 0..n {
196 v.push(PartitionResponse::decode(buf, version)?);
197 }
198 v
199 };
200 }
201 if flex {
202 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203 }
204 Ok(out)
205 }
206}
207#[cfg(test)]
208impl TopicResponse {
209 #[must_use]
210 pub fn populated(version: i16) -> Self {
211 let mut m = Self::default();
212 if version >= 0 {
213 m.name = "x".to_owned();
214 }
215 if version >= 0 {
216 m.partitions = vec![PartitionResponse::populated(version)];
217 }
218 m
219 }
220}
221#[derive(Debug, Clone, PartialEq, Eq, Default)]
222pub struct PartitionResponse {
223 pub partition_index: i32,
224 pub error_code: i16,
225 pub error_message: Option<String>,
226 pub active_producers: Vec<ProducerState>,
227 pub unknown_tagged_fields: UnknownTaggedFields,
228}
229impl Encode for PartitionResponse {
230 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
231 let flex = version >= 0;
232 if version >= 0 {
233 put_i32(buf, self.partition_index);
234 }
235 if version >= 0 {
236 put_i16(buf, self.error_code);
237 }
238 if version >= 0 {
239 if flex {
240 put_compact_nullable_string(buf, self.error_message.as_deref())?;
241 } else {
242 put_nullable_string(buf, self.error_message.as_deref())?;
243 }
244 }
245 if version >= 0 {
246 {
247 put_array_len(buf, (self.active_producers).len(), flex)?;
248 for it in &self.active_producers {
249 it.encode(buf, version)?;
250 }
251 }
252 }
253 if flex {
254 let tagged = WriteTaggedFields::new();
255 tagged.write(buf, &self.unknown_tagged_fields)?;
256 }
257 Ok(())
258 }
259 fn encoded_len(&self, version: i16) -> usize {
260 let flex = version >= 0;
261 let mut n: usize = 0;
262 if version >= 0 {
263 n += 4;
264 }
265 if version >= 0 {
266 n += 2;
267 }
268 if version >= 0 {
269 n += if flex {
270 compact_nullable_string_len(self.error_message.as_deref())
271 } else {
272 nullable_string_len(self.error_message.as_deref())
273 };
274 }
275 if version >= 0 {
276 n += {
277 let prefix = array_len_prefix_len((self.active_producers).len(), flex);
278 let body: usize = (self.active_producers)
279 .iter()
280 .map(|it| it.encoded_len(version))
281 .sum();
282 prefix + body
283 };
284 }
285 if flex {
286 let known_pairs: Vec<(u32, usize)> = Vec::new();
287 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
288 }
289 n
290 }
291}
292impl Decode<'_> for PartitionResponse {
293 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
294 let flex = version >= 0;
295 let mut out = Self::default();
296 if version >= 0 {
297 out.partition_index = get_i32(buf)?;
298 }
299 if version >= 0 {
300 out.error_code = get_i16(buf)?;
301 }
302 if version >= 0 {
303 out.error_message = if flex {
304 get_compact_nullable_string_owned(buf)?
305 } else {
306 get_nullable_string_owned(buf)?
307 };
308 }
309 if version >= 0 {
310 out.active_producers = {
311 let n = get_array_len(buf, flex)?;
312 let mut v = Vec::with_capacity(n);
313 for _ in 0..n {
314 v.push(ProducerState::decode(buf, version)?);
315 }
316 v
317 };
318 }
319 if flex {
320 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
321 }
322 Ok(out)
323 }
324}
325#[cfg(test)]
326impl PartitionResponse {
327 #[must_use]
328 pub fn populated(version: i16) -> Self {
329 let mut m = Self::default();
330 if version >= 0 {
331 m.partition_index = 1i32;
332 }
333 if version >= 0 {
334 m.error_code = 1i16;
335 }
336 if version >= 0 {
337 m.error_message = Some("x".to_owned());
338 }
339 if version >= 0 {
340 m.active_producers = vec![ProducerState::populated(version)];
341 }
342 m
343 }
344}
345#[derive(Debug, Clone, PartialEq, Eq)]
346pub struct ProducerState {
347 pub producer_id: i64,
348 pub producer_epoch: i32,
349 pub last_sequence: i32,
350 pub last_timestamp: i64,
351 pub coordinator_epoch: i32,
352 pub current_txn_start_offset: i64,
353 pub unknown_tagged_fields: UnknownTaggedFields,
354}
355impl Default for ProducerState {
356 fn default() -> Self {
357 Self {
358 producer_id: 0i64,
359 producer_epoch: 0i32,
360 last_sequence: -1i32,
361 last_timestamp: -1i64,
362 coordinator_epoch: 0i32,
363 current_txn_start_offset: -1i64,
364 unknown_tagged_fields: UnknownTaggedFields::default(),
365 }
366 }
367}
368impl Encode for ProducerState {
369 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
370 let flex = version >= 0;
371 if version >= 0 {
372 put_i64(buf, self.producer_id);
373 }
374 if version >= 0 {
375 put_i32(buf, self.producer_epoch);
376 }
377 if version >= 0 {
378 put_i32(buf, self.last_sequence);
379 }
380 if version >= 0 {
381 put_i64(buf, self.last_timestamp);
382 }
383 if version >= 0 {
384 put_i32(buf, self.coordinator_epoch);
385 }
386 if version >= 0 {
387 put_i64(buf, self.current_txn_start_offset);
388 }
389 if flex {
390 let tagged = WriteTaggedFields::new();
391 tagged.write(buf, &self.unknown_tagged_fields)?;
392 }
393 Ok(())
394 }
395 fn encoded_len(&self, version: i16) -> usize {
396 let flex = version >= 0;
397 let mut n: usize = 0;
398 if version >= 0 {
399 n += 8;
400 }
401 if version >= 0 {
402 n += 4;
403 }
404 if version >= 0 {
405 n += 4;
406 }
407 if version >= 0 {
408 n += 8;
409 }
410 if version >= 0 {
411 n += 4;
412 }
413 if version >= 0 {
414 n += 8;
415 }
416 if flex {
417 let known_pairs: Vec<(u32, usize)> = Vec::new();
418 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
419 }
420 n
421 }
422}
423impl Decode<'_> for ProducerState {
424 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
425 let flex = version >= 0;
426 let mut out = Self::default();
427 if version >= 0 {
428 out.producer_id = get_i64(buf)?;
429 }
430 if version >= 0 {
431 out.producer_epoch = get_i32(buf)?;
432 }
433 if version >= 0 {
434 out.last_sequence = get_i32(buf)?;
435 }
436 if version >= 0 {
437 out.last_timestamp = get_i64(buf)?;
438 }
439 if version >= 0 {
440 out.coordinator_epoch = get_i32(buf)?;
441 }
442 if version >= 0 {
443 out.current_txn_start_offset = get_i64(buf)?;
444 }
445 if flex {
446 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
447 }
448 Ok(out)
449 }
450}
451#[cfg(test)]
452impl ProducerState {
453 #[must_use]
454 pub fn populated(version: i16) -> Self {
455 let mut m = Self::default();
456 if version >= 0 {
457 m.producer_id = 1i64;
458 }
459 if version >= 0 {
460 m.producer_epoch = 1i32;
461 }
462 if version >= 0 {
463 m.last_sequence = 1i32;
464 }
465 if version >= 0 {
466 m.last_timestamp = 1i64;
467 }
468 if version >= 0 {
469 m.coordinator_epoch = 1i32;
470 }
471 if version >= 0 {
472 m.current_txn_start_offset = 1i64;
473 }
474 m
475 }
476}
477#[must_use]
480#[allow(unused_comparisons)]
481pub fn default_json(_version: i16) -> ::serde_json::Value {
482 let mut obj = ::serde_json::Map::new();
483 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
484 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
485 ::serde_json::Value::Object(obj)
486}