Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i8, get_i32, put_i32};
4use crate::primitives::string_bytes::{
5    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6    string_len,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const API_KEY: i16 = 75;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct DescribeTopicPartitionsRequest {
21    pub topics: Vec<TopicRequest>,
22    pub response_partition_limit: i32,
23    pub cursor: Option<Cursor>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for DescribeTopicPartitionsRequest {
27    fn default() -> Self {
28        Self {
29            topics: Vec::new(),
30            response_partition_limit: 2_000i32,
31            cursor: None,
32            unknown_tagged_fields: Default::default(),
33        }
34    }
35}
36impl Encode for DescribeTopicPartitionsRequest {
37    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39            return Err(ProtocolError::UnsupportedVersion {
40                api_key: API_KEY,
41                version,
42            });
43        }
44        let flex = is_flexible(version);
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 version >= 0 {
54            put_i32(buf, self.response_partition_limit);
55        }
56        if version >= 0 {
57            match &self.cursor {
58                None => {
59                    buf.put_i8(-1);
60                }
61                Some(v) => {
62                    buf.put_i8(1);
63                    v.encode(buf, version)?;
64                }
65            }
66        }
67        if flex {
68            let tagged = WriteTaggedFields::new();
69            tagged.write(buf, &self.unknown_tagged_fields);
70        }
71        Ok(())
72    }
73    fn encoded_len(&self, version: i16) -> usize {
74        let flex = is_flexible(version);
75        let mut n: usize = 0;
76        if version >= 0 {
77            n += {
78                let prefix =
79                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
80                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
81                prefix + body
82            };
83        }
84        if version >= 0 {
85            n += 4;
86        }
87        if version >= 0 {
88            n += 1 + self.cursor.as_ref().map_or(0, |v| v.encoded_len(version));
89        }
90        if flex {
91            let known_pairs: Vec<(u32, usize)> = Vec::new();
92            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
93        }
94        n
95    }
96}
97impl Decode<'_> for DescribeTopicPartitionsRequest {
98    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
99        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
100            return Err(ProtocolError::UnsupportedVersion {
101                api_key: API_KEY,
102                version,
103            });
104        }
105        let flex = is_flexible(version);
106        let mut out = Self::default();
107        if version >= 0 {
108            out.topics = {
109                let n = crate::primitives::array::get_array_len(buf, flex)?;
110                let mut v = Vec::with_capacity(n);
111                for _ in 0..n {
112                    v.push(TopicRequest::decode(buf, version)?);
113                }
114                v
115            };
116        }
117        if version >= 0 {
118            out.response_partition_limit = get_i32(buf)?;
119        }
120        if version >= 0 {
121            out.cursor = if get_i8(buf)? < 0 {
122                None
123            } else {
124                Some(Cursor::decode(buf, version)?)
125            };
126        }
127        if flex {
128            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
129        }
130        Ok(out)
131    }
132}
133#[cfg(test)]
134impl DescribeTopicPartitionsRequest {
135    #[must_use]
136    pub fn populated(version: i16) -> Self {
137        let mut m = Self::default();
138        if version >= 0 {
139            m.topics = vec![TopicRequest::populated(version)];
140        }
141        if version >= 0 {
142            m.response_partition_limit = 1i32;
143        }
144        if version >= 0 {
145            m.cursor = Some(Cursor::populated(version));
146        }
147        m
148    }
149}
150#[derive(Debug, Clone, PartialEq, Eq, Default)]
151pub struct TopicRequest {
152    pub name: String,
153    pub unknown_tagged_fields: UnknownTaggedFields,
154}
155impl Encode for TopicRequest {
156    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
157        let flex = version >= 0;
158        if version >= 0 {
159            if flex {
160                put_compact_string(buf, &self.name);
161            } else {
162                put_string(buf, &self.name);
163            }
164        }
165        if flex {
166            let tagged = WriteTaggedFields::new();
167            tagged.write(buf, &self.unknown_tagged_fields);
168        }
169        Ok(())
170    }
171    fn encoded_len(&self, version: i16) -> usize {
172        let flex = version >= 0;
173        let mut n: usize = 0;
174        if version >= 0 {
175            n += if flex {
176                compact_string_len(&self.name)
177            } else {
178                string_len(&self.name)
179            };
180        }
181        if flex {
182            let known_pairs: Vec<(u32, usize)> = Vec::new();
183            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
184        }
185        n
186    }
187}
188impl Decode<'_> for TopicRequest {
189    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
190        let flex = version >= 0;
191        let mut out = Self::default();
192        if version >= 0 {
193            out.name = if flex {
194                get_compact_string_owned(buf)?
195            } else {
196                get_string_owned(buf)?
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 TopicRequest {
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        m
214    }
215}
216#[derive(Debug, Clone, PartialEq, Eq, Default)]
217pub struct Cursor {
218    pub topic_name: String,
219    pub partition_index: i32,
220    pub unknown_tagged_fields: UnknownTaggedFields,
221}
222impl Encode for Cursor {
223    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
224        let flex = version >= 0;
225        if version >= 0 {
226            if flex {
227                put_compact_string(buf, &self.topic_name);
228            } else {
229                put_string(buf, &self.topic_name);
230            }
231        }
232        if version >= 0 {
233            put_i32(buf, self.partition_index);
234        }
235        if flex {
236            let tagged = WriteTaggedFields::new();
237            tagged.write(buf, &self.unknown_tagged_fields);
238        }
239        Ok(())
240    }
241    fn encoded_len(&self, version: i16) -> usize {
242        let flex = version >= 0;
243        let mut n: usize = 0;
244        if version >= 0 {
245            n += if flex {
246                compact_string_len(&self.topic_name)
247            } else {
248                string_len(&self.topic_name)
249            };
250        }
251        if version >= 0 {
252            n += 4;
253        }
254        if flex {
255            let known_pairs: Vec<(u32, usize)> = Vec::new();
256            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
257        }
258        n
259    }
260}
261impl Decode<'_> for Cursor {
262    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
263        let flex = version >= 0;
264        let mut out = Self::default();
265        if version >= 0 {
266            out.topic_name = if flex {
267                get_compact_string_owned(buf)?
268            } else {
269                get_string_owned(buf)?
270            };
271        }
272        if version >= 0 {
273            out.partition_index = get_i32(buf)?;
274        }
275        if flex {
276            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
277        }
278        Ok(out)
279    }
280}
281#[cfg(test)]
282impl Cursor {
283    #[must_use]
284    pub fn populated(version: i16) -> Self {
285        let mut m = Self::default();
286        if version >= 0 {
287            m.topic_name = "x".to_string();
288        }
289        if version >= 0 {
290            m.partition_index = 1i32;
291        }
292        m
293    }
294}
295/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
296/// Only includes fields valid for the given version.
297#[must_use]
298#[allow(unused_comparisons)]
299pub fn default_json(version: i16) -> ::serde_json::Value {
300    let mut obj = ::serde_json::Map::new();
301    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
302    obj.insert(
303        "responsePartitionLimit".to_string(),
304        ::serde_json::json!(2000),
305    );
306    obj.insert("cursor".to_string(), ::serde_json::Value::Null);
307    ::serde_json::Value::Object(obj)
308}
309impl crate::ProtocolRequest for DescribeTopicPartitionsRequest {
310    const API_KEY: i16 = API_KEY;
311    const MIN_VERSION: i16 = MIN_VERSION;
312    const MAX_VERSION: i16 = MAX_VERSION;
313    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
314    type Response = super::describe_topic_partitions_response::DescribeTopicPartitionsResponse;
315}