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