krabka_protocol/opt/rustwide/workdir/generated/
DescribeShareGroupOffsetsRequest.owned.rs1use 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 = 90;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 1;
19pub const LATEST_STABLE_VERSION: i16 = 1;
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 DescribeShareGroupOffsetsRequest {
28 pub groups: Vec<DescribeShareGroupOffsetsRequestGroup>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for DescribeShareGroupOffsetsRequest {
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.groups).len(), flex);
43 for it in &self.groups {
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.groups).len(), flex);
61 let body: usize = (self.groups).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 DescribeShareGroupOffsetsRequest {
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.groups = {
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(DescribeShareGroupOffsetsRequestGroup::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 DescribeShareGroupOffsetsRequest {
100 #[must_use]
101 pub fn populated(version: i16) -> Self {
102 let mut m = Self::default();
103 if version >= 0 {
104 m.groups = vec![DescribeShareGroupOffsetsRequestGroup::populated(version)];
105 }
106 m
107 }
108}
109#[derive(Debug, Clone, PartialEq, Eq)]
110pub struct DescribeShareGroupOffsetsRequestGroup {
111 pub group_id: String,
112 pub topics: Option<Vec<DescribeShareGroupOffsetsRequestTopic>>,
113 pub unknown_tagged_fields: UnknownTaggedFields,
114}
115impl Default for DescribeShareGroupOffsetsRequestGroup {
116 fn default() -> Self {
117 Self {
118 group_id: String::new(),
119 topics: Some(Vec::new()),
120 unknown_tagged_fields: UnknownTaggedFields::default(),
121 }
122 }
123}
124impl Encode for DescribeShareGroupOffsetsRequestGroup {
125 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
126 let flex = version >= 0;
127 if version >= 0 {
128 if flex {
129 let () = put_compact_string(buf, &self.group_id);
130 } else {
131 let () = put_string(buf, &self.group_id);
132 }
133 }
134 if version >= 0 {
135 {
136 let len = (self.topics).as_ref().map(Vec::len);
137 crate::primitives::array::put_nullable_array_len(buf, len, flex);
138 if let Some(v) = &self.topics {
139 for it in v {
140 it.encode(buf, version)?;
141 }
142 }
143 };
144 }
145 if flex {
146 let tagged = WriteTaggedFields::new();
147 tagged.write(buf, &self.unknown_tagged_fields);
148 }
149 Ok(())
150 }
151 fn encoded_len(&self, version: i16) -> usize {
152 let flex = version >= 0;
153 let mut n: usize = 0;
154 if version >= 0 {
155 n += if flex {
156 compact_string_len(&self.group_id)
157 } else {
158 string_len(&self.group_id)
159 };
160 }
161 if version >= 0 {
162 n += {
163 let opt: Option<&Vec<_>> = (self.topics).as_ref();
164 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
165 opt.map(std::vec::Vec::len),
166 flex,
167 );
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 = crate::primitives::array::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_string();
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 let () = put_compact_string(buf, &self.topic_name);
240 } else {
241 let () = put_string(buf, &self.topic_name);
242 }
243 }
244 if version >= 0 {
245 {
246 crate::primitives::array::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 =
271 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
272 let body: usize = (self.partitions).iter().map(|_| 4).sum();
273 prefix + body
274 };
275 }
276 if flex {
277 let known_pairs: Vec<(u32, usize)> = Vec::new();
278 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
279 }
280 n
281 }
282}
283impl Decode<'_> for DescribeShareGroupOffsetsRequestTopic {
284 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
285 let flex = version >= 0;
286 let mut out = Self::default();
287 if version >= 0 {
288 out.topic_name = if flex {
289 get_compact_string_owned(buf)?
290 } else {
291 get_string_owned(buf)?
292 };
293 }
294 if version >= 0 {
295 out.partitions = {
296 let n = crate::primitives::array::get_array_len(buf, flex)?;
297 let mut v = Vec::with_capacity(n);
298 for _ in 0..n {
299 v.push(get_i32(buf)?);
300 }
301 v
302 };
303 }
304 if flex {
305 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
306 }
307 Ok(out)
308 }
309}
310#[cfg(test)]
311impl DescribeShareGroupOffsetsRequestTopic {
312 #[must_use]
313 pub fn populated(version: i16) -> Self {
314 let mut m = Self::default();
315 if version >= 0 {
316 m.topic_name = "x".to_string();
317 }
318 if version >= 0 {
319 m.partitions = vec![1i32];
320 }
321 m
322 }
323}
324#[must_use]
327#[allow(unused_comparisons)]
328pub fn default_json(_version: i16) -> ::serde_json::Value {
329 let mut obj = ::serde_json::Map::new();
330 obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
331 ::serde_json::Value::Object(obj)
332}
333impl crate::ProtocolRequest for DescribeShareGroupOffsetsRequest {
334 const API_KEY: i16 = API_KEY;
335 const MIN_VERSION: i16 = MIN_VERSION;
336 const MAX_VERSION: i16 = MAX_VERSION;
337 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
338 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
339 type Response = super::describe_share_group_offsets_response::DescribeShareGroupOffsetsResponse;
340}