Skip to main content

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