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