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