Skip to main content

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