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