Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesResponse.borrowed.rs

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