Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{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 = 61;
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, Default)]
20pub struct DescribeProducersRequest {
21    pub topics: Vec<TopicRequest>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for DescribeProducersRequest {
25    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27            return Err(ProtocolError::UnsupportedVersion {
28                api_key: API_KEY,
29                version,
30            });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 {
34            {
35                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
36                for it in &self.topics {
37                    it.encode(buf, version)?;
38                }
39            }
40        }
41        if flex {
42            let tagged = WriteTaggedFields::new();
43            tagged.write(buf, &self.unknown_tagged_fields);
44        }
45        Ok(())
46    }
47    fn encoded_len(&self, version: i16) -> usize {
48        let flex = is_flexible(version);
49        let mut n: usize = 0;
50        if version >= 0 {
51            n += {
52                let prefix =
53                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
54                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
55                prefix + body
56            };
57        }
58        if flex {
59            let known_pairs: Vec<(u32, usize)> = Vec::new();
60            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
61        }
62        n
63    }
64}
65impl Decode<'_> for DescribeProducersRequest {
66    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68            return Err(ProtocolError::UnsupportedVersion {
69                api_key: API_KEY,
70                version,
71            });
72        }
73        let flex = is_flexible(version);
74        let mut out = Self::default();
75        if version >= 0 {
76            out.topics = {
77                let n = crate::primitives::array::get_array_len(buf, flex)?;
78                let mut v = Vec::with_capacity(n);
79                for _ in 0..n {
80                    v.push(TopicRequest::decode(buf, version)?);
81                }
82                v
83            };
84        }
85        if flex {
86            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
87        }
88        Ok(out)
89    }
90}
91#[cfg(test)]
92impl DescribeProducersRequest {
93    #[must_use]
94    pub fn populated(version: i16) -> Self {
95        let mut m = Self::default();
96        if version >= 0 {
97            m.topics = vec![TopicRequest::populated(version)];
98        }
99        m
100    }
101}
102#[derive(Debug, Clone, PartialEq, Eq, Default)]
103pub struct TopicRequest {
104    pub name: String,
105    pub partition_indexes: Vec<i32>,
106    pub unknown_tagged_fields: UnknownTaggedFields,
107}
108impl Encode for TopicRequest {
109    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
110        let flex = version >= 0;
111        if version >= 0 {
112            if flex {
113                put_compact_string(buf, &self.name);
114            } else {
115                put_string(buf, &self.name);
116            }
117        }
118        if version >= 0 {
119            {
120                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
121                for it in &self.partition_indexes {
122                    put_i32(buf, *it);
123                }
124            }
125        }
126        if flex {
127            let tagged = WriteTaggedFields::new();
128            tagged.write(buf, &self.unknown_tagged_fields);
129        }
130        Ok(())
131    }
132    fn encoded_len(&self, version: i16) -> usize {
133        let flex = version >= 0;
134        let mut n: usize = 0;
135        if version >= 0 {
136            n += if flex {
137                compact_string_len(&self.name)
138            } else {
139                string_len(&self.name)
140            };
141        }
142        if version >= 0 {
143            n += {
144                let prefix = crate::primitives::array::array_len_prefix_len(
145                    (self.partition_indexes).len(),
146                    flex,
147                );
148                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
149                prefix + body
150            };
151        }
152        if flex {
153            let known_pairs: Vec<(u32, usize)> = Vec::new();
154            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
155        }
156        n
157    }
158}
159impl Decode<'_> for TopicRequest {
160    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
161        let flex = version >= 0;
162        let mut out = Self::default();
163        if version >= 0 {
164            out.name = if flex {
165                get_compact_string_owned(buf)?
166            } else {
167                get_string_owned(buf)?
168            };
169        }
170        if version >= 0 {
171            out.partition_indexes = {
172                let n = crate::primitives::array::get_array_len(buf, flex)?;
173                let mut v = Vec::with_capacity(n);
174                for _ in 0..n {
175                    v.push(get_i32(buf)?);
176                }
177                v
178            };
179        }
180        if flex {
181            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
182        }
183        Ok(out)
184    }
185}
186#[cfg(test)]
187impl TopicRequest {
188    #[must_use]
189    pub fn populated(version: i16) -> Self {
190        let mut m = Self::default();
191        if version >= 0 {
192            m.name = "x".to_string();
193        }
194        if version >= 0 {
195            m.partition_indexes = vec![1i32];
196        }
197        m
198    }
199}
200/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
201/// Only includes fields valid for the given version.
202#[must_use]
203#[allow(unused_comparisons)]
204pub fn default_json(version: i16) -> ::serde_json::Value {
205    let mut obj = ::serde_json::Map::new();
206    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
207    ::serde_json::Value::Object(obj)
208}
209impl crate::ProtocolRequest for DescribeProducersRequest {
210    const API_KEY: i16 = API_KEY;
211    const MIN_VERSION: i16 = MIN_VERSION;
212    const MAX_VERSION: i16 = MAX_VERSION;
213    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
214    type Response = super::describe_producers_response::DescribeProducersResponse;
215}