Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeProducersResponse.owned.rs

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