Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{BufMut, Bytes};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
9};
10use crate::primitives::string_bytes::{put_bytes, put_compact_bytes};
11use crate::primitives::string_bytes_borrowed::{get_bytes_borrowed, get_compact_bytes_borrowed};
12use crate::primitives::string_bytes_borrowed::{
13    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
14    get_nullable_string_borrowed, get_string_borrowed,
15};
16use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
17use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
18
19pub const API_KEY: i16 = 15;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 6;
22pub const FLEXIBLE_MIN: i16 = 5;
23
24#[inline]
25fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct DescribeGroupsResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub groups: Vec<DescribedGroup<'a>>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl DescribeGroupsResponse<'_> {
36    pub fn to_owned(&self) -> crate::owned::describe_groups_response::DescribeGroupsResponse {
37        crate::owned::describe_groups_response::DescribeGroupsResponse {
38            throttle_time_ms: (self.throttle_time_ms),
39            groups: (self.groups).iter().map(DescribedGroup::to_owned).collect(),
40            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41        }
42    }
43}
44impl Encode for DescribeGroupsResponse<'_> {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion {
48                api_key: API_KEY,
49                version,
50            });
51        }
52        let flex = is_flexible(version);
53        if version >= 1 {
54            put_i32(buf, self.throttle_time_ms);
55        }
56        if version >= 0 {
57            {
58                crate::primitives::array::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 >= 1 {
74            n += 4;
75        }
76        if version >= 0 {
77            n += {
78                let prefix =
79                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
80                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
81                prefix + body
82            };
83        }
84        if flex {
85            let known_pairs: Vec<(u32, usize)> = Vec::new();
86            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87        }
88        n
89    }
90}
91impl<'de> DecodeBorrow<'de> for DescribeGroupsResponse<'de> {
92    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
93        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94            return Err(ProtocolError::UnsupportedVersion {
95                api_key: API_KEY,
96                version,
97            });
98        }
99        let flex = is_flexible(version);
100        let mut out = Self::default();
101        if version >= 1 {
102            out.throttle_time_ms = get_i32(buf)?;
103        }
104        if version >= 0 {
105            out.groups = {
106                let n = crate::primitives::array::get_array_len(buf, flex)?;
107                let mut v = Vec::with_capacity(n);
108                for _ in 0..n {
109                    v.push(DescribedGroup::decode_borrow(buf, version)?);
110                }
111                v
112            };
113        }
114        if flex {
115            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116        }
117        Ok(out)
118    }
119}
120#[cfg(test)]
121impl DescribeGroupsResponse<'_> {
122    #[must_use]
123    pub fn populated(version: i16) -> Self {
124        let mut m = Self::default();
125        if version >= 1 {
126            m.throttle_time_ms = 1i32;
127        }
128        if version >= 0 {
129            m.groups = vec![DescribedGroup::populated(version)];
130        }
131        m
132    }
133}
134#[derive(Debug, Clone, PartialEq, Eq)]
135pub struct DescribedGroup<'a> {
136    pub error_code: i16,
137    pub error_message: Option<&'a str>,
138    pub group_id: &'a str,
139    pub group_state: &'a str,
140    pub protocol_type: &'a str,
141    pub protocol_data: &'a str,
142    pub members: Vec<DescribedGroupMember<'a>>,
143    pub authorized_operations: i32,
144    pub unknown_tagged_fields: UnknownTaggedFields,
145}
146impl Default for DescribedGroup<'_> {
147    fn default() -> Self {
148        Self {
149            error_code: 0i16,
150            error_message: None,
151            group_id: "",
152            group_state: "",
153            protocol_type: "",
154            protocol_data: "",
155            members: Vec::new(),
156            authorized_operations: -2_147_483_648i32,
157            unknown_tagged_fields: Default::default(),
158        }
159    }
160}
161impl DescribedGroup<'_> {
162    pub fn to_owned(&self) -> crate::owned::describe_groups_response::DescribedGroup {
163        crate::owned::describe_groups_response::DescribedGroup {
164            error_code: (self.error_code),
165            error_message: (self.error_message).map(std::string::ToString::to_string),
166            group_id: (self.group_id).to_string(),
167            group_state: (self.group_state).to_string(),
168            protocol_type: (self.protocol_type).to_string(),
169            protocol_data: (self.protocol_data).to_string(),
170            members: (self.members)
171                .iter()
172                .map(DescribedGroupMember::to_owned)
173                .collect(),
174            authorized_operations: (self.authorized_operations),
175            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
176        }
177    }
178}
179impl Encode for DescribedGroup<'_> {
180    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
181        let flex = version >= 5;
182        if version >= 0 {
183            put_i16(buf, self.error_code);
184        }
185        if version >= 6 {
186            if flex {
187                put_compact_nullable_string(buf, self.error_message);
188            } else {
189                put_nullable_string(buf, self.error_message);
190            }
191        }
192        if version >= 0 {
193            if flex {
194                put_compact_string(buf, self.group_id);
195            } else {
196                put_string(buf, self.group_id);
197            }
198        }
199        if version >= 0 {
200            if flex {
201                put_compact_string(buf, self.group_state);
202            } else {
203                put_string(buf, self.group_state);
204            }
205        }
206        if version >= 0 {
207            if flex {
208                put_compact_string(buf, self.protocol_type);
209            } else {
210                put_string(buf, self.protocol_type);
211            }
212        }
213        if version >= 0 {
214            if flex {
215                put_compact_string(buf, self.protocol_data);
216            } else {
217                put_string(buf, self.protocol_data);
218            }
219        }
220        if version >= 0 {
221            {
222                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
223                for it in &self.members {
224                    it.encode(buf, version)?;
225                }
226            }
227        }
228        if version >= 3 {
229            put_i32(buf, self.authorized_operations);
230        }
231        if flex {
232            let tagged = WriteTaggedFields::new();
233            tagged.write(buf, &self.unknown_tagged_fields);
234        }
235        Ok(())
236    }
237    fn encoded_len(&self, version: i16) -> usize {
238        let flex = version >= 5;
239        let mut n: usize = 0;
240        if version >= 0 {
241            n += 2;
242        }
243        if version >= 6 {
244            n += if flex {
245                compact_nullable_string_len(self.error_message)
246            } else {
247                nullable_string_len(self.error_message)
248            };
249        }
250        if version >= 0 {
251            n += if flex {
252                compact_string_len(self.group_id)
253            } else {
254                string_len(self.group_id)
255            };
256        }
257        if version >= 0 {
258            n += if flex {
259                compact_string_len(self.group_state)
260            } else {
261                string_len(self.group_state)
262            };
263        }
264        if version >= 0 {
265            n += if flex {
266                compact_string_len(self.protocol_type)
267            } else {
268                string_len(self.protocol_type)
269            };
270        }
271        if version >= 0 {
272            n += if flex {
273                compact_string_len(self.protocol_data)
274            } else {
275                string_len(self.protocol_data)
276            };
277        }
278        if version >= 0 {
279            n += {
280                let prefix =
281                    crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
282                let body: usize = (self.members)
283                    .iter()
284                    .map(|it| it.encoded_len(version))
285                    .sum();
286                prefix + body
287            };
288        }
289        if version >= 3 {
290            n += 4;
291        }
292        if flex {
293            let known_pairs: Vec<(u32, usize)> = Vec::new();
294            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
295        }
296        n
297    }
298}
299impl<'de> DecodeBorrow<'de> for DescribedGroup<'de> {
300    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
301        let flex = version >= 5;
302        let mut out = Self::default();
303        if version >= 0 {
304            out.error_code = get_i16(buf)?;
305        }
306        if version >= 6 {
307            out.error_message = if flex {
308                get_compact_nullable_string_borrowed(buf)?
309            } else {
310                get_nullable_string_borrowed(buf)?
311            };
312        }
313        if version >= 0 {
314            out.group_id = if flex {
315                get_compact_string_borrowed(buf)?
316            } else {
317                get_string_borrowed(buf)?
318            };
319        }
320        if version >= 0 {
321            out.group_state = if flex {
322                get_compact_string_borrowed(buf)?
323            } else {
324                get_string_borrowed(buf)?
325            };
326        }
327        if version >= 0 {
328            out.protocol_type = if flex {
329                get_compact_string_borrowed(buf)?
330            } else {
331                get_string_borrowed(buf)?
332            };
333        }
334        if version >= 0 {
335            out.protocol_data = if flex {
336                get_compact_string_borrowed(buf)?
337            } else {
338                get_string_borrowed(buf)?
339            };
340        }
341        if version >= 0 {
342            out.members = {
343                let n = crate::primitives::array::get_array_len(buf, flex)?;
344                let mut v = Vec::with_capacity(n);
345                for _ in 0..n {
346                    v.push(DescribedGroupMember::decode_borrow(buf, version)?);
347                }
348                v
349            };
350        }
351        if version >= 3 {
352            out.authorized_operations = get_i32(buf)?;
353        }
354        if flex {
355            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
356        }
357        Ok(out)
358    }
359}
360#[cfg(test)]
361impl DescribedGroup<'_> {
362    #[must_use]
363    pub fn populated(version: i16) -> Self {
364        let mut m = Self::default();
365        if version >= 0 {
366            m.error_code = 1i16;
367        }
368        if version >= 6 {
369            m.error_message = Some("x");
370        }
371        if version >= 0 {
372            m.group_id = "x";
373        }
374        if version >= 0 {
375            m.group_state = "x";
376        }
377        if version >= 0 {
378            m.protocol_type = "x";
379        }
380        if version >= 0 {
381            m.protocol_data = "x";
382        }
383        if version >= 0 {
384            m.members = vec![DescribedGroupMember::populated(version)];
385        }
386        if version >= 3 {
387            m.authorized_operations = 1i32;
388        }
389        m
390    }
391}
392#[derive(Debug, Clone, PartialEq, Eq, Default)]
393pub struct DescribedGroupMember<'a> {
394    pub member_id: &'a str,
395    pub group_instance_id: Option<&'a str>,
396    pub client_id: &'a str,
397    pub client_host: &'a str,
398    pub member_metadata: &'a [u8],
399    pub member_assignment: &'a [u8],
400    pub unknown_tagged_fields: UnknownTaggedFields,
401}
402impl DescribedGroupMember<'_> {
403    pub fn to_owned(&self) -> crate::owned::describe_groups_response::DescribedGroupMember {
404        crate::owned::describe_groups_response::DescribedGroupMember {
405            member_id: (self.member_id).to_string(),
406            group_instance_id: (self.group_instance_id).map(std::string::ToString::to_string),
407            client_id: (self.client_id).to_string(),
408            client_host: (self.client_host).to_string(),
409            member_metadata: Bytes::copy_from_slice(self.member_metadata),
410            member_assignment: Bytes::copy_from_slice(self.member_assignment),
411            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
412        }
413    }
414}
415impl Encode for DescribedGroupMember<'_> {
416    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
417        let flex = version >= 5;
418        if version >= 0 {
419            if flex {
420                put_compact_string(buf, self.member_id);
421            } else {
422                put_string(buf, self.member_id);
423            }
424        }
425        if version >= 4 {
426            if flex {
427                put_compact_nullable_string(buf, self.group_instance_id);
428            } else {
429                put_nullable_string(buf, self.group_instance_id);
430            }
431        }
432        if version >= 0 {
433            if flex {
434                put_compact_string(buf, self.client_id);
435            } else {
436                put_string(buf, self.client_id);
437            }
438        }
439        if version >= 0 {
440            if flex {
441                put_compact_string(buf, self.client_host);
442            } else {
443                put_string(buf, self.client_host);
444            }
445        }
446        if version >= 0 {
447            if flex {
448                put_compact_bytes(buf, self.member_metadata);
449            } else {
450                put_bytes(buf, self.member_metadata);
451            }
452        }
453        if version >= 0 {
454            if flex {
455                put_compact_bytes(buf, self.member_assignment);
456            } else {
457                put_bytes(buf, self.member_assignment);
458            }
459        }
460        if flex {
461            let tagged = WriteTaggedFields::new();
462            tagged.write(buf, &self.unknown_tagged_fields);
463        }
464        Ok(())
465    }
466    fn encoded_len(&self, version: i16) -> usize {
467        let flex = version >= 5;
468        let mut n: usize = 0;
469        if version >= 0 {
470            n += if flex {
471                compact_string_len(self.member_id)
472            } else {
473                string_len(self.member_id)
474            };
475        }
476        if version >= 4 {
477            n += if flex {
478                compact_nullable_string_len(self.group_instance_id)
479            } else {
480                nullable_string_len(self.group_instance_id)
481            };
482        }
483        if version >= 0 {
484            n += if flex {
485                compact_string_len(self.client_id)
486            } else {
487                string_len(self.client_id)
488            };
489        }
490        if version >= 0 {
491            n += if flex {
492                compact_string_len(self.client_host)
493            } else {
494                string_len(self.client_host)
495            };
496        }
497        if version >= 0 {
498            n += if flex {
499                crate::primitives::varint::uvarint_len(
500                    u32::try_from((self.member_metadata).len() + 1).unwrap(),
501                ) + (self.member_metadata).len()
502            } else {
503                4 + (self.member_metadata).len()
504            };
505        }
506        if version >= 0 {
507            n += if flex {
508                crate::primitives::varint::uvarint_len(
509                    u32::try_from((self.member_assignment).len() + 1).unwrap(),
510                ) + (self.member_assignment).len()
511            } else {
512                4 + (self.member_assignment).len()
513            };
514        }
515        if flex {
516            let known_pairs: Vec<(u32, usize)> = Vec::new();
517            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
518        }
519        n
520    }
521}
522impl<'de> DecodeBorrow<'de> for DescribedGroupMember<'de> {
523    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
524        let flex = version >= 5;
525        let mut out = Self::default();
526        if version >= 0 {
527            out.member_id = if flex {
528                get_compact_string_borrowed(buf)?
529            } else {
530                get_string_borrowed(buf)?
531            };
532        }
533        if version >= 4 {
534            out.group_instance_id = if flex {
535                get_compact_nullable_string_borrowed(buf)?
536            } else {
537                get_nullable_string_borrowed(buf)?
538            };
539        }
540        if version >= 0 {
541            out.client_id = if flex {
542                get_compact_string_borrowed(buf)?
543            } else {
544                get_string_borrowed(buf)?
545            };
546        }
547        if version >= 0 {
548            out.client_host = if flex {
549                get_compact_string_borrowed(buf)?
550            } else {
551                get_string_borrowed(buf)?
552            };
553        }
554        if version >= 0 {
555            out.member_metadata = if flex {
556                get_compact_bytes_borrowed(buf)?
557            } else {
558                get_bytes_borrowed(buf)?
559            };
560        }
561        if version >= 0 {
562            out.member_assignment = if flex {
563                get_compact_bytes_borrowed(buf)?
564            } else {
565                get_bytes_borrowed(buf)?
566            };
567        }
568        if flex {
569            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
570        }
571        Ok(out)
572    }
573}
574#[cfg(test)]
575impl DescribedGroupMember<'_> {
576    #[must_use]
577    pub fn populated(version: i16) -> Self {
578        let mut m = Self::default();
579        if version >= 0 {
580            m.member_id = "x";
581        }
582        if version >= 4 {
583            m.group_instance_id = Some("x");
584        }
585        if version >= 0 {
586            m.client_id = "x";
587        }
588        if version >= 0 {
589            m.client_host = "x";
590        }
591        if version >= 0 {
592            m.member_metadata = &b"x"[..];
593        }
594        if version >= 0 {
595            m.member_assignment = &b"x"[..];
596        }
597        m
598    }
599}