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