Skip to main content

kacrab_protocol/generated/
describe_groups_request.rs

1//! Generated from DescribeGroupsRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct DescribeGroupsRequestData {
17    /// The names of the groups to describe.
18    pub groups: Vec<KafkaString>,
19    /// Whether to include authorized operations.
20    pub include_authorized_operations: bool,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for DescribeGroupsRequestData {
24    fn default() -> Self {
25        Self {
26            groups: Vec::new(),
27            include_authorized_operations: false,
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl DescribeGroupsRequestData {
33    pub fn with_groups(mut self, value: Vec<KafkaString>) -> Self {
34        self.groups = value;
35        self
36    }
37    pub fn with_include_authorized_operations(mut self, value: bool) -> Self {
38        self.include_authorized_operations = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42        if version < 0 || version > 6 {
43            return Err(UnsupportedVersion::new(15, version).into());
44        }
45        let groups;
46        let mut include_authorized_operations = false;
47        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
48        if version >= 5 {
49            groups = {
50                let len = read_compact_array_length(buf)?;
51                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
52                for _ in 0..len {
53                    arr.push(read_compact_string(buf)?);
54                }
55                arr
56            };
57        } else {
58            groups = {
59                let len = read_array_length(buf)?;
60                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
61                for _ in 0..len {
62                    arr.push(read_string(buf)?);
63                }
64                arr
65            };
66        }
67        if version >= 3 {
68            include_authorized_operations = read_bool(buf)?;
69        }
70        if version >= 5 {
71            let tagged_fields = read_tagged_fields(buf)?;
72            for field in &tagged_fields {
73                match field.tag {
74                    _ => {
75                        _unknown_tagged_fields.push(field.clone());
76                    },
77                }
78            }
79        }
80        Ok(Self {
81            groups,
82            include_authorized_operations,
83            _unknown_tagged_fields,
84        })
85    }
86    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
87        if version < 0 || version > 6 {
88            return Err(UnsupportedVersion::new(15, version).into());
89        }
90        if version >= 5 {
91            write_compact_array_length(buf, self.groups.len() as i32);
92            for el in &self.groups {
93                write_compact_string(buf, el)?;
94            }
95        } else {
96            write_array_length(buf, self.groups.len() as i32);
97            for el in &self.groups {
98                write_string(buf, el)?;
99            }
100        }
101        if version >= 3 {
102            write_bool(buf, self.include_authorized_operations);
103        } else if self.include_authorized_operations != false {
104            return Err(
105                UnsupportedFieldVersion::new(15, "include_authorized_operations", version).into(),
106            );
107        }
108        if version >= 5 {
109            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
110            all_tags.sort_by_key(|f| f.tag);
111            write_tagged_fields(buf, &all_tags)?;
112        }
113        Ok(())
114    }
115    pub fn encoded_len(&self, version: i16) -> Result<usize> {
116        if version < 0 || version > 6 {
117            return Err(UnsupportedVersion::new(15, version).into());
118        }
119        let mut len: usize = 0;
120        if version >= 5 {
121            len += compact_array_length_len(self.groups.len() as i32);
122            for el in &self.groups {
123                len += compact_string_len(el)?;
124            }
125        } else {
126            len += array_length_len();
127            for el in &self.groups {
128                len += string_len(el)?;
129            }
130        }
131        if version >= 3 {
132            len += 1;
133        } else if self.include_authorized_operations != false {
134            return Err(
135                UnsupportedFieldVersion::new(15, "include_authorized_operations", version).into(),
136            );
137        }
138        if version >= 5 {
139            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
140            all_tags.sort_by_key(|f| f.tag);
141            len += tagged_fields_len(&all_tags)?;
142        }
143        Ok(len)
144    }
145}