Skip to main content

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

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