Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
IncrementalAlterConfigsResponse.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_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, compact_string_len, nullable_string_len,
10            put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11            string_len,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15            get_nullable_string_borrowed, get_string_borrowed,
16        },
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 44;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 1;
23pub const FLEXIBLE_MIN: i16 = 1;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct IncrementalAlterConfigsResponse<'a> {
31    pub throttle_time_ms: i32,
32    pub responses: Vec<AlterConfigsResourceResponse<'a>>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl IncrementalAlterConfigsResponse<'_> {
36    /// # Panics
37    ///
38    /// Panics if a records field contains an invalid encoded record batch.
39    #[must_use]
40    pub fn to_owned(
41        &self,
42    ) -> crate::owned::incremental_alter_configs_response::IncrementalAlterConfigsResponse {
43        crate::owned::incremental_alter_configs_response::IncrementalAlterConfigsResponse {
44            throttle_time_ms: (self.throttle_time_ms),
45            responses: (self.responses)
46                .iter()
47                .map(AlterConfigsResourceResponse::to_owned)
48                .collect(),
49            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
50        }
51    }
52}
53impl Encode for IncrementalAlterConfigsResponse<'_> {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion {
57                api_key: API_KEY,
58                version,
59            });
60        }
61        let flex = is_flexible(version);
62        if version >= 0 {
63            put_i32(buf, self.throttle_time_ms);
64        }
65        if version >= 0 {
66            {
67                crate::primitives::array::put_array_len(buf, (self.responses).len(), flex);
68                for it in &self.responses {
69                    it.encode(buf, version)?;
70                }
71            };
72        }
73        if flex {
74            let tagged = WriteTaggedFields::new();
75            tagged.write(buf, &self.unknown_tagged_fields);
76        }
77        Ok(())
78    }
79    fn encoded_len(&self, version: i16) -> usize {
80        let flex = is_flexible(version);
81        let mut n: usize = 0;
82        if version >= 0 {
83            n += 4;
84        }
85        if version >= 0 {
86            n += {
87                let prefix =
88                    crate::primitives::array::array_len_prefix_len((self.responses).len(), flex);
89                let body: usize = (self.responses)
90                    .iter()
91                    .map(|it| it.encoded_len(version))
92                    .sum();
93                prefix + body
94            };
95        }
96        if flex {
97            let known_pairs: Vec<(u32, usize)> = Vec::new();
98            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
99        }
100        n
101    }
102}
103impl<'de> DecodeBorrow<'de> for IncrementalAlterConfigsResponse<'de> {
104    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
105        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
106            return Err(ProtocolError::UnsupportedVersion {
107                api_key: API_KEY,
108                version,
109            });
110        }
111        let flex = is_flexible(version);
112        let mut out = Self::default();
113        if version >= 0 {
114            out.throttle_time_ms = get_i32(buf)?;
115        }
116        if version >= 0 {
117            out.responses = {
118                let n = crate::primitives::array::get_array_len(buf, flex)?;
119                let mut v = Vec::with_capacity(n);
120                for _ in 0..n {
121                    v.push(AlterConfigsResourceResponse::decode_borrow(buf, version)?);
122                }
123                v
124            };
125        }
126        if flex {
127            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
128        }
129        Ok(out)
130    }
131}
132#[cfg(test)]
133impl IncrementalAlterConfigsResponse<'_> {
134    #[must_use]
135    pub fn populated(version: i16) -> Self {
136        let mut m = Self::default();
137        if version >= 0 {
138            m.throttle_time_ms = 1i32;
139        }
140        if version >= 0 {
141            m.responses = vec![AlterConfigsResourceResponse::populated(version)];
142        }
143        m
144    }
145}
146#[derive(Debug, Clone, PartialEq, Eq)]
147pub struct AlterConfigsResourceResponse<'a> {
148    pub error_code: i16,
149    pub error_message: Option<&'a str>,
150    pub resource_type: i8,
151    pub resource_name: &'a str,
152    pub unknown_tagged_fields: UnknownTaggedFields,
153}
154impl Default for AlterConfigsResourceResponse<'_> {
155    fn default() -> Self {
156        Self {
157            error_code: 0i16,
158            error_message: Some(""),
159            resource_type: 0i8,
160            resource_name: "",
161            unknown_tagged_fields: UnknownTaggedFields::default(),
162        }
163    }
164}
165impl AlterConfigsResourceResponse<'_> {
166    /// # Panics
167    ///
168    /// Panics if a records field contains an invalid encoded record batch.
169    #[must_use]
170    pub fn to_owned(
171        &self,
172    ) -> crate::owned::incremental_alter_configs_response::AlterConfigsResourceResponse {
173        crate::owned::incremental_alter_configs_response::AlterConfigsResourceResponse {
174            error_code: (self.error_code),
175            error_message: (self.error_message).map(std::string::ToString::to_string),
176            resource_type: (self.resource_type),
177            resource_name: (self.resource_name).to_string(),
178            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
179        }
180    }
181}
182impl Encode for AlterConfigsResourceResponse<'_> {
183    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
184        let flex = version >= 1;
185        if version >= 0 {
186            put_i16(buf, self.error_code);
187        }
188        if version >= 0 {
189            if flex {
190                let () = put_compact_nullable_string(buf, self.error_message);
191            } else {
192                let () = put_nullable_string(buf, self.error_message);
193            }
194        }
195        if version >= 0 {
196            put_i8(buf, self.resource_type);
197        }
198        if version >= 0 {
199            if flex {
200                let () = put_compact_string(buf, self.resource_name);
201            } else {
202                let () = put_string(buf, self.resource_name);
203            }
204        }
205        if flex {
206            let tagged = WriteTaggedFields::new();
207            tagged.write(buf, &self.unknown_tagged_fields);
208        }
209        Ok(())
210    }
211    fn encoded_len(&self, version: i16) -> usize {
212        let flex = version >= 1;
213        let mut n: usize = 0;
214        if version >= 0 {
215            n += 2;
216        }
217        if version >= 0 {
218            n += if flex {
219                compact_nullable_string_len(self.error_message)
220            } else {
221                nullable_string_len(self.error_message)
222            };
223        }
224        if version >= 0 {
225            n += 1;
226        }
227        if version >= 0 {
228            n += if flex {
229                compact_string_len(self.resource_name)
230            } else {
231                string_len(self.resource_name)
232            };
233        }
234        if flex {
235            let known_pairs: Vec<(u32, usize)> = Vec::new();
236            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
237        }
238        n
239    }
240}
241impl<'de> DecodeBorrow<'de> for AlterConfigsResourceResponse<'de> {
242    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
243        let flex = version >= 1;
244        let mut out = Self::default();
245        if version >= 0 {
246            out.error_code = get_i16(buf)?;
247        }
248        if version >= 0 {
249            out.error_message = if flex {
250                get_compact_nullable_string_borrowed(buf)?
251            } else {
252                get_nullable_string_borrowed(buf)?
253            };
254        }
255        if version >= 0 {
256            out.resource_type = get_i8(buf)?;
257        }
258        if version >= 0 {
259            out.resource_name = if flex {
260                get_compact_string_borrowed(buf)?
261            } else {
262                get_string_borrowed(buf)?
263            };
264        }
265        if flex {
266            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
267        }
268        Ok(out)
269    }
270}
271#[cfg(test)]
272impl AlterConfigsResourceResponse<'_> {
273    #[must_use]
274    pub fn populated(version: i16) -> Self {
275        let mut m = Self::default();
276        if version >= 0 {
277            m.error_code = 1i16;
278        }
279        if version >= 0 {
280            m.error_message = Some("x");
281        }
282        if version >= 0 {
283            m.resource_type = 1i8;
284        }
285        if version >= 0 {
286            m.resource_name = "x";
287        }
288        m
289    }
290}