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