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