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