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,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 61;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeProducersResponse {
25    pub throttle_time_ms: i32,
26    pub topics: Vec<TopicResponse>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
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 { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        if version >= 0 { n += 4; }
48        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56
57impl<'de> Decode<'de> for DescribeProducersResponse {
58    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61        }
62        let flex = is_flexible(version);
63        let mut out = Self::default();
64        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
65        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicResponse::decode(buf, version)?); } v }; }
66        if flex {
67            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68                Ok(false)
69            })?;
70        }
71        Ok(out)
72    }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Default)]
76pub struct TopicResponse {
77    pub name: String,
78    pub partitions: Vec<PartitionResponse>,
79    pub unknown_tagged_fields: UnknownTaggedFields,
80}
81
82impl Encode for TopicResponse {
83    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
84        let flex = version >= 0;
85        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
86        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
87        if flex {
88            let tagged = WriteTaggedFields::new();
89            tagged.write(buf, &self.unknown_tagged_fields);
90        }
91        Ok(())
92    }
93    fn encoded_len(&self, version: i16) -> usize {
94        let flex = version >= 0;
95        let mut n: usize = 0;
96        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
97        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
98        if flex {
99            let known_pairs: Vec<(u32, usize)> = Vec::new();
100            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
101        }
102        n
103    }
104}
105
106impl<'de> Decode<'de> for TopicResponse {
107    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
108        let flex = version >= 0;
109        let mut out = Self::default();
110        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
111        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionResponse::decode(buf, version)?); } v }; }
112        if flex {
113            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
114                Ok(false)
115            })?;
116        }
117        Ok(out)
118    }
119}
120
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct PartitionResponse {
123    pub partition_index: i32,
124    pub error_code: i16,
125    pub error_message: Option<String>,
126    pub active_producers: Vec<ProducerState>,
127    pub unknown_tagged_fields: UnknownTaggedFields,
128}
129
130impl Encode for PartitionResponse {
131    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132        let flex = version >= 0;
133        if version >= 0 { put_i32(buf, self.partition_index) }
134        if version >= 0 { put_i16(buf, self.error_code) }
135        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
136        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.active_producers).len(), flex); for it in &self.active_producers { it.encode(buf, version)?; } } }
137        if flex {
138            let tagged = WriteTaggedFields::new();
139            tagged.write(buf, &self.unknown_tagged_fields);
140        }
141        Ok(())
142    }
143    fn encoded_len(&self, version: i16) -> usize {
144        let flex = version >= 0;
145        let mut n: usize = 0;
146        if version >= 0 { n += 4; }
147        if version >= 0 { n += 2; }
148        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
149        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.active_producers).len(), flex); let body: usize = (self.active_producers).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
150        if flex {
151            let known_pairs: Vec<(u32, usize)> = Vec::new();
152            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
153        }
154        n
155    }
156}
157
158impl<'de> Decode<'de> for PartitionResponse {
159    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
160        let flex = version >= 0;
161        let mut out = Self::default();
162        if version >= 0 { out.partition_index = get_i32(buf)?; }
163        if version >= 0 { out.error_code = get_i16(buf)?; }
164        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
165        if version >= 0 { out.active_producers = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ProducerState::decode(buf, version)?); } v }; }
166        if flex {
167            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
168                Ok(false)
169            })?;
170        }
171        Ok(out)
172    }
173}
174
175#[derive(Debug, Clone, PartialEq, Eq)]
176pub struct ProducerState {
177    pub producer_id: i64,
178    pub producer_epoch: i32,
179    pub last_sequence: i32,
180    pub last_timestamp: i64,
181    pub coordinator_epoch: i32,
182    pub current_txn_start_offset: i64,
183    pub unknown_tagged_fields: UnknownTaggedFields,
184}
185
186impl Default for ProducerState {
187    fn default() -> Self {
188        Self {
189            producer_id: 0i64,
190            producer_epoch: 0i32,
191            last_sequence: -1i32,
192            last_timestamp: -1i64,
193            coordinator_epoch: 0i32,
194            current_txn_start_offset: -1i64,
195            unknown_tagged_fields: Default::default(),
196        }
197    }
198}
199
200impl Encode for ProducerState {
201    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
202        let flex = version >= 0;
203        if version >= 0 { put_i64(buf, self.producer_id) }
204        if version >= 0 { put_i32(buf, self.producer_epoch) }
205        if version >= 0 { put_i32(buf, self.last_sequence) }
206        if version >= 0 { put_i64(buf, self.last_timestamp) }
207        if version >= 0 { put_i32(buf, self.coordinator_epoch) }
208        if version >= 0 { put_i64(buf, self.current_txn_start_offset) }
209        if flex {
210            let tagged = WriteTaggedFields::new();
211            tagged.write(buf, &self.unknown_tagged_fields);
212        }
213        Ok(())
214    }
215    fn encoded_len(&self, version: i16) -> usize {
216        let flex = version >= 0;
217        let mut n: usize = 0;
218        if version >= 0 { n += 8; }
219        if version >= 0 { n += 4; }
220        if version >= 0 { n += 4; }
221        if version >= 0 { n += 8; }
222        if version >= 0 { n += 4; }
223        if version >= 0 { n += 8; }
224        if flex {
225            let known_pairs: Vec<(u32, usize)> = Vec::new();
226            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
227        }
228        n
229    }
230}
231
232impl<'de> Decode<'de> for ProducerState {
233    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
234        let flex = version >= 0;
235        let mut out = Self::default();
236        if version >= 0 { out.producer_id = get_i64(buf)?; }
237        if version >= 0 { out.producer_epoch = get_i32(buf)?; }
238        if version >= 0 { out.last_sequence = get_i32(buf)?; }
239        if version >= 0 { out.last_timestamp = get_i64(buf)?; }
240        if version >= 0 { out.coordinator_epoch = get_i32(buf)?; }
241        if version >= 0 { out.current_txn_start_offset = get_i64(buf)?; }
242        if flex {
243            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
244                Ok(false)
245            })?;
246        }
247        Ok(out)
248    }
249}
250
251/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
252/// Only includes fields valid for the given version.
253#[must_use]
254#[allow(unused_comparisons)]
255pub fn default_json(version: i16) -> ::serde_json::Value {
256    let mut obj = ::serde_json::Map::new();
257    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
258    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
259    ::serde_json::Value::Object(obj)
260}