Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsRequest.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_bool, put_bool},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 15;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 6;
16pub const LATEST_STABLE_VERSION: i16 = 6;
17pub const FLEXIBLE_MIN: i16 = 5;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeGroupsRequest<'a> {
25    pub groups: Vec<&'a str>,
26    pub include_authorized_operations: bool,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl DescribeGroupsRequest<'_> {
30    /// # Panics
31    ///
32    /// Panics if a records field contains an invalid encoded record batch.
33    #[must_use]
34    pub fn to_owned(&self) -> crate::owned::describe_groups_request::DescribeGroupsRequest {
35        crate::owned::describe_groups_request::DescribeGroupsRequest {
36            groups: (self.groups)
37                .iter()
38                .map(std::string::ToString::to_string)
39                .collect(),
40            include_authorized_operations: (self.include_authorized_operations),
41            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
42        }
43    }
44}
45impl Encode for DescribeGroupsRequest<'_> {
46    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
47        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48            return Err(ProtocolError::UnsupportedVersion {
49                api_key: API_KEY,
50                version,
51            });
52        }
53        let flex = is_flexible(version);
54        if version >= 0 {
55            {
56                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
57                for it in &self.groups {
58                    if flex {
59                        let () = put_compact_string(buf, it);
60                    } else {
61                        let () = put_string(buf, it);
62                    }
63                }
64            };
65        }
66        if version >= 3 {
67            put_bool(buf, self.include_authorized_operations);
68        }
69        if flex {
70            let tagged = WriteTaggedFields::new();
71            tagged.write(buf, &self.unknown_tagged_fields);
72        }
73        Ok(())
74    }
75    fn encoded_len(&self, version: i16) -> usize {
76        let flex = is_flexible(version);
77        let mut n: usize = 0;
78        if version >= 0 {
79            n += {
80                let prefix =
81                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
82                let body: usize = (self.groups)
83                    .iter()
84                    .map(|it| {
85                        if flex {
86                            compact_string_len(it)
87                        } else {
88                            string_len(it)
89                        }
90                    })
91                    .sum();
92                prefix + body
93            };
94        }
95        if version >= 3 {
96            n += 1;
97        }
98        if flex {
99            let known_pairs: Vec<(u32, usize)> = Vec::new();
100            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
101        }
102        n
103    }
104}
105impl<'de> DecodeBorrow<'de> for DescribeGroupsRequest<'de> {
106    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
107        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
108            return Err(ProtocolError::UnsupportedVersion {
109                api_key: API_KEY,
110                version,
111            });
112        }
113        let flex = is_flexible(version);
114        let mut out = Self::default();
115        if version >= 0 {
116            out.groups = {
117                let n = crate::primitives::array::get_array_len(buf, flex)?;
118                let mut v = Vec::with_capacity(n);
119                for _ in 0..n {
120                    v.push(if flex {
121                        get_compact_string_borrowed(buf)?
122                    } else {
123                        get_string_borrowed(buf)?
124                    });
125                }
126                v
127            };
128        }
129        if version >= 3 {
130            out.include_authorized_operations = get_bool(buf)?;
131        }
132        if flex {
133            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
134        }
135        Ok(out)
136    }
137}
138#[cfg(test)]
139impl DescribeGroupsRequest<'_> {
140    #[must_use]
141    pub fn populated(version: i16) -> Self {
142        let mut m = Self::default();
143        if version >= 0 {
144            m.groups = vec!["x"];
145        }
146        if version >= 3 {
147            m.include_authorized_operations = true;
148        }
149        m
150    }
151}