Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
CreateAclsResponse.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, nullable_string_len, put_compact_nullable_string,
5    put_nullable_string,
6};
7use crate::primitives::string_bytes_borrowed::{
8    get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
12use bytes::BufMut;
13pub const API_KEY: i16 = 30;
14pub const MIN_VERSION: i16 = 1;
15pub const MAX_VERSION: i16 = 3;
16pub const FLEXIBLE_MIN: i16 = 2;
17#[inline]
18fn is_flexible(version: i16) -> bool {
19    version >= FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct CreateAclsResponse<'a> {
23    pub throttle_time_ms: i32,
24    pub results: Vec<AclCreationResult<'a>>,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl CreateAclsResponse<'_> {
28    pub fn to_owned(&self) -> crate::owned::create_acls_response::CreateAclsResponse {
29        crate::owned::create_acls_response::CreateAclsResponse {
30            throttle_time_ms: (self.throttle_time_ms),
31            results: (self.results)
32                .iter()
33                .map(AclCreationResult::to_owned)
34                .collect(),
35            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
36        }
37    }
38}
39impl Encode for CreateAclsResponse<'_> {
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 >= 0 {
49            put_i32(buf, self.throttle_time_ms);
50        }
51        if version >= 0 {
52            {
53                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
54                for it in &self.results {
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 >= 0 {
69            n += 4;
70        }
71        if version >= 0 {
72            n += {
73                let prefix =
74                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
75                let body: usize = (self.results)
76                    .iter()
77                    .map(|it| it.encoded_len(version))
78                    .sum();
79                prefix + body
80            };
81        }
82        if flex {
83            let known_pairs: Vec<(u32, usize)> = Vec::new();
84            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
85        }
86        n
87    }
88}
89impl<'de> DecodeBorrow<'de> for CreateAclsResponse<'de> {
90    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
91        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
92            return Err(ProtocolError::UnsupportedVersion {
93                api_key: API_KEY,
94                version,
95            });
96        }
97        let flex = is_flexible(version);
98        let mut out = Self::default();
99        if version >= 0 {
100            out.throttle_time_ms = get_i32(buf)?;
101        }
102        if version >= 0 {
103            out.results = {
104                let n = crate::primitives::array::get_array_len(buf, flex)?;
105                let mut v = Vec::with_capacity(n);
106                for _ in 0..n {
107                    v.push(AclCreationResult::decode_borrow(buf, version)?);
108                }
109                v
110            };
111        }
112        if flex {
113            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
114        }
115        Ok(out)
116    }
117}
118#[cfg(test)]
119impl CreateAclsResponse<'_> {
120    #[must_use]
121    pub fn populated(version: i16) -> Self {
122        let mut m = Self::default();
123        if version >= 0 {
124            m.throttle_time_ms = 1i32;
125        }
126        if version >= 0 {
127            m.results = vec![AclCreationResult::populated(version)];
128        }
129        m
130    }
131}
132#[derive(Debug, Clone, PartialEq, Eq, Default)]
133pub struct AclCreationResult<'a> {
134    pub error_code: i16,
135    pub error_message: Option<&'a str>,
136    pub unknown_tagged_fields: UnknownTaggedFields,
137}
138impl AclCreationResult<'_> {
139    pub fn to_owned(&self) -> crate::owned::create_acls_response::AclCreationResult {
140        crate::owned::create_acls_response::AclCreationResult {
141            error_code: (self.error_code),
142            error_message: (self.error_message).map(std::string::ToString::to_string),
143            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
144        }
145    }
146}
147impl Encode for AclCreationResult<'_> {
148    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
149        let flex = version >= 2;
150        if version >= 0 {
151            put_i16(buf, self.error_code);
152        }
153        if version >= 0 {
154            if flex {
155                put_compact_nullable_string(buf, self.error_message);
156            } else {
157                put_nullable_string(buf, self.error_message);
158            }
159        }
160        if flex {
161            let tagged = WriteTaggedFields::new();
162            tagged.write(buf, &self.unknown_tagged_fields);
163        }
164        Ok(())
165    }
166    fn encoded_len(&self, version: i16) -> usize {
167        let flex = version >= 2;
168        let mut n: usize = 0;
169        if version >= 0 {
170            n += 2;
171        }
172        if version >= 0 {
173            n += if flex {
174                compact_nullable_string_len(self.error_message)
175            } else {
176                nullable_string_len(self.error_message)
177            };
178        }
179        if flex {
180            let known_pairs: Vec<(u32, usize)> = Vec::new();
181            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
182        }
183        n
184    }
185}
186impl<'de> DecodeBorrow<'de> for AclCreationResult<'de> {
187    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
188        let flex = version >= 2;
189        let mut out = Self::default();
190        if version >= 0 {
191            out.error_code = get_i16(buf)?;
192        }
193        if version >= 0 {
194            out.error_message = if flex {
195                get_compact_nullable_string_borrowed(buf)?
196            } else {
197                get_nullable_string_borrowed(buf)?
198            };
199        }
200        if flex {
201            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
202        }
203        Ok(out)
204    }
205}
206#[cfg(test)]
207impl AclCreationResult<'_> {
208    #[must_use]
209    pub fn populated(version: i16) -> Self {
210        let mut m = Self::default();
211        if version >= 0 {
212            m.error_code = 1i16;
213        }
214        if version >= 0 {
215            m.error_message = Some("x");
216        }
217        m
218    }
219}