Skip to main content

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