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